diff --git a/Cargo.lock b/Cargo.lock index 99fd04b7af..e8b56cf8c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -614,24 +614,7 @@ dependencies = [ [[package]] name = "console" -version = "0.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "console" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -870,7 +853,7 @@ dependencies = [ "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", + "console 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1364,7 +1347,7 @@ name = "indicatif" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "console 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "console 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1809,15 +1792,6 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot_core" version = "0.5.0" @@ -1847,19 +1821,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot_core" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "paste" version = "0.1.6" @@ -2540,11 +2501,6 @@ name = "smallvec" version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "smallvec" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "socket2" version = "0.3.11" @@ -3322,8 +3278,7 @@ dependencies = [ "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" "checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03" -"checksum console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628" -"checksum console 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5d540c2d34ac9dd0deb5f3b5f54c36c79efa78f6b3ad19106a554d07a7b5d9f" +"checksum console 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "45e0f3986890b3acbc782009e2629dfe2baa430ac091519ce3be26164a2ae6c0" "checksum const-random 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7b641a8c9867e341f3295564203b1c250eb8ce6cb6126e007941f78c4d2ed7fe" "checksum const-random-macro 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c750ec12b83377637110d5a57f5ae08e895b06c4b16e2bdbf1a94ef717428c59" "checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" @@ -3448,12 +3403,10 @@ dependencies = [ "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c977d08e1312e2f7e4b86f9ebaa0ed3b19d1daff75fae88bbb88108afbd801fc" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" -"checksum parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" "checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" "checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" "checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" -"checksum parking_lot_core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1" "checksum paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "423a519e1c6e828f1e73b720f9d9ed2fa643dce8a7737fb43235ce0b41eeaa49" "checksum paste-impl 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4214c9e912ef61bf42b81ba9a47e8aad1b2ffaf739ab162bf96d1e011f54e6c5" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" @@ -3530,7 +3483,6 @@ dependencies = [ "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" -"checksum smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum string_cache 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "96ccb3a75a3caf2d7f2eb9ada86ec1fbbd4c74ad2bd8dc00a96a0c2f93509ef0" diff --git a/src/dfx/Cargo.toml b/src/dfx/Cargo.toml index 7391795b37..3e1c79c37c 100644 --- a/src/dfx/Cargo.toml +++ b/src/dfx/Cargo.toml @@ -22,7 +22,7 @@ actix-files = "0.1.4" atty = "0.2.13" base64 = "0.11.0" clap = "2.33.0" -console = "0.7.7" +console = "0.9.2" crossbeam = "0.7.3" flate2 = "1.0.11" futures = "0.1.28" diff --git a/src/dfx/src/commands/build.rs b/src/dfx/src/commands/build.rs index 4a660fd512..38e1b0f580 100644 --- a/src/dfx/src/commands/build.rs +++ b/src/dfx/src/commands/build.rs @@ -12,6 +12,7 @@ use console::Style; use ic_http_agent::CanisterId; use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; use rand::{thread_rng, Rng}; +use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::ffi::OsStr; use std::io::Read; @@ -31,8 +32,22 @@ pub fn construct() -> App<'static, 'static> { .takes_value(false) .help(UserMessage::SkipFrontend.to_str()), ) + .arg( + Arg::with_name("extra-args") + .long("extra-args") + .takes_value(true) + .help(UserMessage::BuildArgs.to_str()), + ) + .arg( + Arg::with_name("verbose") + .long("verbose") + .takes_value(false) + .help(UserMessage::BuildVerbose.to_str()), + ) } +thread_local!(static VERBOSE: RefCell = RefCell::new(false)); + fn get_asset_fn(assets: &AssetMap) -> String { // Create the if/else series. let mut cases = String::new(); @@ -79,9 +94,9 @@ struct MotokoParams<'a> { // The following fields will not be used by self.to_args() // TODO move input into self.to_args once inject_code is deprecated. input: &'a Path, - verbose: bool, surpress_warning: bool, inject_code: bool, + extra_args: &'a str, } impl MotokoParams<'_> { @@ -98,6 +113,10 @@ impl MotokoParams<'_> { cmd.args(&["--actor-alias", name, canister_id]); } }; + if !self.extra_args.is_empty() { + let args: Vec<_> = self.extra_args.split(' ').collect(); + cmd.args(args); + }; } } @@ -137,7 +156,7 @@ fn motoko_compile(cache: &dyn Cache, params: &MotokoParams<'_>, assets: &AssetMa .arg("--package") .arg("stdlib") .arg(&stdlib_path.as_path()); - run_command(cmd, params.verbose, params.surpress_warning)?; + run_command(cmd, params.surpress_warning)?; if params.inject_code { std::fs::remove_file(input_path)?; @@ -201,7 +220,7 @@ fn parse_moc_deps(line: &str) -> DfxResult { } None => match fullpath { Some(fullpath) => { - let path = PathBuf::from(fullpath); + let path = PathBuf::from(fullpath).canonicalize()?; if !path.is_file() { return Err(DfxError::BuildError(BuildErrorKind::DependencyError( format!("Cannot find import file {}", path.display()), @@ -228,7 +247,7 @@ fn find_deps(cache: &dyn Cache, input_path: &Path, deps: &mut MotokoImports) -> let mut cmd = cache.get_binary_command("moc")?; let cmd = cmd.arg("--print-deps").arg(&input_path); - let output = run_command(cmd, false, false)?; + let output = run_command(cmd, false)?; let output = String::from_utf8_lossy(&output.stdout); for dep in output.lines() { @@ -248,18 +267,16 @@ fn find_deps(cache: &dyn Cache, input_path: &Path, deps: &mut MotokoImports) -> fn build_did_js(cache: &dyn Cache, input_path: &Path, output_path: &Path) -> DfxResult { let mut cmd = cache.get_binary_command("didc")?; let cmd = cmd.arg("--js").arg(&input_path).arg("-o").arg(&output_path); - run_command(cmd, false, false)?; + run_command(cmd, false)?; Ok(()) } -fn run_command( - cmd: &mut std::process::Command, - verbose: bool, - surpress_warning: bool, -) -> DfxResult { - if verbose { - println!("{:?}", cmd); - } +fn run_command(cmd: &mut std::process::Command, surpress_warning: bool) -> DfxResult { + VERBOSE.with(|v| { + if *v.borrow() { + println!("{:?}", cmd); + } + }); let output = cmd.output()?; if !output.status.success() { Err(DfxError::BuildError(BuildErrorKind::CompilerError( @@ -306,6 +323,7 @@ fn build_file( name: &str, id_map: &CanisterIdMap, assets: &AssetMap, + extra_args: &str, ) -> DfxResult { let canister_info = CanisterInfo::load(config, name).map_err(|_| { BuildError(BuildErrorKind::CanisterNameIsNotInConfigError( @@ -345,11 +363,11 @@ fn build_file( }, surpress_warning: false, inject_code: true, - verbose: false, input: &input_path, output: &output_wasm_path, idl_path: &idl_dir_path, idl_map: &id_map, + extra_args, }; motoko_compile(cache.as_ref(), ¶ms, assets)?; // Generate IDL @@ -362,11 +380,11 @@ fn build_file( // Surpress the warnings the second time we call moc surpress_warning: true, inject_code: false, - verbose: false, input: &input_path, output: &output_idl_path, idl_path: &idl_dir_path, idl_map: &id_map, + extra_args, }; motoko_compile(cache.as_ref(), ¶ms, &HashMap::new())?; std::fs::copy(&output_idl_path, &idl_file_path)?; @@ -462,7 +480,6 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { env.get_cache().install()?; let green = Style::new().green().bold(); - let status_bar = ProgressBar::new_spinner(); status_bar.set_draw_target(ProgressDrawTarget::stderr()); status_bar.set_message("Building canisters..."); @@ -475,6 +492,13 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { } let canisters = maybe_canisters.as_ref().unwrap(); + if args.is_present("verbose") { + VERBOSE.with(|v| { + *v.borrow_mut() = true; + }); + status_bar.set_draw_target(ProgressDrawTarget::hidden()); + } + // Build canister id map and dependency graph let mut id_map = HashMap::new(); let mut deps = HashMap::new(); @@ -518,10 +542,27 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { ); build_stage_bar.enable_steady_tick(80); + if args.is_present("verbose") { + build_stage_bar.set_draw_target(ProgressDrawTarget::hidden()); + } + + let extra_args: &str = args.value_of("extra-args").unwrap_or("").trim(); + // Build canister for name in &seq.canisters { - build_stage_bar.println(&format!("{} canister {}", green.apply_to("Building"), name)); - match build_file(env, &config, name, &seq.get_ids(name), &HashMap::new()) { + build_stage_bar.println(&format!( + "{} canister {}", + green.apply_to("Compiling"), + name + )); + match build_file( + env, + &config, + name, + &seq.get_ids(name), + &HashMap::new(), + extra_args, + ) { Ok(()) => {} Err(e) => { build_stage_bar.abandon(); @@ -547,7 +588,7 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { .current_dir(config.get_project_root()) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()); - run_command(&mut cmd, false, false)?; + run_command(&mut cmd, false)?; build_stage_bar.inc(1); build_stage_bar.println(&format!( @@ -587,7 +628,14 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { } } - match build_file(env, &config, &name, &seq.get_ids(&name), &assets) { + match build_file( + env, + &config, + &name, + &seq.get_ids(&name), + &assets, + extra_args, + ) { Ok(()) => {} Err(e) => { build_stage_bar.abandon(); @@ -658,11 +706,11 @@ mod tests { build_target: BuildTarget::Debug, surpress_warning: false, inject_code: true, - verbose: false, input: &input_path, output: Path::new("/out/file.wasm"), idl_path: Path::new("."), idl_map: &HashMap::new(), + extra_args: "", }; motoko_compile(&cache, ¶ms, &HashMap::new()).expect("Function failed."); @@ -670,11 +718,11 @@ mod tests { build_target: BuildTarget::IDL, surpress_warning: false, inject_code: false, - verbose: false, input: Path::new("/in/file.mo"), output: Path::new("/out/file.did"), idl_path: Path::new("."), idl_map: &HashMap::new(), + extra_args: "", }; motoko_compile(&cache, ¶ms, &HashMap::new()).expect("Function failed (didl_compile)"); build_did_js( @@ -738,7 +786,7 @@ mod tests { ) .unwrap(); - build_file(&env, &config, "name", &HashMap::new(), &HashMap::new()) + build_file(&env, &config, "name", &HashMap::new(), &HashMap::new(), "") .expect("Function failed - build_file"); assert!(output_path.exists()); } diff --git a/src/dfx/src/lib/message.rs b/src/dfx/src/lib/message.rs index 6b09c48de6..3428d53591 100644 --- a/src/dfx/src/lib/message.rs +++ b/src/dfx/src/lib/message.rs @@ -52,6 +52,8 @@ user_message!( // dfx build BuildCanister => "Builds all or specific canisters from the code in your project. By default, all canisters are built.", SkipFrontend => "Skip building the frontend, only build the canisters.", + BuildVerbose => "Outputs all commands run by the build process.", + BuildArgs => "Specifies extra arguments passed to the compiler.", // dfx config ConfigureOptions => "Configures project options for your currently-selected project.",