Skip to content

Commit

Permalink
manifest: warn if path of rerun-if-changed=PATH does not point to exi…
Browse files Browse the repository at this point in the history
…sting file.

Fixes rust-lang#6003
  • Loading branch information
matthiaskrgr committed Sep 13, 2018
1 parent c514b94 commit ed17a51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,17 @@ fn build_script_local_fingerprints<'a, 'cfg>(
// dependencies.
let deps = &cx.build_explicit_deps[unit];
let output = deps.build_script_output.clone();

// check if rerun_if_changed paths corresponds to existing files and warn if not (#6003)
for path in &deps.rerun_if_changed {
if !path.exists() {
cx.bcx.config.shell().warn(format!(
"\"cargo:rerun-if-changed\" file \"{}\" not found.",
path.display()
))?;
}
}

if deps.rerun_if_changed.is_empty() && deps.rerun_if_env_changed.is_empty() {
debug!("old local fingerprints deps");
let s = pkg_fingerprint(&cx.bcx, unit.pkg)?;
Expand Down Expand Up @@ -630,6 +641,7 @@ fn local_fingerprints_deps(

for var in deps.rerun_if_env_changed.iter() {
let val = env::var(var).ok();
// check if the vlu
local.push(LocalFingerprint::EnvBased(var.clone(), val));
}

Expand Down
5 changes: 4 additions & 1 deletion tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,8 @@ fn rebuild_only_on_explicit_paths() {
p.cargo("build -v")
.with_stderr(
"\
[WARNING] \"cargo:rerun-if-changed\" file \"foo\" not found.
[WARNING] \"cargo:rerun-if-changed\" file \"bar\" not found.
[COMPILING] foo v0.5.0 ([..])
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
Expand All @@ -2350,7 +2352,7 @@ fn rebuild_only_on_explicit_paths() {
File::create(p.root().join("bar")).unwrap();
sleep_ms(1000); // make sure the to-be-created outfile has a timestamp distinct from the infiles

// now the exist, so run once, catch the mtime, then shouldn't run again
// now they exist, so run once, catch the mtime, then shouldn't run again
println!("run with");
p.cargo("build -v")
.with_stderr(
Expand Down Expand Up @@ -2403,6 +2405,7 @@ fn rebuild_only_on_explicit_paths() {
p.cargo("build -v")
.with_stderr(
"\
[WARNING] \"cargo:rerun-if-changed\" file \"bar\" not found.
[COMPILING] foo v0.5.0 ([..])
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
Expand Down

0 comments on commit ed17a51

Please sign in to comment.