From 063155cbca91b76a813be69661de6cd76a4345a9 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 1 Apr 2024 17:23:53 -0700 Subject: [PATCH 1/3] build.rs: rebuild packages if they have changed --- kinode/build.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kinode/build.rs b/kinode/build.rs index 47b0b8e56..f872f1b85 100644 --- a/kinode/build.rs +++ b/kinode/build.rs @@ -1,5 +1,6 @@ use rayon::prelude::*; use std::{ + collections::HashSet, fs::{self, File}, io::{Cursor, Read, Write}, path::{Path, PathBuf}, @@ -22,6 +23,24 @@ fn get_features() -> String { features } +fn output_reruns(dir: &Path, rerun_files: &HashSet) { + if let Ok(entries) = fs::read_dir(dir) { + for entry in entries.filter_map(|e| e.ok()) { + let path = entry.path(); + if path.is_dir() { + // If the entry is a directory, recursively walk it + output_reruns(&path, rerun_files); + } else if let Some(filename) = path.file_name().and_then(|n| n.to_str()) { + // Check if the current file is in our list of interesting files + if rerun_files.contains(filename) { + // If so, print a `cargo:rerun-if-changed=PATH` line for it + println!("cargo:rerun-if-changed={}", path.display()); + } + } + } + } +} + fn build_and_zip_package( entry_path: PathBuf, parent_pkg_path: &str, @@ -76,6 +95,13 @@ fn main() -> anyhow::Result<()> { .map(|entry| entry.unwrap().path()) .collect(); + let rerun_files: HashSet = HashSet::from([ + "Cargo.lock".to_string(), + "Cargo.toml".to_string(), + "src/".to_string(), + ]); + output_reruns(&parent_dir, &rerun_files); + let features = get_features(); let results: Vec)>> = entries From 19516a1318e334c17ef92daf7c43b22979a00112 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 1 Apr 2024 17:25:48 -0700 Subject: [PATCH 2/3] app_store: return a failure when start a package if it fails --- .../packages/app_store/app_store/src/lib.rs | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/kinode/packages/app_store/app_store/src/lib.rs b/kinode/packages/app_store/app_store/src/lib.rs index 630100470..54623f6d0 100644 --- a/kinode/packages/app_store/app_store/src/lib.rs +++ b/kinode/packages/app_store/app_store/src/lib.rs @@ -686,25 +686,35 @@ pub fn handle_install( ))?) .send()?; - let _bytes_response = Request::to(("our", "vfs", "distro", "sys")) - .body(serde_json::to_vec(&vfs::VfsRequest { - path: wasm_path.clone(), - action: vfs::VfsAction::Read, - })?) - .send_and_await_response(5)??; + if let Ok(vfs::VfsResponse::Err(_)) = serde_json::from_slice( + Request::to(("our", "vfs", "distro", "sys")) + .body(serde_json::to_vec(&vfs::VfsRequest { + path: wasm_path.clone(), + action: vfs::VfsAction::Read, + })?) + .send_and_await_response(5)?? + .body() + ) { + return Err(anyhow::anyhow!("failed to read process file")); + }; - Request::new() - .target(("our", "kernel", "distro", "sys")) - .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { - id: parsed_new_process_id.clone(), - wasm_bytes_handle: wasm_path, - wit_version: None, - on_exit: entry.on_exit.clone(), - initial_capabilities: HashSet::new(), - public: entry.public, - })?) - .inherit(true) - .send_and_await_response(5)??; + let Ok(kt::KernelResponse::InitializedProcess) = serde_json::from_slice( + Request::new() + .target(("our", "kernel", "distro", "sys")) + .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { + id: parsed_new_process_id.clone(), + wasm_bytes_handle: wasm_path, + wit_version: None, + on_exit: entry.on_exit.clone(), + initial_capabilities: HashSet::new(), + public: entry.public, + })?) + .inherit(true) + .send_and_await_response(5)?? + .body() + ) else { + return Err(anyhow::anyhow!("failed to initialize process")); + }; // build initial caps let mut requested_capabilities: Vec = vec![]; for value in &entry.request_capabilities { @@ -829,11 +839,16 @@ pub fn handle_install( } } } - Request::to(("our", "kernel", "distro", "sys")) - .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( - parsed_new_process_id, - ))?) - .send_and_await_response(5)??; + let Ok(kt::KernelResponse::StartedProcess) = serde_json::from_slice( + Request::to(("our", "kernel", "distro", "sys")) + .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( + parsed_new_process_id, + ))?) + .send_and_await_response(5)?? + .body() + ) else { + return Err(anyhow::anyhow!("failed to start process")); + }; } // finally set the package as installed state.update_downloaded_package(package_id, |package_state| { From eaf347f05e5b9b488eb0bf4193f6729e11e7a54a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:26:23 +0000 Subject: [PATCH 3/3] Format Rust code using rustfmt --- kinode/packages/app_store/app_store/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kinode/packages/app_store/app_store/src/lib.rs b/kinode/packages/app_store/app_store/src/lib.rs index 54623f6d0..e534a6822 100644 --- a/kinode/packages/app_store/app_store/src/lib.rs +++ b/kinode/packages/app_store/app_store/src/lib.rs @@ -693,7 +693,7 @@ pub fn handle_install( action: vfs::VfsAction::Read, })?) .send_and_await_response(5)?? - .body() + .body(), ) { return Err(anyhow::anyhow!("failed to read process file")); }; @@ -711,7 +711,7 @@ pub fn handle_install( })?) .inherit(true) .send_and_await_response(5)?? - .body() + .body(), ) else { return Err(anyhow::anyhow!("failed to initialize process")); }; @@ -845,7 +845,7 @@ pub fn handle_install( parsed_new_process_id, ))?) .send_and_await_response(5)?? - .body() + .body(), ) else { return Err(anyhow::anyhow!("failed to start process")); };