feat(cli.rs): expose debug flag to beforeDev/beforeBuild commands (#2727)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Jonas Kruckenberg
2021-10-08 16:30:06 +02:00
committed by GitHub
parent 53fdfe52bb
commit b5ee03a13a
6 changed files with 15 additions and 10 deletions

View File

@@ -2,4 +2,4 @@
"cli.rs": patch
---
Define `PLATFORM`, `ARCH`, `FAMILY` and `PLATFORM_TYPE` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts.
Define `PLATFORM`, `ARCH`, `FAMILY`, `PLATFORM_TYPE` and `TAURI_DEBUG` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts.

View File

@@ -820,11 +820,11 @@ pub struct BuildConfig {
pub dist_dir: AppUrl,
/// A shell command to run before `tauri dev` kicks in.
///
/// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.
/// The PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
pub before_dev_command: Option<String>,
/// A shell command to run before `tauri build` kicks in.
///
/// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.
/// The PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
pub before_build_command: Option<String>,
/// Features passed to `cargo` commands.
pub features: Option<Vec<String>>,

View File

@@ -261,14 +261,14 @@
"type": "object",
"properties": {
"beforeBuildCommand": {
"description": "A shell command to run before `tauri build` kicks in.\n\nThe PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.",
"description": "A shell command to run before `tauri build` kicks in.\n\nThe PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
"type": [
"string",
"null"
]
},
"beforeDevCommand": {
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.",
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
"type": [
"string",
"null"

View File

@@ -91,7 +91,7 @@ impl Build {
.arg("/C")
.arg(before_build)
.current_dir(app_dir())
.envs(command_env()),
.envs(command_env(self.debug)),
)
.with_context(|| format!("failed to run `{}` with `cmd /C`", before_build))?;
#[cfg(not(target_os = "windows"))]
@@ -100,7 +100,7 @@ impl Build {
.arg("-c")
.arg(before_build)
.current_dir(app_dir())
.envs(command_env()),
.envs(command_env(self.debug)),
)
.with_context(|| format!("failed to run `{}` with `sh -c`", before_build))?;
}

View File

@@ -142,7 +142,7 @@ impl Dev {
.arg("/C")
.arg(before_dev)
.current_dir(app_dir())
.envs(command_env())
.envs(command_env(true)) // development build always includes debug information
.spawn()
.with_context(|| format!("failed to run `{}` with `cmd /C`", before_dev))?;
#[cfg(not(target_os = "windows"))]
@@ -150,7 +150,7 @@ impl Dev {
.arg("-c")
.arg(before_dev)
.current_dir(app_dir())
.envs(command_env())
.envs(command_env(true)) // development build always includes debug information
.spawn()
.with_context(|| format!("failed to run `{}` with `sh -c`", before_dev))?;
BEFORE_DEV.set(Mutex::new(child)).unwrap();

View File

@@ -41,8 +41,9 @@ pub fn execute_with_output(cmd: &mut Command) -> crate::Result<()> {
}
}
pub fn command_env() -> HashMap<String, String> {
pub fn command_env(debug: bool) -> HashMap<String, String> {
let mut map = HashMap::new();
map.insert("PLATFORM".into(), std::env::consts::OS.into());
map.insert("ARCH".into(), std::env::consts::ARCH.into());
map.insert("FAMILY".into(), std::env::consts::FAMILY.into());
@@ -55,6 +56,10 @@ pub fn command_env() -> HashMap<String, String> {
#[cfg(target_os = "macos")]
map.insert("PLATFORM_TYPE".into(), "Darwing".into());
if debug {
map.insert("TAURI_DEBUG".into(), "true".to_string());
}
map
}