refactor: remove bootstrapper, closes #3786 (#3832)

This commit is contained in:
Lucas Fernandes Nogueira 2022-03-31 10:51:17 -07:00 committed by GitHub
parent 985d250898
commit 6a5ff08ce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 33 additions and 249 deletions

View File

@ -0,0 +1,6 @@
---
"tauri-bundler": patch
"tauri-utils": patch
---
**Breaking change:** Removed the `useBootstrapper` option. Use https://github.com/tauri-apps/fix-path-env-rs instead.

View File

@ -91,9 +91,6 @@ impl BundleTarget {
pub struct DebConfig {
/// The list of deb dependencies your application relies on.
pub depends: Option<Vec<String>>,
/// Enable the boostrapper script.
#[serde(default)]
pub use_bootstrapper: bool,
/// The files to include on the package.
#[serde(default)]
pub files: HashMap<PathBuf, PathBuf>,
@ -136,9 +133,6 @@ pub struct MacConfig {
pub exception_domain: Option<String>,
/// The path to the license file to add to the DMG bundle.
pub license: Option<String>,
/// Enable the boostrapper script.
#[serde(default)]
pub use_bootstrapper: bool,
/// Identity to use for code signing.
pub signing_identity: Option<String>,
/// Provider short name for notarization.
@ -154,7 +148,6 @@ impl Default for MacConfig {
minimum_system_version: minimum_system_version(),
exception_domain: None,
license: None,
use_bootstrapper: false,
signing_identity: None,
provider_short_name: None,
entitlements: None,

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -24,12 +24,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -35,12 +35,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": "",
"signingIdentity": null,
"entitlements": null

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -24,12 +24,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -24,14 +24,12 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"signingIdentity": null,
"entitlements": "../entitlements.plist",
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
},
"windows": {

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -25,12 +25,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},

View File

@ -48,7 +48,6 @@ These settings are used only when bundling `deb` packages.
* `depends`: A list of strings indicating other packages (e.g. shared
libraries) that this package depends on to be installed. If present, this
forms the `Depends:` field of the `deb` package control file.
* `use_bootstrapper`: Enables the bootstrapper script, which allows access to the environment variables.
### Mac OS X-specific settings
@ -75,7 +74,6 @@ These settings are used only when bundling `app` and `dmg` packages.
you want) to ensure that the compiled binary has the same minimum version.
* `license`: Path to the license file for the DMG bundle.
* `exception_domain`: The exception domain to use on the macOS .app bundle. Allows communication to the outside world e.g. a web server you're shipping.
* `use_bootstrapper`: Enables the bootstrapper script, which allows access to the environment variables.
* `provider_short_name`: If your Apple ID is connected to multiple teams, you have to specify the provider short name of the team you want to use to notarize your app. See [Customizing the notarization workflow](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow) and search for `--list-providers` for more information how to obtain your provider short name.
### Example `tauri.conf.json`:
@ -102,14 +100,12 @@ These settings are used only when bundling `app` and `dmg` packages.
],
"resources": ["./assets/**/*.png"],
"deb": {
"depends": ["debian-dependency1", "debian-dependency2"],
"useBootstrapper": true
"depends": ["debian-dependency1", "debian-dependency2"]
},
"macOS": {
"frameworks": [],
"minimumSystemVersion": "10.11",
"license": "./LICENSE",
"useBootstrapper": true
"license": "./LICENSE"
},
"externalBin": ["./sidecar-app"]
}

View File

@ -29,7 +29,6 @@ use anyhow::Context;
use heck::ToKebabCase;
use image::{self, codecs::png::PngDecoder, GenericImageView, ImageDecoder};
use libflate::gzip;
use std::process::{Command, Stdio};
use walkdir::WalkDir;
use std::{
@ -128,80 +127,9 @@ pub fn generate_data(
generate_icon_files(settings, &data_dir).with_context(|| "Failed to create icon files")?;
generate_desktop_file(settings, &data_dir).with_context(|| "Failed to create desktop file")?;
let use_bootstrapper = settings.deb().use_bootstrapper.unwrap_or_default();
if use_bootstrapper {
generate_bootstrap_file(settings, &data_dir)
.with_context(|| "Failed to generate bootstrap file")?;
}
Ok((data_dir, icons))
}
/// Generates the bootstrap script file.
fn generate_bootstrap_file(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
let bin_name = settings.main_binary_name();
let bin_dir = data_dir.join("usr/bin");
let bootstrap_file_name = format!("__{}-bootstrapper", bin_name);
let bootstrapper_file_path = bin_dir.join(bootstrap_file_name.clone());
let bootstrapper_file = &mut common::create_file(&bootstrapper_file_path)?;
write!(
bootstrapper_file,
"#!/usr/bin/env sh
# This bootstraps the environment for Tauri, so environments are available.
export NVM_DIR=\"$([ -z \"${{XDG_CONFIG_HOME-}}\" ] && printf %s \"${{HOME}}/.nvm\" || printf %s \"${{XDG_CONFIG_HOME}}/nvm\")\"
[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"
if [ -e ~/.bash_profile ]
then
source ~/.bash_profile
fi
if [ -e ~/.zprofile ]
then
source ~/.zprofile
fi
if [ -e ~/.profile ]
then
source ~/.profile
fi
if [ -e ~/.bashrc ]
then
source ~/.bashrc
fi
if [ -e ~/.zshrc ]
then
source ~/.zshrc
fi
echo $PATH
source /etc/profile
if pidof -x \"{}\" >/dev/null; then
exit 0
else
Exec=/usr/bin/env /usr/bin/{} $@ & disown
fi
exit 0",
bootstrap_file_name, bin_name
)?;
bootstrapper_file.flush()?;
let status = Command::new("chmod")
.arg("+x")
.arg(bootstrap_file_name)
.current_dir(&bin_dir)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.status()?;
if !status.success() {
return Err(anyhow::anyhow!("failed to make the bootstrapper an executable",).into());
}
Ok(())
}
/// Generate the application desktop file and store it under the `data_dir`.
fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
let bin_name = settings.main_binary_name();
@ -221,16 +149,7 @@ fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<
if !settings.short_description().is_empty() {
writeln!(file, "Comment={}", settings.short_description())?;
}
let use_bootstrapper = settings.deb().use_bootstrapper.unwrap_or_default();
writeln!(
file,
"Exec={}",
if use_bootstrapper {
format!("__{}-bootstrapper", bin_name)
} else {
bin_name.to_string()
}
)?;
writeln!(file, "Exec={}", bin_name)?;
writeln!(file, "Icon={}", bin_name)?;
writeln!(file, "Name={}", settings.product_name())?;
writeln!(file, "Terminal=false")?;

View File

@ -80,12 +80,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
copy_binaries_to_bundle(&bundle_directory, settings)?;
let use_bootstrapper = settings.macos().use_bootstrapper.unwrap_or_default();
if use_bootstrapper {
create_bootstrapper(&bundle_directory, settings)
.with_context(|| "Failed to create macOS bootstrapper")?;
}
if let Some(identity) = &settings.macos().signing_identity {
// setup keychain allow you to import your certificate
// for CI build
@ -117,63 +111,6 @@ fn copy_binaries_to_bundle(bundle_directory: &Path, settings: &Settings) -> crat
Ok(())
}
// Creates the bootstrap script file.
fn create_bootstrapper(bundle_dir: &Path, settings: &Settings) -> crate::Result<()> {
let file = &mut common::create_file(&bundle_dir.join("MacOS/__bootstrapper"))?;
// Create a shell script to bootstrap the $PATH for Tauri, so environments like node are available.
write!(
file,
"#!/usr/bin/env sh
# This bootstraps the environment for Tauri, so environments are available.
if [ -e ~/.bash_profile ]
then
. ~/.bash_profile
fi
if [ -e ~/.zprofile ]
then
. ~/.zprofile
fi
if [ -e ~/.profile ]
then
. ~/.profile
fi
if [ -e ~/.bashrc ]
then
. ~/.bashrc
fi
if [ -e ~/.zshrc ]
then
. ~/.zshrc
fi
if pidof \"__bootstrapper\" >/dev/null; then
exit 0
else
exec \"`dirname \\\"$0\\\"`/{}\" $@ & disown
fi
exit 0",
settings.product_name()
)?;
file.flush()?;
// We have to make the __bootstrapper executable, or the bundle will not work
let status = Command::new("chmod")
.arg("+x")
.arg("__bootstrapper")
.current_dir(&bundle_dir.join("MacOS/"))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.status()?;
if !status.success() {
return Err(anyhow::anyhow!("failed to make the bootstrapper an executable",).into());
}
Ok(())
}
// Creates the Info.plist file.
fn create_info_plist(
bundle_dir: &Path,
@ -188,7 +125,6 @@ fn create_info_plist(
let bundle_plist_path = bundle_dir.join("Info.plist");
let file = &mut common::create_file(&bundle_plist_path)?;
let use_bootstrapper = settings.macos().use_bootstrapper.unwrap_or_default();
write!(
file,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
@ -210,11 +146,7 @@ fn create_info_plist(
write!(
file,
" <key>CFBundleExecutable</key>\n <string>{}</string>\n",
if use_bootstrapper {
"__bootstrapper"
} else {
settings.main_binary_name()
}
settings.main_binary_name()
)?;
if let Some(path) = bundle_icon_file {
write!(

View File

@ -126,12 +126,6 @@ pub struct DebianSettings {
// OS-specific settings:
/// the list of debian dependencies.
pub depends: Option<Vec<String>>,
/// whether we should use the bootstrap script on debian or not.
///
/// this script goal is to allow your app to access environment variables e.g $PATH.
///
/// without it, you can't run some applications installed by the user.
pub use_bootstrapper: Option<bool>,
/// List of custom files to add to the deb package.
/// Maps the path on the debian package to the path of the file to include (relative to the current working directory).
pub files: HashMap<PathBuf, PathBuf>,
@ -157,12 +151,6 @@ pub struct MacOsSettings {
/// The path to the LICENSE file for macOS apps.
/// Currently only used by the dmg bundle.
pub license: Option<String>,
/// whether we should use the bootstrap script on macOS .app or not.
///
/// this script goal is to allow your app to access environment variables e.g $PATH.
///
/// without it, you can't run some applications installed by the user.
pub use_bootstrapper: Option<bool>,
/// The exception domain to use on the macOS .app bundle.
///
/// This allows communication to the outside world e.g. a web server you're shipping.

View File

@ -134,14 +134,12 @@
"bundle": {
"active": false,
"deb": {
"files": {},
"useBootstrapper": false
"files": {}
},
"icon": [],
"identifier": "",
"macOS": {
"minimumSystemVersion": "10.13",
"useBootstrapper": false
"minimumSystemVersion": "10.13"
},
"windows": {
"allowDowngrades": true,
@ -482,8 +480,7 @@
"deb": {
"description": "Configuration for the Debian bundle.",
"default": {
"files": {},
"useBootstrapper": false
"files": {}
},
"allOf": [
{
@ -523,8 +520,7 @@
"macOS": {
"description": "Configuration for the macOS bundles.",
"default": {
"minimumSystemVersion": "10.13",
"useBootstrapper": false
"minimumSystemVersion": "10.13"
},
"allOf": [
{
@ -925,11 +921,6 @@
"additionalProperties": {
"type": "string"
}
},
"useBootstrapper": {
"description": "Enable the boostrapper script.",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
@ -1168,11 +1159,6 @@
"string",
"null"
]
},
"useBootstrapper": {
"description": "Enable the boostrapper script.",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
@ -1637,14 +1623,12 @@
"default": {
"active": false,
"deb": {
"files": {},
"useBootstrapper": false
"files": {}
},
"icon": [],
"identifier": "",
"macOS": {
"minimumSystemVersion": "10.13",
"useBootstrapper": false
"minimumSystemVersion": "10.13"
},
"windows": {
"allowDowngrades": true,
@ -2258,4 +2242,4 @@
"additionalProperties": false
}
}
}
}

View File

@ -456,14 +456,12 @@ fn tauri_config_to_bundle_settings(
} else {
Some(depends)
},
use_bootstrapper: Some(config.deb.use_bootstrapper),
files: config.deb.files,
},
macos: MacOsSettings {
frameworks: config.macos.frameworks,
minimum_system_version: config.macos.minimum_system_version,
license: config.macos.license,
use_bootstrapper: Some(config.macos.use_bootstrapper),
exception_domain: config.macos.exception_domain,
signing_identity,
provider_short_name,

View File

@ -28,12 +28,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": "",
"signingIdentity": null,
"providerShortName": null,

View File

@ -26,12 +26,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": "",
"signingIdentity": null,
"entitlements": null

View File

@ -24,12 +24,10 @@
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": [],
"useBootstrapper": false
"depends": []
},
"macOS": {
"frameworks": [],
"useBootstrapper": false,
"exceptionDomain": ""
}
},