Skip to content

Commit a1cdb34

Browse files
authored
build: harden rerun-if-changed path handling (#439)
* build: harden rerun-if-changed path handling * build: add rerun-if-changed fallback * build: inline format arg
1 parent ee82dce commit a1cdb34

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/build/src/utils.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ pub(crate) fn cargo_rerun_if_changed(metadata: &Metadata, program_dir: &Path) {
2020
];
2121
for dir in dirs {
2222
if dir.exists() {
23-
println!("cargo::rerun-if-changed={}", dir.canonicalize().unwrap().display());
23+
if let Ok(canonical_path) = dir.canonicalize() {
24+
println!("cargo::rerun-if-changed={}", canonical_path.display());
25+
} else {
26+
println!(
27+
"cargo::warning=Could not canonicalize path: {dir:?}, using original path"
28+
);
29+
println!("cargo::rerun-if-changed={}", dir.display());
30+
}
2431
}
2532
}
2633

2734
// Re-run the build script if the workspace root's Cargo.lock changes. If the program is its own
2835
// workspace, this will be the program's Cargo.lock.
29-
println!("cargo:rerun-if-changed={}", metadata.workspace_root.join("Cargo.lock").as_str());
36+
println!("cargo::rerun-if-changed={}", metadata.workspace_root.join("Cargo.lock").as_str());
3037

3138
// Re-run if any local dependency changes.
3239
for package in &metadata.packages {
3340
for dependency in &package.dependencies {
3441
if let Some(path) = &dependency.path {
35-
println!("cargo:rerun-if-changed={}", path.as_str());
42+
println!("cargo::rerun-if-changed={}", path.as_str());
3643
}
3744
}
3845
}

0 commit comments

Comments
 (0)