diff --git a/Cargo.lock b/Cargo.lock index d5efb296..0c764f2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1403,7 +1403,7 @@ dependencies = [ ] [[package]] -name = "build_package" +name = "build_packages" version = "0.1.0" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 9b14b678..f44e6005 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ members = [ "kinode/packages/terminal/help", "kinode/packages/terminal/hi", "kinode/packages/terminal/kfetch", "kinode/packages/terminal/kill", "kinode/packages/terminal/m", "kinode/packages/terminal/top", "kinode/packages/terminal/net_diagnostics", "kinode/packages/terminal/peer", "kinode/packages/terminal/peers", - "kinode/packages/tester/tester", "scripts/build_package", + "kinode/packages/tester/tester", "scripts/build_packages", ] default-members = ["lib"] resolver = "2" diff --git a/kinode/build.rs b/kinode/build.rs index 8250dac9..5ac4a90e 100644 --- a/kinode/build.rs +++ b/kinode/build.rs @@ -2,21 +2,24 @@ use std::path::PathBuf; const CANONICAL_PACKAGES_ZIP_PATH: &str = "../target/packages.zip"; +macro_rules! p { + ($($tokens: tt)*) => { + println!("cargo:warning={}", format!($($tokens)*)) + } +} + fn main() -> anyhow::Result<()> { let path_to_packages_zip = match std::env::var("PATH_TO_PACKAGES_ZIP") { - Err(_) => { - let build_package_script_path = PathBuf::from("../scripts/build_package"); - let mut child = std::process::Command::new("cargo") - .arg("run") - .current_dir(&build_package_script_path) - .spawn()?; - let result = child.wait()?; - if !result.success() { - return Err(anyhow::anyhow!("Failed to build packages.")); - } - CANONICAL_PACKAGES_ZIP_PATH.to_string() - } Ok(env_var) => env_var, + Err(_) => { + let canonical_path = PathBuf::from(CANONICAL_PACKAGES_ZIP_PATH); + if canonical_path.exists() { + p!("No path given via PATH_TO_PACKAGES_ZIP envvar. Defaulting to path of `kinode/target/packages.zip`."); + CANONICAL_PACKAGES_ZIP_PATH.to_string() + } else { + return Err(anyhow::anyhow!("You must build packages.zip with scripts/build_packages or set PATH_TO_PACKAGES_ZIP to point to your desired pacakges.zip (default path at kinode/target/packages.zip was not populated).")); + } + } }; let path = PathBuf::from(&path_to_packages_zip); if !path.exists() { diff --git a/scripts/build_package/Cargo.toml b/scripts/build_packages/Cargo.toml similarity index 90% rename from scripts/build_package/Cargo.toml rename to scripts/build_packages/Cargo.toml index 824917a6..fe507b3e 100644 --- a/scripts/build_package/Cargo.toml +++ b/scripts/build_packages/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "build_package" +name = "build_packages" version = "0.1.0" edition = "2021" diff --git a/scripts/build_package/src/main.rs b/scripts/build_packages/src/main.rs similarity index 97% rename from scripts/build_package/src/main.rs rename to scripts/build_packages/src/main.rs index a76fcb32..f80a99c9 100644 --- a/scripts/build_package/src/main.rs +++ b/scripts/build_packages/src/main.rs @@ -70,7 +70,7 @@ fn build_and_zip_package( } fn main() -> anyhow::Result<()> { - let matches = Command::new("build_package") + let matches = Command::new("build_packages") .about("Build the core Kinode packages.") .arg( Arg::new("FEATURES") @@ -167,8 +167,7 @@ fn main() -> anyhow::Result<()> { Ok((entry_path, zip_filename, zip_contents)) => { let metadata_path = entry_path.join("metadata.json"); let metadata_contents = fs::read_to_string(&metadata_path)?; - let metadata_contents: serde_json::Value = - serde_json::from_str(&metadata_contents)?; + let metadata_contents: serde_json::Value = serde_json::from_str(&metadata_contents)?; file_to_metadata.insert(zip_filename.clone(), metadata_contents); let zip_path = target_packages_dir.join(&zip_filename); fs::write(&zip_path, &zip_contents)?;