Skip to content

Commit

Permalink
feat(bundler): hide output from shell scripts unless --verbose is pas…
Browse files Browse the repository at this point in the history
…sed (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>
  • Loading branch information
nklayman and lucasfernog committed Jul 26, 2020
1 parent 63b9c64 commit 78add1e
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changes/bundler-script-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Hide external scripts output unless `--verbose` is passed.
15 changes: 11 additions & 4 deletions cli/tauri-bundler/src/bundle/appimage_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down
13 changes: 10 additions & 3 deletions cli/tauri-bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::Settings;
use std;
use std::ffi::OsStr;
use std::fs::{self, File};
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions cli/tauri-bundler/src/bundle/dmg_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
9 changes: 9 additions & 0 deletions cli/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -444,6 +447,7 @@ impl Settings {
target,
features,
is_release,
is_verbose,
project_out_directory: target_dir,
binaries,
bundle_settings,
Expand Down Expand Up @@ -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
Expand Down
28 changes: 24 additions & 4 deletions cli/tauri-bundler/src/bundle/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");

Expand All @@ -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<()> {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions cli/tauri-bundler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)]
Expand Down
4 changes: 4 additions & 0 deletions cli/tauri-bundler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions cli/tauri.js/bin/tauri-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand All @@ -30,7 +32,8 @@ async function run () {
ctx: {
debug: argv.debug,
target: argv.target
}
},
verbose: argv.verbose
}).promise
}

Expand Down
1 change: 1 addition & 0 deletions cli/tauri.js/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Runner {
)
]
.concat(cfg.ctx.debug ? [] : ['--release'])
.concat(cfg.verbose ? ['--verbose'] : [])
.concat(target ? ['--target', target] : [])
})

Expand Down
4 changes: 4 additions & 0 deletions cli/tauri.js/src/types/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@
"window"
],
"type": "object"
},
"verbose": {
"description": "Whether or not to enable verbose logging",
"type": "boolean"
}
},
"required": [
Expand Down
4 changes: 4 additions & 0 deletions cli/tauri.js/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ export interface TauriConfig {
[key: string]: any
}
}
/**
* Whether or not to enable verbose logging
*/
verbose?: boolean
}

export default TauriConfig
4 changes: 4 additions & 0 deletions cli/tauri.js/src/types/config.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ export const TauriConfigSchema = {
"window"
],
"type": "object"
},
"verbose": {
"description": "Whether or not to enable verbose logging",
"type": "boolean"
}
},
"required": [
Expand Down

0 comments on commit 78add1e

Please sign in to comment.