From 695666a250c5968c6d74748167ed51b1f7e4a60c Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 24 May 2024 16:07:52 -0700 Subject: [PATCH 1/2] refactor build::run_command() --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/boot_fake_node/mod.rs | 3 ++- src/build/mod.rs | 44 +++++++++++++++++++++++++++------------ src/dev_ui/mod.rs | 2 ++ src/setup/mod.rs | 31 +++++++++++++++++---------- src/update/mod.rs | 8 +++---- 7 files changed, 60 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4adedce..bba2365a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1332,7 +1332,7 @@ dependencies = [ [[package]] name = "kit" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 59cfb132..e0ad3663 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kit" -version = "0.5.1" +version = "0.5.2" edition = "2021" [build-dependencies] diff --git a/src/boot_fake_node/mod.rs b/src/boot_fake_node/mod.rs index a86f9375..c327df58 100644 --- a/src/boot_fake_node/mod.rs +++ b/src/boot_fake_node/mod.rs @@ -91,7 +91,8 @@ pub fn compile_runtime(path: &Path, release: bool) -> Result<()> { build::run_command(Command::new("cargo") .args(&args) - .current_dir(path) + .current_dir(path), + false, )?; info!("Done compiling Kinode runtime."); diff --git a/src/build/mod.rs b/src/build/mod.rs index e9cc7cc4..c0959dfb 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -31,13 +31,18 @@ struct CargoPackage { } #[instrument(level = "trace", skip_all)] -pub fn run_command(cmd: &mut Command) -> Result<(String, String)> { +pub fn run_command(cmd: &mut Command, verbose: bool) -> Result> { + if verbose { + let mut child = cmd.spawn()?; + child.wait()?; + return Ok(None); + } let output = cmd.output()?; if output.status.success() { - Ok(( + Ok(Some(( String::from_utf8_lossy(&output.stdout).to_string(), String::from_utf8_lossy(&output.stderr).to_string(), - )) + ))) } else { Err(eyre!( "Command `{} {:?}` failed with exit code {}\nstdout: {}\nstderr: {}", @@ -127,12 +132,14 @@ async fn compile_javascript_wasm_process( Command::new("bash") .args(&["-c", &install]) .current_dir(process_dir), + false, )?; run_command( Command::new("bash") .args(&["-c", &componentize]) .current_dir(process_dir), + false, )?; info!( @@ -154,13 +161,15 @@ async fn compile_python_wasm_process(process_dir: &Path, python: &str) -> Result Command::new(python) .args(&["-m", "venv", PY_VENV_NAME]) .current_dir(process_dir), + false, )?; run_command(Command::new("bash") .args(&[ "-c", &format!("source ../{PY_VENV_NAME}/bin/activate && pip install {REQUIRED_PY_PACKAGE} && componentize-py -d ../wit/ -w process componentize lib -o ../../pkg/{wasm_file_name}.wasm"), ]) - .current_dir(process_dir.join("src")) + .current_dir(process_dir.join("src")), + false, )?; info!("Done compiling Python Kinode process in {:?}.", process_dir); @@ -194,14 +203,17 @@ async fn compile_rust_wasm_process( download_file(&wasi_snapshot_url, &wasi_snapshot_file).await?; // Create target.wasm (compiled .wit) & world - run_command(Command::new("wasm-tools").args(&[ - "component", - "wit", - wit_dir.to_str().unwrap(), - "-o", - &bindings_dir.join("target.wasm").to_str().unwrap(), - "--wasm", - ]))?; + run_command(Command::new("wasm-tools") + .args(&[ + "component", + "wit", + wit_dir.to_str().unwrap(), + "-o", + &bindings_dir.join("target.wasm").to_str().unwrap(), + "--wasm", + ]), + false, + )?; // Copy wit directory to bindings fs::create_dir_all(&bindings_dir.join("wit"))?; @@ -236,7 +248,8 @@ async fn compile_rust_wasm_process( Command::new("cargo") .args(&args) .current_dir(process_dir), - )?; + false, + )?.unwrap(); if stdout.contains("warning") { warn!("{}", stdout); } @@ -267,6 +280,7 @@ async fn compile_rust_wasm_process( wasi_snapshot_file.to_str().unwrap(), ]) .current_dir(process_dir), + false, )?; let wasm_path = format!("../pkg/{}.wasm", wasm_file_name); @@ -286,6 +300,7 @@ async fn compile_rust_wasm_process( wasm_path.to_str().unwrap(), ]) .current_dir(process_dir), + false, )?; info!("Done compiling Rust Kinode process in {:?}.", process_dir); @@ -319,6 +334,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Command::new("bash") .args(&["-c", &install]) .current_dir(&ui_path), + false, )?; info!("Running npm run build:copy..."); @@ -327,6 +343,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Command::new("bash") .args(&["-c", &run]) .current_dir(&ui_path), + false, )?; } else { let pkg_ui_path = package_dir.join("pkg/ui"); @@ -337,6 +354,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Command::new("cp") .args(["-r", "ui", "pkg/ui"]) .current_dir(&package_dir), + false, )?; } } else { diff --git a/src/dev_ui/mod.rs b/src/dev_ui/mod.rs index 2a03710d..554f06cb 100644 --- a/src/dev_ui/mod.rs +++ b/src/dev_ui/mod.rs @@ -43,6 +43,7 @@ pub fn execute( Command::new("bash") .args(&["-c", &install_command]) .current_dir(&ui_path), + false, )?; info!("Running {}", dev); @@ -52,6 +53,7 @@ pub fn execute( .args(&["-c", &dev_command]) .env("VITE_NODE_URL", url) .current_dir(&ui_path), + false, )?; } else { return Err(eyre!("'ui' directory not found or 'ui/package.json' does not exist")); diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 7f2c07e8..033fe523 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -22,7 +22,7 @@ pub const REQUIRED_PY_PACKAGE: &str = "componentize-py==0.11.0"; #[derive(Clone)] pub enum Dependency { Anvil, - Forge, + Forge, Nvm, Npm, Node, @@ -74,7 +74,8 @@ fn install_nvm() -> Result<()> { FETCH_NVM_VERSION, ); run_command(Command::new("bash") - .args(&["-c", &install_nvm]) + .args(&["-c", &install_nvm]), + false, )?; info!("Done getting nvm."); @@ -86,7 +87,8 @@ fn install_rust() -> Result<()> { info!("Getting rust..."); let install_rust = "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"; run_command(Command::new("bash") - .args(&["-c", install_rust]) + .args(&["-c", install_rust]), + false, )?; info!("Done getting rust."); @@ -98,7 +100,8 @@ fn check_python_venv(python: &str) -> Result<()> { info!("Checking for python venv..."); let venv_result = run_command(Command::new(python) .args(&["-m", "venv", "kinode-test-venv"]) - .current_dir("/tmp") + .current_dir("/tmp"), + false, ); let venv_dir = PathBuf::from("/tmp/kinode-test-venv"); if venv_dir.exists() { @@ -220,7 +223,8 @@ fn call_with_nvm_output(arg: &str) -> Result { #[instrument(level = "trace", skip_all)] fn call_with_nvm(arg: &str) -> Result<()> { run_command(Command::new("bash") - .args(&["-c", &format!("source ~/.nvm/nvm.sh && {}", arg)]) + .args(&["-c", &format!("source ~/.nvm/nvm.sh && {}", arg)]), + false, )?; Ok(()) } @@ -228,7 +232,8 @@ fn call_with_nvm(arg: &str) -> Result<()> { #[instrument(level = "trace", skip_all)] fn call_rustup(arg: &str) -> Result<()> { run_command(Command::new("bash") - .args(&["-c", &format!("rustup {}", arg)]) + .args(&["-c", &format!("rustup {}", arg)]), + false, )?; Ok(()) } @@ -241,7 +246,8 @@ fn call_cargo(arg: &str) -> Result<()> { format!("cargo --color=always {}", arg) }; run_command(Command::new("bash") - .args(&["-c", &command]) + .args(&["-c", &command]), + false, )?; Ok(()) } @@ -293,7 +299,8 @@ fn check_rust_toolchains_targets() -> Result> { run_command(Command::new("rustup") .args(&["default", "stable"]) .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stderr(Stdio::null()), + false, )?; let output = Command::new("rustup") .arg("show") @@ -322,7 +329,8 @@ fn check_rust_toolchains_targets() -> Result> { run_command(Command::new("rustup") .args(&["default", "nightly"]) .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stderr(Stdio::null()), + false, )?; let output = Command::new("rustup") .arg("show") @@ -341,7 +349,8 @@ fn check_rust_toolchains_targets() -> Result> { run_command(Command::new("rustup") .args(&["default", original_default]) .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stderr(Stdio::null()), + false, )?; Ok(missing_deps) } @@ -434,7 +443,7 @@ pub fn check_foundry_deps() -> Result> { // install forge+anvil+others, could be separated into binary extractions from github releases. pub fn install_foundry() -> Result<()> { let install_cmd = "curl -L https://foundry.paradigm.xyz | bash"; - run_command(Command::new("bash").args(&["-c", install_cmd]))?; + run_command(Command::new("bash").args(&["-c", install_cmd]), false)?; Ok(()) } diff --git a/src/update/mod.rs b/src/update/mod.rs index 2951c210..5d6cbd21 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -5,7 +5,7 @@ use fs_err as fs; use tracing::instrument; use crate::KIT_CACHE; -//use crate::build; +use crate::build::run_command; #[instrument(level = "trace", skip_all)] pub fn execute(mut user_args: Vec, branch: &str) -> Result<()> { @@ -19,10 +19,8 @@ pub fn execute(mut user_args: Vec, branch: &str) -> Result<()> { .map(|v| v.to_string()) .collect(); args.append(&mut user_args); - let mut update_process = Command::new("cargo") - .args(&args[..]) - .spawn()?; - update_process.wait()?; + + run_command(Command::new("cargo").args(&args[..]), true)?; let cache_path = format!("{}/kinode-dao-kit-commits", KIT_CACHE); let cache_path = std::path::Path::new(&cache_path); From b32bff3bc4c4f47123a9fb1dcb5bbed08c18671f Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 24 May 2024 16:56:51 -0700 Subject: [PATCH 2/2] add `--verbose` flag --- Cargo.lock | 2 +- src/boot_fake_node/mod.rs | 1 + src/build/mod.rs | 82 +++++++++++++++++++++------------- src/build_start_package/mod.rs | 3 +- src/chain/mod.rs | 7 +-- src/dev_ui/mod.rs | 2 +- src/main.rs | 49 ++++++++++++++++++-- src/run_tests/mod.rs | 5 ++- src/setup/mod.rs | 59 +++++++++++++----------- 9 files changed, 142 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bba2365a..74fd4029 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1332,7 +1332,7 @@ dependencies = [ [[package]] name = "kit" -version = "0.5.1" +version = "0.5.2" dependencies = [ "anyhow", "base64", diff --git a/src/boot_fake_node/mod.rs b/src/boot_fake_node/mod.rs index c327df58..48f0d111 100644 --- a/src/boot_fake_node/mod.rs +++ b/src/boot_fake_node/mod.rs @@ -432,6 +432,7 @@ pub async fn execute( fakechain_port, true, recv_kill_in_start_chain, + false, ).await?; if node_home.exists() { diff --git a/src/build/mod.rs b/src/build/mod.rs index c0959dfb..16d61334 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -101,6 +101,7 @@ pub async fn download_file(url: &str, path: &Path) -> Result<()> { async fn compile_javascript_wasm_process( process_dir: &Path, valid_node: Option, + verbose: bool, ) -> Result<()> { info!( "Compiling Javascript Kinode process in {:?}...", @@ -132,14 +133,14 @@ async fn compile_javascript_wasm_process( Command::new("bash") .args(&["-c", &install]) .current_dir(process_dir), - false, + verbose, )?; run_command( Command::new("bash") .args(&["-c", &componentize]) .current_dir(process_dir), - false, + verbose, )?; info!( @@ -150,7 +151,11 @@ async fn compile_javascript_wasm_process( } #[instrument(level = "trace", skip_all)] -async fn compile_python_wasm_process(process_dir: &Path, python: &str) -> Result<()> { +async fn compile_python_wasm_process( + process_dir: &Path, + python: &str, + verbose: bool, +) -> Result<()> { info!("Compiling Python Kinode process in {:?}...", process_dir); let wit_dir = process_dir.join("wit"); download_file(KINODE_WIT_URL, &wit_dir.join("kinode.wit")).await?; @@ -161,7 +166,7 @@ async fn compile_python_wasm_process(process_dir: &Path, python: &str) -> Result Command::new(python) .args(&["-m", "venv", PY_VENV_NAME]) .current_dir(process_dir), - false, + verbose, )?; run_command(Command::new("bash") .args(&[ @@ -169,7 +174,7 @@ async fn compile_python_wasm_process(process_dir: &Path, python: &str) -> Result &format!("source ../{PY_VENV_NAME}/bin/activate && pip install {REQUIRED_PY_PACKAGE} && componentize-py -d ../wit/ -w process componentize lib -o ../../pkg/{wasm_file_name}.wasm"), ]) .current_dir(process_dir.join("src")), - false, + verbose, )?; info!("Done compiling Python Kinode process in {:?}.", process_dir); @@ -180,6 +185,7 @@ async fn compile_python_wasm_process(process_dir: &Path, python: &str) -> Result async fn compile_rust_wasm_process( process_dir: &Path, features: &str, + verbose: bool, ) -> Result<()> { info!("Compiling Rust Kinode process in {:?}...", process_dir); @@ -212,7 +218,7 @@ async fn compile_rust_wasm_process( &bindings_dir.join("target.wasm").to_str().unwrap(), "--wasm", ]), - false, + verbose, )?; // Copy wit directory to bindings @@ -244,17 +250,20 @@ async fn compile_rust_wasm_process( args.push("--features"); args.push(&features); } - let (stdout, stderr) = run_command( + let result = run_command( Command::new("cargo") .args(&args) .current_dir(process_dir), - false, - )?.unwrap(); - if stdout.contains("warning") { - warn!("{}", stdout); - } - if stderr.contains("warning") { - warn!("{}", stderr); + verbose, + )?; + + if let Some((stdout, stderr)) = result { + if stdout.contains("warning") { + warn!("{}", stdout); + } + if stderr.contains("warning") { + warn!("{}", stderr); + } } // Adapt the module using wasm-tools @@ -280,7 +289,7 @@ async fn compile_rust_wasm_process( wasi_snapshot_file.to_str().unwrap(), ]) .current_dir(process_dir), - false, + verbose, )?; let wasm_path = format!("../pkg/{}.wasm", wasm_file_name); @@ -300,7 +309,7 @@ async fn compile_rust_wasm_process( wasm_path.to_str().unwrap(), ]) .current_dir(process_dir), - false, + verbose, )?; info!("Done compiling Rust Kinode process in {:?}.", process_dir); @@ -308,7 +317,11 @@ async fn compile_rust_wasm_process( } #[instrument(level = "trace", skip_all)] -async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Result<()> { +async fn compile_and_copy_ui( + package_dir: &Path, + valid_node: Option, + verbose: bool, +) -> Result<()> { let ui_path = package_dir.join("ui"); info!("Building UI in {:?}...", ui_path); @@ -334,7 +347,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Command::new("bash") .args(&["-c", &install]) .current_dir(&ui_path), - false, + verbose, )?; info!("Running npm run build:copy..."); @@ -343,7 +356,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Command::new("bash") .args(&["-c", &run]) .current_dir(&ui_path), - false, + verbose, )?; } else { let pkg_ui_path = package_dir.join("pkg/ui"); @@ -354,7 +367,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option) -> Command::new("cp") .args(["-r", "ui", "pkg/ui"]) .current_dir(&package_dir), - false, + verbose, )?; } } else { @@ -371,9 +384,10 @@ async fn compile_package_and_ui( valid_node: Option, skip_deps_check: bool, features: &str, + verbose: bool, ) -> Result<()> { - compile_and_copy_ui(package_dir, valid_node).await?; - compile_package(package_dir, skip_deps_check, features).await?; + compile_and_copy_ui(package_dir, valid_node, verbose).await?; + compile_package(package_dir, skip_deps_check, features, verbose).await?; Ok(()) } @@ -381,19 +395,20 @@ async fn compile_package_and_ui( async fn compile_package_item( entry: std::io::Result, features: String, + verbose: bool, ) -> Result<()> { let entry = entry?; let path = entry.path(); if path.is_dir() { if path.join(RUST_SRC_PATH).exists() { - compile_rust_wasm_process(&path, &features).await?; + compile_rust_wasm_process(&path, &features, verbose).await?; } else if path.join(PYTHON_SRC_PATH).exists() { let python = get_python_version(None, None)? .ok_or_else(|| eyre!("kit requires Python 3.10 or newer"))?; - compile_python_wasm_process(&path, &python).await?; + compile_python_wasm_process(&path, &python, verbose).await?; } else if path.join(JAVASCRIPT_SRC_PATH).exists() { let valid_node = get_newest_valid_node_version(None, None)?; - compile_javascript_wasm_process(&path, valid_node).await?; + compile_javascript_wasm_process(&path, valid_node, verbose).await?; } } Ok(()) @@ -404,6 +419,7 @@ async fn compile_package( package_dir: &Path, skip_deps_check: bool, features: &str, + verbose: bool, ) -> Result<()> { let mut checked_rust = false; let mut checked_py = false; @@ -414,14 +430,14 @@ async fn compile_package( if path.is_dir() { if path.join(RUST_SRC_PATH).exists() && !checked_rust && !skip_deps_check { let deps = check_rust_deps()?; - get_deps(deps)?; + get_deps(deps, verbose)?; checked_rust = true; } else if path.join(PYTHON_SRC_PATH).exists() && !checked_py { check_py_deps()?; checked_py = true; } else if path.join(JAVASCRIPT_SRC_PATH).exists() && !checked_js && !skip_deps_check { let deps = check_js_deps()?; - get_deps(deps)?; + get_deps(deps, verbose)?; checked_js = true; } } @@ -430,7 +446,7 @@ async fn compile_package( let mut tasks = tokio::task::JoinSet::new(); let features = features.to_string(); for entry in package_dir.read_dir()? { - tasks.spawn(compile_package_item(entry, features.clone())); + tasks.spawn(compile_package_item(entry, features.clone(), verbose.clone())); } while let Some(res) = tasks.join_next().await { res??; @@ -446,6 +462,7 @@ pub async fn execute( ui_only: bool, skip_deps_check: bool, features: &str, + verbose: bool, ) -> Result<()> { if !package_dir.join("pkg").exists() { if Some(".DS_Store") == package_dir.file_name().and_then(|s| s.to_str()) { @@ -463,25 +480,26 @@ pub async fn execute( if ui_only { return Err(eyre!("kit build: can't build UI: no ui directory exists")); } else { - compile_package(package_dir, skip_deps_check, features).await + compile_package(package_dir, skip_deps_check, features, verbose).await } } else { if no_ui { - return compile_package(package_dir, skip_deps_check, features).await; + return compile_package(package_dir, skip_deps_check, features, verbose).await; } let deps = check_js_deps()?; - get_deps(deps)?; + get_deps(deps, verbose)?; let valid_node = get_newest_valid_node_version(None, None)?; if ui_only { - compile_and_copy_ui(package_dir, valid_node).await + compile_and_copy_ui(package_dir, valid_node, verbose).await } else { compile_package_and_ui( package_dir, valid_node, skip_deps_check, features, + verbose, ).await } } diff --git a/src/build_start_package/mod.rs b/src/build_start_package/mod.rs index 92d23f2b..0ab4e634 100644 --- a/src/build_start_package/mod.rs +++ b/src/build_start_package/mod.rs @@ -14,8 +14,9 @@ pub async fn execute( url: &str, skip_deps_check: bool, features: &str, + verbose: bool, ) -> Result<()> { - build::execute(package_dir, no_ui, ui_only, skip_deps_check, features).await?; + build::execute(package_dir, no_ui, ui_only, skip_deps_check, features, verbose).await?; start_package::execute(package_dir, url).await?; Ok(()) } diff --git a/src/chain/mod.rs b/src/chain/mod.rs index 128ec326..58839a33 100644 --- a/src/chain/mod.rs +++ b/src/chain/mod.rs @@ -37,9 +37,10 @@ pub async fn start_chain( port: u16, piped: bool, recv_kill: BroadcastRecvBool, + verbose: bool, ) -> Result> { let deps = check_foundry_deps()?; - get_deps(deps)?; + get_deps(deps, verbose)?; let state_hash = write_kinostate().await?; let state_path = format!("./kinostate-{}.json", state_hash); @@ -121,7 +122,7 @@ async fn wait_for_anvil( /// kit chain, alias to anvil #[instrument(level = "trace", skip_all)] -pub async fn execute(port: u16) -> Result<()> { +pub async fn execute(port: u16, verbose: bool) -> Result<()> { let (send_to_cleanup, mut recv_in_cleanup) = tokio::sync::mpsc::unbounded_channel(); let (send_to_kill, _recv_kill) = tokio::sync::broadcast::channel(1); let recv_kill_in_cos = send_to_kill.subscribe(); @@ -129,7 +130,7 @@ pub async fn execute(port: u16) -> Result<()> { let handle_signals = tokio::spawn(cleanup_on_signal(send_to_cleanup.clone(), recv_kill_in_cos)); let recv_kill_in_start_chain = send_to_kill.subscribe(); - let child = start_chain(port, false, recv_kill_in_start_chain).await?; + let child = start_chain(port, false, recv_kill_in_start_chain, verbose).await?; let Some(mut child) = child else { return Err(eyre!("Port {} is already in use by another anvil process", port)); }; diff --git a/src/dev_ui/mod.rs b/src/dev_ui/mod.rs index 554f06cb..60cf0f85 100644 --- a/src/dev_ui/mod.rs +++ b/src/dev_ui/mod.rs @@ -16,7 +16,7 @@ pub fn execute( ) -> Result<()> { if !skip_deps_check { let deps = check_js_deps()?; - get_deps(deps)?; + get_deps(deps, false)?; } let valid_node = get_newest_valid_node_version(None, None)?; diff --git a/src/main.rs b/src/main.rs index 571fe474..0ad4611f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,8 +173,16 @@ async fn execute( Some(f) => f.clone(), None => "".into(), }; + let verbose = build_matches.get_one::("VERBOSE").unwrap(); - build::execute(&package_dir, *no_ui, *ui_only, *skip_deps_check, &features).await + build::execute( + &package_dir, + *no_ui, + *ui_only, + *skip_deps_check, + &features, + *verbose, + ).await } Some(("build-start-package", build_start_matches)) => { let package_dir = PathBuf::from(build_start_matches.get_one::("DIR").unwrap()); @@ -196,6 +204,7 @@ async fn execute( Some(f) => f.clone(), None => "".into(), }; + let verbose = build_start_matches.get_one::("VERBOSE").unwrap(); build_start_package::execute( &package_dir, @@ -204,12 +213,14 @@ async fn execute( &url, *skip_deps_check, &features, + *verbose, ) .await } Some(("chain", chain_matches)) => { let port = chain_matches.get_one::("PORT").unwrap(); - chain::execute(*port).await + let verbose = chain_matches.get_one::("VERBOSE").unwrap(); + chain::execute(*port, *verbose).await } Some(("dev-ui", dev_ui_matches)) => { let package_dir = PathBuf::from(dev_ui_matches.get_one::("DIR").unwrap()); @@ -300,7 +311,11 @@ async fn execute( run_tests::execute(config_path.to_str().unwrap()).await } - Some(("setup", _setup_matches)) => setup::execute(), + Some(("setup", setup_matches)) => { + let verbose = setup_matches.get_one::("VERBOSE").unwrap(); + + setup::execute(*verbose) + } Some(("start-package", start_package_matches)) => { let package_dir = PathBuf::from(start_package_matches.get_one::("DIR").unwrap()); @@ -469,6 +484,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .help("Pass these comma-delimited feature flags to Rust cargo builds") .required(false) ) + .arg(Arg::new("VERBOSE") + .action(ArgAction::SetTrue) + .short('v') + .long("verbose") + .help("If set, output stdout and stderr") + .required(false) + ) ) .subcommand(Command::new("build-start-package") .about("Build and start a Kinode package") @@ -518,6 +540,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .help("Pass these comma-delimited feature flags to Rust cargo builds") .required(false) ) + .arg(Arg::new("VERBOSE") + .action(ArgAction::SetTrue) + .short('v') + .long("verbose") + .help("If set, output stdout and stderr") + .required(false) + ) ) .subcommand(Command::new("chain") .about("Start a local chain for development") @@ -530,6 +559,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .default_value("8545") .value_parser(value_parser!(u16)) ) + .arg(Arg::new("VERBOSE") + .action(ArgAction::SetTrue) + .short('v') + .long("verbose") + .help("If set, output stdout and stderr") + .required(false) + ) ) .subcommand(Command::new("dev-ui") .about("Start the web UI development server with hot reloading (same as `cd ui && npm i && npm run dev`)") @@ -712,6 +748,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { ) .subcommand(Command::new("setup") .about("Fetch & setup kit dependencies") + .arg(Arg::new("VERBOSE") + .action(ArgAction::SetTrue) + .short('v') + .long("verbose") + .help("If set, output stdout and stderr") + .required(false) + ) ) .subcommand(Command::new("start-package") .about("Start a built Kinode process") diff --git a/src/run_tests/mod.rs b/src/run_tests/mod.rs index 729d46b2..c0569914 100644 --- a/src/run_tests/mod.rs +++ b/src/run_tests/mod.rs @@ -293,10 +293,10 @@ async fn run_tests( #[instrument(level = "trace", skip_all)] async fn handle_test(detached: bool, runtime_path: &Path, test: Test) -> Result<()> { for setup_package_path in &test.setup_package_paths { - build::execute(&setup_package_path, false, false, false, "").await?; + build::execute(&setup_package_path, false, false, false, "", false).await?; } for TestPackage { ref path, .. } in &test.test_packages { - build::execute(path, false, false, false, "").await?; + build::execute(path, false, false, false, "", false).await?; } // Initialize variables for master node and nodes list @@ -332,6 +332,7 @@ async fn handle_test(detached: bool, runtime_path: &Path, test: Test) -> Result< test.fakechain_router, true, recv_kill_in_start_chain, + false, ).await?; // Process each node diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 033fe523..4212d149 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -67,7 +67,7 @@ fn is_nvm_installed() -> Result { } #[instrument(level = "trace", skip_all)] -fn install_nvm() -> Result<()> { +fn install_nvm(verbose: bool) -> Result<()> { info!("Getting nvm..."); let install_nvm = format!( "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/{}/install.sh | bash", @@ -75,7 +75,7 @@ fn install_nvm() -> Result<()> { ); run_command(Command::new("bash") .args(&["-c", &install_nvm]), - false, + verbose, )?; info!("Done getting nvm."); @@ -83,12 +83,12 @@ fn install_nvm() -> Result<()> { } #[instrument(level = "trace", skip_all)] -fn install_rust() -> Result<()> { +fn install_rust(verbose: bool) -> Result<()> { info!("Getting rust..."); let install_rust = "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"; run_command(Command::new("bash") .args(&["-c", install_rust]), - false, + verbose, )?; info!("Done getting rust."); @@ -221,25 +221,25 @@ fn call_with_nvm_output(arg: &str) -> Result { } #[instrument(level = "trace", skip_all)] -fn call_with_nvm(arg: &str) -> Result<()> { +fn call_with_nvm(arg: &str, verbose: bool) -> Result<()> { run_command(Command::new("bash") .args(&["-c", &format!("source ~/.nvm/nvm.sh && {}", arg)]), - false, + verbose, )?; Ok(()) } #[instrument(level = "trace", skip_all)] -fn call_rustup(arg: &str) -> Result<()> { +fn call_rustup(arg: &str, verbose: bool) -> Result<()> { run_command(Command::new("bash") .args(&["-c", &format!("rustup {}", arg)]), - false, + verbose, )?; Ok(()) } #[instrument(level = "trace", skip_all)] -fn call_cargo(arg: &str) -> Result<()> { +fn call_cargo(arg: &str, verbose: bool) -> Result<()> { let command = if arg.contains("--color=always") { format!("cargo {}", arg) } else { @@ -247,7 +247,7 @@ fn call_cargo(arg: &str) -> Result<()> { }; run_command(Command::new("bash") .args(&["-c", &command]), - false, + verbose, )?; Ok(()) } @@ -470,7 +470,7 @@ pub fn check_rust_deps() -> Result> { } #[instrument(level = "trace", skip_all)] -pub fn get_deps(deps: Vec) -> Result<()> { +pub fn get_deps(deps: Vec, verbose: bool) -> Result<()> { if deps.is_empty() { return Ok(()); } @@ -495,22 +495,31 @@ pub fn get_deps(deps: Vec) -> Result<()> { "y" | "yes" | "" => { for dep in deps { match dep { - Dependency::Nvm => install_nvm()?, - Dependency::Npm => call_with_nvm(&format!("nvm install-latest-npm"))?, + Dependency::Nvm => install_nvm(verbose)?, + Dependency::Npm => call_with_nvm( + &format!("nvm install-latest-npm"), + verbose, + )?, Dependency::Node => { - call_with_nvm(&format!( - "nvm install {}.{}", - REQUIRED_NODE_MAJOR, - MINIMUM_NODE_MINOR, - ))? + call_with_nvm( + &format!( + "nvm install {}.{}", + REQUIRED_NODE_MAJOR, + MINIMUM_NODE_MINOR, + ), + verbose, + )? }, - Dependency::Rust => install_rust()?, - Dependency::RustNightly => call_rustup("install nightly")?, - Dependency::RustWasm32Wasi => call_rustup("target add wasm32-wasi")?, + Dependency::Rust => install_rust(verbose)?, + Dependency::RustNightly => call_rustup("install nightly", verbose)?, + Dependency::RustWasm32Wasi => call_rustup( + "target add wasm32-wasi", + verbose, + )?, Dependency::RustNightlyWasm32Wasi => { - call_rustup("target add wasm32-wasi --toolchain nightly")? + call_rustup("target add wasm32-wasi --toolchain nightly", verbose)? }, - Dependency::WasmTools => call_cargo("install wasm-tools")?, + Dependency::WasmTools => call_cargo("install wasm-tools", verbose)?, Dependency::Forge | Dependency::Anvil => { install_foundry()? }, @@ -523,13 +532,13 @@ pub fn get_deps(deps: Vec) -> Result<()> { } #[instrument(level = "trace", skip_all)] -pub fn execute() -> Result<()> { +pub fn execute(verbose: bool) -> Result<()> { info!("Setting up..."); check_py_deps()?; let mut missing_deps = check_js_deps()?; missing_deps.append(&mut check_rust_deps()?); - get_deps(missing_deps)?; + get_deps(missing_deps, verbose)?; info!("Done setting up."); Ok(())