diff --git a/kinode/build.rs b/kinode/build.rs index 41279366..b5d8b8be 100644 --- a/kinode/build.rs +++ b/kinode/build.rs @@ -30,7 +30,23 @@ fn compute_hash(file_path: &Path) -> anyhow::Result { fn main() -> anyhow::Result<()> { let path_to_packages_zip = match std::env::var("PATH_TO_PACKAGES_ZIP") { - Ok(env_var) => env_var, + Ok(env_var) => { + let path = PathBuf::from(&env_var); + if !path.exists() { + let path = std::env::current_dir()?; + let Some(path) = path.parent() else { + return Err(anyhow::anyhow!("Given path to packages {env_var} not found (cwd: {:?})", std::env::current_dir())); + }; + let path = path.join(&env_var); + if path.exists() { + path.display().to_string() + } else { + return Err(anyhow::anyhow!("Given path to packages {env_var} not found in parent of cwd: {:?}", std::env::current_dir())); + } + } else { + env_var + } + } Err(_) => { let canonical_path = PathBuf::from(CANONICAL_PACKAGES_ZIP_PATH); if canonical_path.exists() { @@ -49,6 +65,10 @@ fn main() -> anyhow::Result<()> { } let path_to_packages_zip_path = PathBuf::from(&path_to_packages_zip).canonicalize()?; + let canonical_packages_zip_path = PathBuf::from(CANONICAL_PACKAGES_ZIP_PATH); + if !canonical_packages_zip_path.exists() { + std::fs::File::create(&canonical_packages_zip_path)?; + } let canonical_packages_zip_path = PathBuf::from(CANONICAL_PACKAGES_ZIP_PATH).canonicalize()?; if path_to_packages_zip_path != canonical_packages_zip_path { std::fs::copy(&path_to_packages_zip_path, &canonical_packages_zip_path)?;