Skip to content

Commit

Permalink
add --verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed May 24, 2024
1 parent 695666a commit b32bff3
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/boot_fake_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ pub async fn execute(
fakechain_port,
true,
recv_kill_in_start_chain,
false,
).await?;

if node_home.exists() {
Expand Down
82 changes: 50 additions & 32 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
verbose: bool,
) -> Result<()> {
info!(
"Compiling Javascript Kinode process in {:?}...",
Expand Down Expand Up @@ -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!(
Expand All @@ -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?;
Expand All @@ -161,15 +166,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,
verbose,
)?;
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")),
false,
verbose,
)?;

info!("Done compiling Python Kinode process in {:?}.", process_dir);
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -300,15 +309,19 @@ 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);
Ok(())
}

#[instrument(level = "trace", skip_all)]
async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option<String>) -> Result<()> {
async fn compile_and_copy_ui(
package_dir: &Path,
valid_node: Option<String>,
verbose: bool,
) -> Result<()> {
let ui_path = package_dir.join("ui");
info!("Building UI in {:?}...", ui_path);

Expand All @@ -334,7 +347,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option<String>) ->
Command::new("bash")
.args(&["-c", &install])
.current_dir(&ui_path),
false,
verbose,
)?;

info!("Running npm run build:copy...");
Expand All @@ -343,7 +356,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option<String>) ->
Command::new("bash")
.args(&["-c", &run])
.current_dir(&ui_path),
false,
verbose,
)?;
} else {
let pkg_ui_path = package_dir.join("pkg/ui");
Expand All @@ -354,7 +367,7 @@ async fn compile_and_copy_ui(package_dir: &Path, valid_node: Option<String>) ->
Command::new("cp")
.args(["-r", "ui", "pkg/ui"])
.current_dir(&package_dir),
false,
verbose,
)?;
}
} else {
Expand All @@ -371,29 +384,31 @@ async fn compile_package_and_ui(
valid_node: Option<String>,
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(())
}

#[instrument(level = "trace", skip_all)]
async fn compile_package_item(
entry: std::io::Result<std::fs::DirEntry>,
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(())
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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??;
Expand All @@ -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()) {
Expand All @@ -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
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/build_start_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
7 changes: 4 additions & 3 deletions src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ pub async fn start_chain(
port: u16,
piped: bool,
recv_kill: BroadcastRecvBool,
verbose: bool,
) -> Result<Option<Child>> {
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);
Expand Down Expand Up @@ -121,15 +122,15 @@ 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();

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));
};
Expand Down
2 changes: 1 addition & 1 deletion src/dev_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
Loading

0 comments on commit b32bff3

Please sign in to comment.