Skip to content

Commit 2a07c68

Browse files
committed
test: cargo-check stuck due to build script mtime too new
See rust-lang/cargo 16104 for what we're testing against
1 parent 8363559 commit 2a07c68

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

tests/testsuite/freshness.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,3 +3184,67 @@ fn use_mtime_cache_in_cargo_home() {
31843184
"#]])
31853185
.run();
31863186
}
3187+
3188+
#[cargo_test]
3189+
fn incremental_build_script_execution_got_new_mtime_and_cargo_check() {
3190+
// See https://github.com/rust-lang/cargo/issues/16104
3191+
let p = project()
3192+
.file("src/lib.rs", "")
3193+
.file("touch-me", "")
3194+
.file(
3195+
"build.rs",
3196+
r#"fn main() { println!("cargo::rerun-if-changed=touch-me") }"#,
3197+
)
3198+
.build();
3199+
3200+
p.cargo("check")
3201+
.env("CARGO_INCREMENTAL", "1")
3202+
.with_stderr_data(str![[r#"
3203+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
3204+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3205+
3206+
"#]])
3207+
.run();
3208+
3209+
if is_coarse_mtime() {
3210+
sleep_ms(1000);
3211+
}
3212+
3213+
p.change_file("touch-me", "oops");
3214+
3215+
// The first one is expected to rerun build script
3216+
p.cargo("check -v")
3217+
.env("CARGO_INCREMENTAL", "1")
3218+
.with_stderr_data(str![[r#"
3219+
[DIRTY] foo v0.0.1 ([ROOT]/foo): the file `touch-me` has changed ([TIME_DIFF_AFTER_LAST_BUILD])
3220+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
3221+
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
3222+
[RUNNING] `rustc --crate-name foo [..]`
3223+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3224+
3225+
"#]])
3226+
.run();
3227+
3228+
// subsequent cargo check gets stuck...
3229+
p.cargo("check -v")
3230+
.env("CARGO_INCREMENTAL", "1")
3231+
.with_stderr_data(str![[r#"
3232+
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3233+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3234+
[RUNNING] `rustc --crate-name foo [..]`
3235+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3236+
3237+
"#]])
3238+
.run();
3239+
3240+
p.cargo("check -v")
3241+
.env("CARGO_INCREMENTAL", "1")
3242+
.with_stderr_data(str![[r#"
3243+
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3244+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3245+
[RUNNING] `rustc --crate-name foo [..]`
3246+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3247+
3248+
"#]])
3249+
.run();
3250+
}

tests/testsuite/freshness_checksum.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,3 +2963,67 @@ fn use_checksum_cache_in_cargo_home() {
29632963
"#]])
29642964
.run();
29652965
}
2966+
2967+
#[cargo_test(nightly, reason = "requires -Zchecksum-hash-algorithm")]
2968+
fn incremental_build_script_execution_got_new_mtime_and_cargo_check() {
2969+
// See https://github.com/rust-lang/cargo/issues/16104
2970+
let p = project()
2971+
.file("src/lib.rs", "")
2972+
.file("touch-me", "")
2973+
.file(
2974+
"build.rs",
2975+
r#"fn main() { println!("cargo::rerun-if-changed=touch-me") }"#,
2976+
)
2977+
.build();
2978+
2979+
p.cargo("check -Zchecksum-freshness")
2980+
.masquerade_as_nightly_cargo(&["checksum-freshness"])
2981+
.env("CARGO_INCREMENTAL", "1")
2982+
.with_stderr_data(str![[r#"
2983+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
2984+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2985+
2986+
"#]])
2987+
.run();
2988+
2989+
p.change_file("touch-me", "oops");
2990+
2991+
// The first one is expected to rerun build script
2992+
p.cargo("check -Zchecksum-freshness -v")
2993+
.masquerade_as_nightly_cargo(&["checksum-freshness"])
2994+
.env("CARGO_INCREMENTAL", "1")
2995+
.with_stderr_data(str![[r#"
2996+
[DIRTY] foo v0.0.1 ([ROOT]/foo): the file `touch-me` has changed ([TIME_DIFF_AFTER_LAST_BUILD])
2997+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
2998+
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
2999+
[RUNNING] `rustc --crate-name foo [..]`
3000+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3001+
3002+
"#]])
3003+
.run();
3004+
3005+
// subsequent cargo check gets stuck...
3006+
p.cargo("check -Zchecksum-freshness -v")
3007+
.masquerade_as_nightly_cargo(&["checksum-freshness"])
3008+
.env("CARGO_INCREMENTAL", "1")
3009+
.with_stderr_data(str![[r#"
3010+
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3011+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3012+
[RUNNING] `rustc --crate-name foo [..]`
3013+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3014+
3015+
"#]])
3016+
.run();
3017+
3018+
p.cargo("check -Zchecksum-freshness -v")
3019+
.masquerade_as_nightly_cargo(&["checksum-freshness"])
3020+
.env("CARGO_INCREMENTAL", "1")
3021+
.with_stderr_data(str![[r#"
3022+
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3023+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3024+
[RUNNING] `rustc --crate-name foo [..]`
3025+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3026+
3027+
"#]])
3028+
.run();
3029+
}

0 commit comments

Comments
 (0)