Skip to content

rerun-if-changed always trigger rebuild on non-exist file #4213

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

Closed
bozaro opened this issue Jun 23, 2017 · 4 comments
Closed

rerun-if-changed always trigger rebuild on non-exist file #4213

bozaro opened this issue Jun 23, 2017 · 4 comments

Comments

@bozaro
Copy link

bozaro commented Jun 23, 2017

Original cause: bozaro/lz4-rs#21

Root cause:

  • I use skeptic for file README.md
  • Skeptic generate some code and tell to cargo:
cargo:rerun-if-changed=README.md
cargo:rerun-if-changed=README.md.skt.md
  • File README.md.skt.md is not presend in my project and cargo always rerun build.

I would expect that the restart will only happen if README.md.skt.md file appears.

Unfortunatelly, adding check for file exists in Skeptic is incorrect, because it should rerun if file appears at some time.

@bozaro bozaro changed the title rerun-if-changed alwas trigger rebuild on non-exits file rerun-if-changed always trigger rebuild on non-exist file Jun 23, 2017
@alexcrichton
Copy link
Member

Thanks for the report! This is expected behavior, though, for Cargo. Cargo needs to rerun a build script when a file is deleted, so if it's not present Cargo doesn't know whether it ws deleted or just didn't exist before.

@bozaro
Copy link
Author

bozaro commented Jun 23, 2017

I do not understand how you can correctly handle incremental compilation, when the appearance of a file can affect the state of the artifact.
For example, I can't tell cargo: rerun if the list of files changed. Something like:

cargo:rerun-wildcard=*.md

@alexcrichton
Copy link
Member

Yeah in general Cargo doesn't (and nor do most build systems) have the ability to get rerun when a file appears. Typically this works out as some other file indicate that said file appeared, but right now it's not possible to do so with Cargo.

jpastuszek pushed a commit to jpastuszek/liquid-rust that referenced this issue Sep 22, 2017
Build script calls skeptic which emits information asking cargo to monitor
content of README.md.skt.md for changes. If changes to that file are
detected cargo should rebuild liquid crate.
In case of this project the files does not exist. This causes
cargo to trigger a rebuild every time in hope that it will get crated by
the build script.
The workaround is to crate the file that skeptic asks to monitor which
stops cargo from triggering the rebuild.

For details consult this issues:

* budziq/rust-skeptic#25
* rust-lang/cargo#4213
jpastuszek pushed a commit to jpastuszek/liquid-rust that referenced this issue Sep 22, 2017
Build script calls skeptic which emits information asking cargo to monitor
content of README.md.skt.md for changes. If changes to that file are
detected cargo should rebuild liquid crate.
In case of this project the files does not exist. This causes
cargo to trigger a rebuild every time in hope that it will get created by
the build script.
The workaround is to create the file that skeptic asks to monitor which
stops cargo from triggering the rebuild.

For details consult this issues:

* budziq/rust-skeptic#25
* rust-lang/cargo#4213
epage added a commit to epage/assert_cli that referenced this issue Sep 24, 2017
Build script calls skeptic which emits information asking cargo to
monitor content of README.md.skt.md for changes. If changes to that file
are detected cargo should rebuild this crate.  In case of this project
the files does not exist. This causes cargo to trigger a rebuild every
time in hope that it will get created by the build script.

The workaround is to create the file that skeptic asks to monitor which
stops cargo from triggering the rebuild.

For details consult this issues:

* budziq/rust-skeptic#25
* rust-lang/cargo#4213
bors bot added a commit to assert-rs/assert_cli that referenced this issue Sep 24, 2017
40: Reduce needless recompiles r=epage a=epage

Build script calls skeptic which emits information asking cargo to
monitor content of README.md.skt.md for changes. If changes to that file
are detected cargo should rebuild this crate.  In case of this project
the files does not exist. This causes cargo to trigger a rebuild every
time in hope that it will get created by the build script.

The workaround is to create the file that skeptic asks to monitor which
stops cargo from triggering the rebuild.

For details consult this issues:

* budziq/rust-skeptic#25
* rust-lang/cargo#4213
mbrubeck added a commit to mbrubeck/rust-skeptic that referenced this issue Oct 26, 2017
budziq pushed a commit to budziq/rust-skeptic that referenced this issue Oct 27, 2017
jorenvo added a commit to jorenvo/ply-rs that referenced this issue Jan 23, 2018
skeptic causes cargo to monitor README.md.skt.md. This file does not
exist, nor is it created by any build script. Because of this cargo
will always rebuild.

Inspired by:
assert-rs/assert_cli@ccc8af5

More info:
budziq/rust-skeptic#25
rust-lang/cargo#4213
jorenvo added a commit to jorenvo/ply-rs that referenced this issue Jan 23, 2018
skeptic causes cargo to monitor README.md.skt.md. This file does not
exist, nor is it created by any build script. Because of this cargo
will always rebuild:

$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
... stale: /home/jvo/.cargo/registry/src/github.com-1ecc6299db9ec823/ply-rs-0.1.1/README.md.skt.md -- missing
... fingerprint error for ply-rs v0.1.1: mtime based components have changed

Inspired by:
assert-rs/assert_cli@ccc8af5

More info:
budziq/rust-skeptic#25
rust-lang/cargo#4213
jorenvo added a commit to jorenvo/ply-rs that referenced this issue Jan 23, 2018
skeptic causes cargo to monitor README.md.skt.md. This file does not
exist, nor is it created by any build script. Because of this cargo
will always rebuild:

$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
... stale: /home/.../ply-rs-0.1.1/README.md.skt.md -- missing
... fingerprint error for ply-rs v0.1.1: mtime based components have changed

Inspired by:
assert-rs/assert_cli@ccc8af5

More info:
budziq/rust-skeptic#25
rust-lang/cargo#4213
jorenvo added a commit to jorenvo/ply-rs that referenced this issue Jan 23, 2018
skeptic causes cargo to monitor README.md.skt.md. This file does not
exist, nor is it created by any build script. Because of this cargo
will always rebuild even if nothing has been changed:

$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
... stale: /home/.../ply-rs-0.1.1/README.md.skt.md -- missing
... fingerprint error for ply-rs v0.1.1: mtime based components have changed

Inspired by:
assert-rs/assert_cli@ccc8af5

More info:
budziq/rust-skeptic#25
rust-lang/cargo#4213
jorenvo added a commit to jorenvo/ply-rs that referenced this issue Jan 23, 2018
skeptic causes cargo to monitor README.md.skt.md. This file does not
exist, nor is it created by any build script. Because of this cargo
will always rebuild even if nothing has changed:

$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
... stale: /home/.../ply-rs-0.1.1/README.md.skt.md -- missing
... fingerprint error for ply-rs v0.1.1: mtime based components have changed

Inspired by:
assert-rs/assert_cli@ccc8af5

More info:
budziq/rust-skeptic#25
rust-lang/cargo#4213
jorenvo added a commit to jorenvo/ply-rs that referenced this issue Jan 23, 2018
skeptic causes cargo to monitor README.md.skt.md. This file does not
exist, nor is it created by any build script. Because of this cargo
will always rebuild even if nothing has changed:

$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
... stale: /home/.../ply-rs-0.1.1/README.md.skt.md -- missing
... fingerprint error for ply-rs v0.1.1: mtime based components have changed
Compiling ply-rs v0.1.1
...
Finished dev [unoptimized + debuginfo] target(s) in 6.90 secs
$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
... stale: /home/.../ply-rs-0.1.1/README.md.skt.md -- missing
... fingerprint error for ply-rs v0.1.1: mtime based components have changed
Compiling ply-rs v0.1.1
...
Finished dev [unoptimized + debuginfo] target(s) in 6.81 secs

Inspired by:
assert-rs/assert_cli@ccc8af5

More info:
budziq/rust-skeptic#25
rust-lang/cargo#4213
@TheButlah
Copy link
Contributor

TheButlah commented Feb 9, 2024

Is this truly intended behavior? If cargo knows which directory to watch for changes via println!("cargo:rerun-if-changed=path_to_nonexistent_file"), it should be able to do (pseudocode):

enum ChangeHistory {
  Exists(Mtime),
  NoFile
}

for (path, history) in tracked_changes {
  match history {
    Exists(mt) => rerun_build_if_mtime_changed(path, mt)
    NoFile => rerun_build_if_file_exists(path),
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants