improve robustness of runtime build (esp w kit)

This commit is contained in:
hosted-fornet 2024-12-02 16:19:06 -08:00
parent a780a575ff
commit 8200ecb6a7

View File

@ -30,7 +30,23 @@ fn compute_hash(file_path: &Path) -> anyhow::Result<String> {
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)?;