Skip to content

Commit

Permalink
feat(cli.rs): expose debug flag to beforeDev/beforeBuild commands (#2727
Browse files Browse the repository at this point in the history
)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
JonasKruckenberg and lucasfernog committed Oct 8, 2021
1 parent 53fdfe5 commit b5ee03a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .changes/before-script-envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions tooling/cli.rs/config_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli.rs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli.rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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))?;
}
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli.rs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ 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"))]
let child = Command::new("sh")
.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();
Expand Down
7 changes: 6 additions & 1 deletion tooling/cli.rs/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
}

Expand Down

0 comments on commit b5ee03a

Please sign in to comment.