diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 083196828bd..a7c21ffee7a 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -65,7 +65,8 @@ pub fn prepare_target<'a, 'cfg>( debug!("fingerprint at: {}", loc.display()); let fingerprint = calculate(cx, unit)?; - let compare = compare_old_fingerprint(&loc, &*fingerprint); + let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use; + let compare = compare_old_fingerprint(&loc, &*fingerprint, mtime_on_use); log_compare(unit, &compare); // If our comparison failed (e.g. we're going to trigger a rebuild of this @@ -102,8 +103,10 @@ pub fn prepare_target<'a, 'cfg>( .filter(|output| output.flavor != FileFlavor::DebugInfo) .find(|output| { if output.path.exists() { - // update the mtime so other cleaners know we used it - let _ = filetime::set_file_times(&output.path, t, t); + if mtime_on_use { + // update the mtime so other cleaners know we used it + let _ = filetime::set_file_times(&output.path, t, t); + } false } else { true @@ -555,7 +558,8 @@ pub fn prepare_build_cmd<'a, 'cfg>( rustc: util::hash_u64(&cx.bcx.rustc.verbose_version), ..Fingerprint::new() }; - let compare = compare_old_fingerprint(&loc, &fingerprint); + let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use; + let compare = compare_old_fingerprint(&loc, &fingerprint, mtime_on_use); log_compare(unit, &compare); // When we write out the fingerprint, we may want to actually change the @@ -688,12 +692,18 @@ pub fn dep_info_loc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> Pa .join(&format!("dep-{}", filename(cx, unit))) } -fn compare_old_fingerprint(loc: &Path, new_fingerprint: &Fingerprint) -> CargoResult<()> { +fn compare_old_fingerprint( + loc: &Path, + new_fingerprint: &Fingerprint, + mtime_on_use: bool, +) -> CargoResult<()> { let old_fingerprint_short = paths::read(loc)?; - // update the mtime so other cleaners know we used it - let t = FileTime::from_system_time(SystemTime::now()); - filetime::set_file_times(loc, t, t)?; + if mtime_on_use { + // update the mtime so other cleaners know we used it + let t = FileTime::from_system_time(SystemTime::now()); + filetime::set_file_times(loc, t, t)?; + } let new_hash = new_fingerprint.hash(); diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index ccc6546dc88..6a90413391f 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -320,6 +320,7 @@ pub struct CliUnstable { pub package_features: bool, pub advanced_env: bool, pub config_profile: bool, + pub mtime_on_use: bool, } impl CliUnstable { @@ -356,6 +357,7 @@ impl CliUnstable { "package-features" => self.package_features = true, "advanced-env" => self.advanced_env = true, "config-profile" => self.config_profile = true, + "mtime-on-use" => self.mtime_on_use = true, _ => failure::bail!("unknown `-Z` flag specified: {}", k), } diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index dfa9e223824..9d14ca533c2 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1193,7 +1193,7 @@ fn simple_deps_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) { } #[test] -fn simple_deps_cleaner_dose_not_rebuild() { +fn simple_deps_cleaner_does_not_rebuild() { let p = project() .file( "Cargo.toml", @@ -1211,8 +1211,11 @@ fn simple_deps_cleaner_dose_not_rebuild() { .file("bar/src/lib.rs", "") .build(); - p.cargo("build").run(); - p.cargo("build") + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() + .run(); + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-C target-cpu=native") .with_stderr( "\ @@ -1228,19 +1231,22 @@ fn simple_deps_cleaner_dose_not_rebuild() { if is_coarse_mtime() { sleep_ms(1000); } - // This dose not make new files, but it dose update the mtime. - p.cargo("build") + // This does not make new files, but it does update the mtime. + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-C target-cpu=native") .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") .run(); simple_deps_cleaner(p.target_debug_dir(), timestamp); // This should not recompile! - p.cargo("build") + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-C target-cpu=native") .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") .run(); // But this should be cleaned and so need a rebuild - p.cargo("build") + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .with_stderr( "\ [COMPILING] bar v0.0.1 ([..]) @@ -1282,7 +1288,7 @@ fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) { } #[test] -fn fingerprint_cleaner_dose_not_rebuild() { +fn fingerprint_cleaner_does_not_rebuild() { let p = project() .file( "Cargo.toml", @@ -1300,8 +1306,11 @@ fn fingerprint_cleaner_dose_not_rebuild() { .file("bar/src/lib.rs", "") .build(); - p.cargo("build").run(); - p.cargo("build") + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() + .run(); + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-C target-cpu=native") .with_stderr( "\ @@ -1317,19 +1326,22 @@ fn fingerprint_cleaner_dose_not_rebuild() { if is_coarse_mtime() { sleep_ms(1000); } - // This dose not make new files, but it dose update the mtime. - p.cargo("build") + // This does not make new files, but it does update the mtime. + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-C target-cpu=native") .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") .run(); fingerprint_cleaner(p.target_debug_dir(), timestamp); // This should not recompile! - p.cargo("build") + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-C target-cpu=native") .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") .run(); // But this should be cleaned and so need a rebuild - p.cargo("build") + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() .with_stderr( "\ [COMPILING] bar v0.0.1 ([..])