Cargo: rerun-if-changed on directory does not rerun on new timestamp or file contents

Created on 21 Apr 2016  路  9Comments  路  Source: rust-lang/cargo

I did println!("cargo:rerun-if-changed=dir") where dir is a directory in the same directory as Cargo.toml.

I expected the build script to rerun if any file within dir changes its timestamp or contents. However, it only reruns if files are created or deleted.

I have created a quick-and-dirty test script in this crate. This is the output:

$ uname -mrs
Darwin 13.4.0 x86_64
$ cargo -V
cargo 0.11.0-nightly (d99a7eb 2016-04-19)
$ ./test.sh
......
[PASS] no rerun with no changes
[FAIL] no rerun with changed timestamp
[PASS] rerun with new file
[FAIL] no rerun with changed file contents
[PASS] rerun with deleted file

cc @huonw

A-documenting-cargo-itself

Most helpful comment

Could rerun-if-changed support globs?

All 9 comments

This is not a regression (it never worked as described in the docs). Same pattern with cargo 0.9 and 0.10.

For sanity: deleting both rerun-if-changed lines from build.rs this is the output:

$ ./test.sh
......
[FAIL] rerun with no changes
[PASS] rerun with changed timestamp
[PASS] rerun with new file
[PASS] rerun with changed file contents
[PASS] rerun with deleted file

Yeah this is actually intended behavior. Cargo does not traverse a directory and try to find changes inside, but rather it just looks at the mtime of the directory itself (which can vary depending on platform when it's updated).

This was discussed in the original implementation and the special support for directories was explicitly removed.

Thanks for the report though!

Please reopen as docs bug, as this is not clear at all.

So how do I say "please rerun the build script if files are created or deleted or changed within this dir"? Do I need to print a line for the directory itself and every file/directory within it?

Ah yeah a docs bug is fine.

And yeah, you'll need to print a line per file in the directory you care about.

Could rerun-if-changed support globs?

Perhaps, yeah, but it's arguably much simpler to keep track of specific files (someone's gonna have to do it).

Is there a way to add extra file detection, but overwrite the default?
I want to be able to re-run the build script when all source code and git changes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alilleybrinker picture alilleybrinker  路  3Comments

dotnetspec picture dotnetspec  路  3Comments

sdroege picture sdroege  路  3Comments

ehuss picture ehuss  路  3Comments

rask picture rask  路  3Comments