Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rerun-if-changed on directory does not rerun on new timestamp or file contents #2599

Closed
durka opened this issue Apr 21, 2016 · 10 comments · Fixed by #2602
Closed

rerun-if-changed on directory does not rerun on new timestamp or file contents #2599

durka opened this issue Apr 21, 2016 · 10 comments · Fixed by #2602
Labels
A-documenting-cargo-itself Area: Cargo's documentation

Comments

@durka
Copy link
Contributor

durka commented Apr 21, 2016

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

@durka
Copy link
Contributor Author

durka commented Apr 21, 2016

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

@durka
Copy link
Contributor Author

durka commented Apr 21, 2016

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

@alexcrichton
Copy link
Member

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!

@durka
Copy link
Contributor Author

durka commented Apr 21, 2016

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

@durka
Copy link
Contributor Author

durka commented Apr 21, 2016

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?

@alexcrichton
Copy link
Member

Ah yeah a docs bug is fine.

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

@alexcrichton alexcrichton reopened this Apr 21, 2016
@alexcrichton alexcrichton added the A-documenting-cargo-itself Area: Cargo's documentation label Apr 21, 2016
durka added a commit to durka/rrict that referenced this issue Apr 21, 2016
bors added a commit that referenced this issue Apr 21, 2016
fix rerun-if-changed documentation

The documentation corresponded to the initial proposed implementation, which was changed to remove special handling of directories before it was ever merged.

closes #2599
r? @alexcrichton
@huonw
Copy link
Member

huonw commented Apr 21, 2016

Could rerun-if-changed support globs?

@alexcrichton
Copy link
Member

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

@umaYnit
Copy link

umaYnit commented Dec 27, 2020

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.

@kupiakos
Copy link

kupiakos commented May 5, 2022

Note from the future: Cargo will rescan an entire directory recursively for changes, done in cee088b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants