From b32bff3bc4c4f47123a9fb1dcb5bbed08c18671f Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 24 May 2024 16:56:51 -0700 Subject: [PATCH] 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(())