Skip to content

Commit 78add1e

Browse files
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>
1 parent 63b9c64 commit 78add1e

File tree

13 files changed

+92
-20
lines changed

13 files changed

+92
-20
lines changed

.changes/bundler-script-output.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
Hide external scripts output unless `--verbose` is passed.

cli/tauri-bundler/src/bundle/appimage_bundle.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
7474

7575
// create the shell script file in the target/ folder.
7676
let sh_file = output_path.join("build_appimage.sh");
77-
common::print_bundling(format!("{:?}", &appimage_path).as_str())?;
77+
common::print_bundling(&appimage_path.file_name().unwrap().to_str().unwrap())?;
7878
write(&sh_file, temp)?;
7979

8080
// chmod script for execution
@@ -91,9 +91,16 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
9191
let mut cmd = Command::new(&sh_file);
9292
cmd.current_dir(output_path);
9393

94-
common::print_info("running build_appimage.sh")?;
95-
common::execute_with_output(&mut cmd)
96-
.map_err(|_| crate::Error::ShellScriptError("error running build_appimage.sh".to_owned()))?;
94+
common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
95+
crate::Error::ShellScriptError(format!(
96+
"error running appimage.sh{}",
97+
if settings.is_verbose() {
98+
""
99+
} else {
100+
", try running with --verbose to see command output"
101+
}
102+
))
103+
})?;
97104

98105
remove_dir_all(&package_dir)?;
99106
Ok(vec![appimage_path])

cli/tauri-bundler/src/bundle/common.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::Settings;
12
use std;
23
use std::ffi::OsStr;
34
use std::fs::{self, File};
@@ -268,12 +269,18 @@ pub fn print_error(error: &anyhow::Error) -> crate::Result<()> {
268269
}
269270
}
270271

271-
pub fn execute_with_output(cmd: &mut Command) -> crate::Result<()> {
272+
pub fn execute_with_verbosity(cmd: &mut Command, settings: &Settings) -> crate::Result<()> {
273+
let stdio_config = if settings.is_verbose() {
274+
Stdio::piped
275+
} else {
276+
Stdio::null
277+
};
272278
let mut child = cmd
273-
.stdout(Stdio::piped())
279+
.stdout(stdio_config())
280+
.stderr(stdio_config())
274281
.spawn()
275282
.expect("failed to spawn command");
276-
{
283+
if settings.is_verbose() {
277284
let stdout = child.stdout.as_mut().expect("Failed to get stdout handle");
278285
let reader = BufReader::new(stdout);
279286

cli/tauri-bundler/src/bundle/dmg_bundle.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,16 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
116116
.args(vec![dmg_name.as_str(), bundle_name.as_str()]);
117117

118118
common::print_info("running bundle_dmg.sh")?;
119-
common::execute_with_output(&mut cmd)
120-
.map_err(|_| crate::Error::ShellScriptError("error running bundle_dmg.sh".to_owned()))?;
119+
common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
120+
crate::Error::ShellScriptError(format!(
121+
"error running bundle_dmg.sh{}",
122+
if settings.is_verbose() {
123+
""
124+
} else {
125+
", try running with --verbose to see command output"
126+
}
127+
))
128+
})?;
121129

122130
fs::rename(bundle_dir.join(dmg_name), dmg_path.clone())?;
123131
Ok(vec![bundle_path, dmg_path])

cli/tauri-bundler/src/bundle/settings.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ pub struct Settings {
281281
project_out_directory: PathBuf,
282282
/// whether we should build the app with release mode or not.
283283
is_release: bool,
284+
/// whether or not to enable verbose logging
285+
is_verbose: bool,
284286
/// the bundle settings.
285287
bundle_settings: BundleSettings,
286288
/// the binaries to bundle.
@@ -337,6 +339,7 @@ impl Settings {
337339
None => None,
338340
};
339341
let is_release = matches.is_present("release");
342+
let is_verbose = matches.is_present("verbose");
340343
let target = match matches.value_of("target") {
341344
Some(triple) => Some((triple.to_string(), TargetInfo::from_str(triple)?)),
342345
None => None,
@@ -444,6 +447,7 @@ impl Settings {
444447
target,
445448
features,
446449
is_release,
450+
is_verbose,
447451
project_out_directory: target_dir,
448452
binaries,
449453
bundle_settings,
@@ -626,6 +630,11 @@ impl Settings {
626630
self.is_release
627631
}
628632

633+
/// Returns true if verbose logging is enabled
634+
pub fn is_verbose(&self) -> bool {
635+
self.is_verbose
636+
}
637+
629638
/// Returns the bundle name, which is either package.metadata.bundle.name or package.name
630639
pub fn bundle_name(&self) -> &str {
631640
self

cli/tauri-bundler/src/bundle/wix.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,16 @@ fn run_candle(
361361
.current_dir(build_path);
362362

363363
common::print_info("running candle.exe")?;
364-
common::execute_with_output(&mut cmd).map_err(|_| crate::Error::CandleError)
364+
common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
365+
crate::Error::ShellScriptError(format!(
366+
"error running candle.exe{}",
367+
if settings.is_verbose() {
368+
""
369+
} else {
370+
", try running with --verbose to see command output"
371+
}
372+
))
373+
})
365374
}
366375

367376
/// Runs the Light.exe file. Light takes the generated code from Candle and produces an MSI Installer.
@@ -370,6 +379,7 @@ fn run_light(
370379
build_path: &Path,
371380
wixobjs: &[&str],
372381
output_path: &Path,
382+
settings: &Settings,
373383
) -> crate::Result<PathBuf> {
374384
let light_exe = wix_toolset_path.join("light.exe");
375385

@@ -391,9 +401,18 @@ fn run_light(
391401
.current_dir(build_path);
392402

393403
common::print_info(format!("running light to produce {}", output_path.display()).as_str())?;
394-
common::execute_with_output(&mut cmd)
404+
common::execute_with_verbosity(&mut cmd, &settings)
395405
.map(|_| output_path.to_path_buf())
396-
.map_err(|_| crate::Error::LightError)
406+
.map_err(|_| {
407+
crate::Error::ShellScriptError(format!(
408+
"error running light.exe{}",
409+
if settings.is_verbose() {
410+
""
411+
} else {
412+
", try running with --verbose to see command output"
413+
}
414+
))
415+
})
397416
}
398417

399418
// fn get_icon_data() -> crate::Result<()> {
@@ -512,7 +531,8 @@ pub fn build_wix_app_installer(
512531
&wix_toolset_path,
513532
&output_path,
514533
&wixobjs,
515-
&app_installer_dir(settings)?,
534+
&app_installer_dir(&settings)?,
535+
&settings,
516536
)?;
517537

518538
Ok(target)

cli/tauri-bundler/src/error.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ pub enum Error {
5555
HashError,
5656
#[error("Architecture Error: `{0}`")]
5757
ArchError(String),
58-
#[error("Error running Candle.exe")]
59-
CandleError,
60-
#[error("Error running Light.exe")]
61-
LightError,
6258
#[error(
6359
"Couldn't get tauri config; please specify the TAURI_CONFIG or TAURI_DIR environment variables"
6460
)]

cli/tauri-bundler/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ fn run() -> crate::Result<()> {
9898
.long("version")
9999
.short("v")
100100
.help("Read the version of the bundler"),
101+
).arg(
102+
Arg::with_name("verbose")
103+
.long("verbose")
104+
.help("Enable verbose output"),
101105
),
102106
)
103107
.get_matches();

cli/tauri.js/bin/tauri-build.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const argv = parseArgs(process.argv.slice(2), {
44
alias: {
55
h: 'help',
66
d: 'debug',
7-
t: 'target'
7+
t: 'target',
8+
v: 'verbose'
89
},
9-
boolean: ['h', 'd']
10+
boolean: ['h', 'd', 'v']
1011
})
1112

1213
if (argv.help) {
@@ -19,6 +20,7 @@ if (argv.help) {
1920
--help, -h Displays this message
2021
--debug, -d Builds with the debug flag
2122
--target, -t Comma-separated list of target triples to build against
23+
--verbose, -v Enable verbose logging
2224
`)
2325
process.exit(0)
2426
}
@@ -30,7 +32,8 @@ async function run () {
3032
ctx: {
3133
debug: argv.debug,
3234
target: argv.target
33-
}
35+
},
36+
verbose: argv.verbose
3437
}).promise
3538
}
3639

cli/tauri.js/src/runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class Runner {
271271
)
272272
]
273273
.concat(cfg.ctx.debug ? [] : ['--release'])
274+
.concat(cfg.verbose ? ['--verbose'] : [])
274275
.concat(target ? ['--target', target] : [])
275276
})
276277

0 commit comments

Comments
 (0)