Explorar el Código

feat(bundler): hide output from shell scripts unless --verbose is passed (fixes #888) (#893)

* feat(bundler): hide output from bundle_appimage.sh

* fix(bundler/appimage): log file name instead of full path
to match behavior of .deb build

* feat(bundler): hide shell script output unless --verbose is passed

* feat(bundler): add notice about --verbose on error

* fix(bundler): windows fails to compile

* fix(bundler) do not warn about verbosity if verbose is set

* chore(changes) add change file

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Noah Klayman hace 5 años
padre
commit
78add1e79e

+ 5 - 0
.changes/bundler-script-output.md

@@ -0,0 +1,5 @@
+---
+"tauri-bundler": patch
+---
+
+Hide external scripts output unless `--verbose` is passed.

+ 11 - 4
cli/tauri-bundler/src/bundle/appimage_bundle.rs

@@ -74,7 +74,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
 
   // create the shell script file in the target/ folder.
   let sh_file = output_path.join("build_appimage.sh");
-  common::print_bundling(format!("{:?}", &appimage_path).as_str())?;
+  common::print_bundling(&appimage_path.file_name().unwrap().to_str().unwrap())?;
   write(&sh_file, temp)?;
 
   // chmod script for execution
@@ -91,9 +91,16 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   let mut cmd = Command::new(&sh_file);
   cmd.current_dir(output_path);
 
-  common::print_info("running build_appimage.sh")?;
-  common::execute_with_output(&mut cmd)
-    .map_err(|_| crate::Error::ShellScriptError("error running build_appimage.sh".to_owned()))?;
+  common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
+    crate::Error::ShellScriptError(format!(
+      "error running appimage.sh{}",
+      if settings.is_verbose() {
+        ""
+      } else {
+        ", try running with --verbose to see command output"
+      }
+    ))
+  })?;
 
   remove_dir_all(&package_dir)?;
   Ok(vec![appimage_path])

+ 10 - 3
cli/tauri-bundler/src/bundle/common.rs

@@ -1,3 +1,4 @@
+use crate::Settings;
 use std;
 use std::ffi::OsStr;
 use std::fs::{self, File};
@@ -268,12 +269,18 @@ pub fn print_error(error: &anyhow::Error) -> crate::Result<()> {
   }
 }
 
-pub fn execute_with_output(cmd: &mut Command) -> crate::Result<()> {
+pub fn execute_with_verbosity(cmd: &mut Command, settings: &Settings) -> crate::Result<()> {
+  let stdio_config = if settings.is_verbose() {
+    Stdio::piped
+  } else {
+    Stdio::null
+  };
   let mut child = cmd
-    .stdout(Stdio::piped())
+    .stdout(stdio_config())
+    .stderr(stdio_config())
     .spawn()
     .expect("failed to spawn command");
-  {
+  if settings.is_verbose() {
     let stdout = child.stdout.as_mut().expect("Failed to get stdout handle");
     let reader = BufReader::new(stdout);
 

+ 10 - 2
cli/tauri-bundler/src/bundle/dmg_bundle.rs

@@ -116,8 +116,16 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
     .args(vec![dmg_name.as_str(), bundle_name.as_str()]);
 
   common::print_info("running bundle_dmg.sh")?;
-  common::execute_with_output(&mut cmd)
-    .map_err(|_| crate::Error::ShellScriptError("error running bundle_dmg.sh".to_owned()))?;
+  common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
+    crate::Error::ShellScriptError(format!(
+      "error running bundle_dmg.sh{}",
+      if settings.is_verbose() {
+        ""
+      } else {
+        ", try running with --verbose to see command output"
+      }
+    ))
+  })?;
 
   fs::rename(bundle_dir.join(dmg_name), dmg_path.clone())?;
   Ok(vec![bundle_path, dmg_path])

+ 9 - 0
cli/tauri-bundler/src/bundle/settings.rs

@@ -281,6 +281,8 @@ pub struct Settings {
   project_out_directory: PathBuf,
   /// whether we should build the app with release mode or not.
   is_release: bool,
+  /// whether or not to enable verbose logging
+  is_verbose: bool,
   /// the bundle settings.
   bundle_settings: BundleSettings,
   /// the binaries to bundle.
@@ -337,6 +339,7 @@ impl Settings {
       None => None,
     };
     let is_release = matches.is_present("release");
+    let is_verbose = matches.is_present("verbose");
     let target = match matches.value_of("target") {
       Some(triple) => Some((triple.to_string(), TargetInfo::from_str(triple)?)),
       None => None,
@@ -444,6 +447,7 @@ impl Settings {
       target,
       features,
       is_release,
+      is_verbose,
       project_out_directory: target_dir,
       binaries,
       bundle_settings,
@@ -626,6 +630,11 @@ impl Settings {
     self.is_release
   }
 
+  /// Returns true if verbose logging is enabled
+  pub fn is_verbose(&self) -> bool {
+    self.is_verbose
+  }
+
   /// Returns the bundle name, which is either package.metadata.bundle.name or package.name
   pub fn bundle_name(&self) -> &str {
     self

+ 24 - 4
cli/tauri-bundler/src/bundle/wix.rs

@@ -361,7 +361,16 @@ fn run_candle(
     .current_dir(build_path);
 
   common::print_info("running candle.exe")?;
-  common::execute_with_output(&mut cmd).map_err(|_| crate::Error::CandleError)
+  common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
+    crate::Error::ShellScriptError(format!(
+      "error running candle.exe{}",
+      if settings.is_verbose() {
+        ""
+      } else {
+        ", try running with --verbose to see command output"
+      }
+    ))
+  })
 }
 
 /// Runs the Light.exe file. Light takes the generated code from Candle and produces an MSI Installer.
@@ -370,6 +379,7 @@ fn run_light(
   build_path: &Path,
   wixobjs: &[&str],
   output_path: &Path,
+  settings: &Settings,
 ) -> crate::Result<PathBuf> {
   let light_exe = wix_toolset_path.join("light.exe");
 
@@ -391,9 +401,18 @@ fn run_light(
     .current_dir(build_path);
 
   common::print_info(format!("running light to produce {}", output_path.display()).as_str())?;
-  common::execute_with_output(&mut cmd)
+  common::execute_with_verbosity(&mut cmd, &settings)
     .map(|_| output_path.to_path_buf())
-    .map_err(|_| crate::Error::LightError)
+    .map_err(|_| {
+      crate::Error::ShellScriptError(format!(
+        "error running light.exe{}",
+        if settings.is_verbose() {
+          ""
+        } else {
+          ", try running with --verbose to see command output"
+        }
+      ))
+    })
 }
 
 // fn get_icon_data() -> crate::Result<()> {
@@ -512,7 +531,8 @@ pub fn build_wix_app_installer(
     &wix_toolset_path,
     &output_path,
     &wixobjs,
-    &app_installer_dir(settings)?,
+    &app_installer_dir(&settings)?,
+    &settings,
   )?;
 
   Ok(target)

+ 0 - 4
cli/tauri-bundler/src/error.rs

@@ -55,10 +55,6 @@ pub enum Error {
   HashError,
   #[error("Architecture Error: `{0}`")]
   ArchError(String),
-  #[error("Error running Candle.exe")]
-  CandleError,
-  #[error("Error running Light.exe")]
-  LightError,
   #[error(
     "Couldn't get tauri config; please specify the TAURI_CONFIG or TAURI_DIR environment variables"
   )]

+ 4 - 0
cli/tauri-bundler/src/main.rs

@@ -98,6 +98,10 @@ fn run() -> crate::Result<()> {
             .long("version")
             .short("v")
             .help("Read the version of the bundler"),
+        ).arg(
+          Arg::with_name("verbose")
+            .long("verbose")
+            .help("Enable verbose output"),
         ),
     )
     .get_matches();

+ 6 - 3
cli/tauri.js/bin/tauri-build.js

@@ -4,9 +4,10 @@ const argv = parseArgs(process.argv.slice(2), {
   alias: {
     h: 'help',
     d: 'debug',
-    t: 'target'
+    t: 'target',
+    v: 'verbose'
   },
-  boolean: ['h', 'd']
+  boolean: ['h', 'd', 'v']
 })
 
 if (argv.help) {
@@ -19,6 +20,7 @@ if (argv.help) {
     --help, -h     Displays this message
     --debug, -d    Builds with the debug flag
     --target, -t   Comma-separated list of target triples to build against
+    --verbose, -v  Enable verbose logging
   `)
   process.exit(0)
 }
@@ -30,7 +32,8 @@ async function run () {
     ctx: {
       debug: argv.debug,
       target: argv.target
-    }
+    },
+    verbose: argv.verbose
   }).promise
 }
 

+ 1 - 0
cli/tauri.js/src/runner.ts

@@ -271,6 +271,7 @@ class Runner {
           )
         ]
           .concat(cfg.ctx.debug ? [] : ['--release'])
+          .concat(cfg.verbose ? ['--verbose'] : [])
           .concat(target ? ['--target', target] : [])
       })
 

+ 4 - 0
cli/tauri.js/src/types/config.schema.json

@@ -492,6 +492,10 @@
         "window"
       ],
       "type": "object"
+    },
+    "verbose": {
+      "description": "Whether or not to enable verbose logging",
+      "type": "boolean"
     }
   },
   "required": [

+ 4 - 0
cli/tauri.js/src/types/config.ts

@@ -294,6 +294,10 @@ export interface TauriConfig {
       [key: string]: any
     }
   }
+  /**
+   * Whether or not to enable verbose logging
+   */
+  verbose?: boolean
 }
 
 export default TauriConfig

+ 4 - 0
cli/tauri.js/src/types/config.validator.ts

@@ -502,6 +502,10 @@ export const TauriConfigSchema = {
         "window"
       ],
       "type": "object"
+    },
+    "verbose": {
+      "description": "Whether or not to enable verbose logging",
+      "type": "boolean"
     }
   },
   "required": [