mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
feat(cli.rs): expose debug flag to beforeDev/beforeBuild commands (#2727)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
committed by
GitHub
parent
53fdfe52bb
commit
b5ee03a13a
@@ -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.
|
||||
|
||||
@@ -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>>,
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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))?;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user