Skip to content

Commit 5f6ede2

Browse files
committed
Put mtime-on-use behind a feature flag.
1 parent 87dd6c2 commit 5f6ede2

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ pub fn prepare_target<'a, 'cfg>(
6565
debug!("fingerprint at: {}", loc.display());
6666

6767
let fingerprint = calculate(cx, unit)?;
68-
let compare = compare_old_fingerprint(&loc, &*fingerprint);
68+
let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use;
69+
let compare = compare_old_fingerprint(&loc, &*fingerprint, mtime_on_use);
6970
log_compare(unit, &compare);
7071

7172
// 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>(
102103
.filter(|output| output.flavor != FileFlavor::DebugInfo)
103104
.find(|output| {
104105
if output.path.exists() {
105-
// update the mtime so other cleaners know we used it
106-
let _ = filetime::set_file_times(&output.path, t, t);
106+
if mtime_on_use {
107+
// update the mtime so other cleaners know we used it
108+
let _ = filetime::set_file_times(&output.path, t, t);
109+
}
107110
false
108111
} else {
109112
true
@@ -555,7 +558,8 @@ pub fn prepare_build_cmd<'a, 'cfg>(
555558
rustc: util::hash_u64(&cx.bcx.rustc.verbose_version),
556559
..Fingerprint::new()
557560
};
558-
let compare = compare_old_fingerprint(&loc, &fingerprint);
561+
let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use;
562+
let compare = compare_old_fingerprint(&loc, &fingerprint, mtime_on_use);
559563
log_compare(unit, &compare);
560564

561565
// 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
688692
.join(&format!("dep-{}", filename(cx, unit)))
689693
}
690694

691-
fn compare_old_fingerprint(loc: &Path, new_fingerprint: &Fingerprint) -> CargoResult<()> {
695+
fn compare_old_fingerprint(
696+
loc: &Path,
697+
new_fingerprint: &Fingerprint,
698+
mtime_on_use: bool,
699+
) -> CargoResult<()> {
692700
let old_fingerprint_short = paths::read(loc)?;
693701

694-
// update the mtime so other cleaners know we used it
695-
let t = FileTime::from_system_time(SystemTime::now());
696-
filetime::set_file_times(loc, t, t)?;
702+
if mtime_on_use {
703+
// update the mtime so other cleaners know we used it
704+
let t = FileTime::from_system_time(SystemTime::now());
705+
filetime::set_file_times(loc, t, t)?;
706+
}
697707

698708
let new_hash = new_fingerprint.hash();
699709

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ pub struct CliUnstable {
320320
pub package_features: bool,
321321
pub advanced_env: bool,
322322
pub config_profile: bool,
323+
pub mtime_on_use: bool,
323324
}
324325

325326
impl CliUnstable {
@@ -356,6 +357,7 @@ impl CliUnstable {
356357
"package-features" => self.package_features = true,
357358
"advanced-env" => self.advanced_env = true,
358359
"config-profile" => self.config_profile = true,
360+
"mtime-on-use" => self.mtime_on_use = true,
359361
_ => failure::bail!("unknown `-Z` flag specified: {}", k),
360362
}
361363

tests/testsuite/freshness.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ fn simple_deps_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
12041204
}
12051205

12061206
#[test]
1207-
fn simple_deps_cleaner_dose_not_rebuild() {
1207+
fn simple_deps_cleaner_does_not_rebuild() {
12081208
let p = project()
12091209
.file(
12101210
"Cargo.toml",
@@ -1222,8 +1222,11 @@ fn simple_deps_cleaner_dose_not_rebuild() {
12221222
.file("bar/src/lib.rs", "")
12231223
.build();
12241224

1225-
p.cargo("build").run();
1226-
p.cargo("build")
1225+
p.cargo("build -Z mtime-on-use")
1226+
.masquerade_as_nightly_cargo()
1227+
.run();
1228+
p.cargo("build -Z mtime-on-use")
1229+
.masquerade_as_nightly_cargo()
12271230
.env("RUSTFLAGS", "-C target-cpu=native")
12281231
.with_stderr(
12291232
"\
@@ -1239,19 +1242,22 @@ fn simple_deps_cleaner_dose_not_rebuild() {
12391242
if is_coarse_mtime() {
12401243
sleep_ms(1000);
12411244
}
1242-
// This dose not make new files, but it dose update the mtime.
1243-
p.cargo("build")
1245+
// This does not make new files, but it does update the mtime.
1246+
p.cargo("build -Z mtime-on-use")
1247+
.masquerade_as_nightly_cargo()
12441248
.env("RUSTFLAGS", "-C target-cpu=native")
12451249
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
12461250
.run();
12471251
simple_deps_cleaner(p.target_debug_dir(), timestamp);
12481252
// This should not recompile!
1249-
p.cargo("build")
1253+
p.cargo("build -Z mtime-on-use")
1254+
.masquerade_as_nightly_cargo()
12501255
.env("RUSTFLAGS", "-C target-cpu=native")
12511256
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
12521257
.run();
12531258
// But this should be cleaned and so need a rebuild
1254-
p.cargo("build")
1259+
p.cargo("build -Z mtime-on-use")
1260+
.masquerade_as_nightly_cargo()
12551261
.with_stderr(
12561262
"\
12571263
[COMPILING] bar v0.0.1 ([..])
@@ -1293,7 +1299,7 @@ fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
12931299
}
12941300

12951301
#[test]
1296-
fn fingerprint_cleaner_dose_not_rebuild() {
1302+
fn fingerprint_cleaner_does_not_rebuild() {
12971303
let p = project()
12981304
.file(
12991305
"Cargo.toml",
@@ -1311,8 +1317,11 @@ fn fingerprint_cleaner_dose_not_rebuild() {
13111317
.file("bar/src/lib.rs", "")
13121318
.build();
13131319

1314-
p.cargo("build").run();
1315-
p.cargo("build")
1320+
p.cargo("build -Z mtime-on-use")
1321+
.masquerade_as_nightly_cargo()
1322+
.run();
1323+
p.cargo("build -Z mtime-on-use")
1324+
.masquerade_as_nightly_cargo()
13161325
.env("RUSTFLAGS", "-C target-cpu=native")
13171326
.with_stderr(
13181327
"\
@@ -1328,19 +1337,22 @@ fn fingerprint_cleaner_dose_not_rebuild() {
13281337
if is_coarse_mtime() {
13291338
sleep_ms(1000);
13301339
}
1331-
// This dose not make new files, but it dose update the mtime.
1332-
p.cargo("build")
1340+
// This does not make new files, but it does update the mtime.
1341+
p.cargo("build -Z mtime-on-use")
1342+
.masquerade_as_nightly_cargo()
13331343
.env("RUSTFLAGS", "-C target-cpu=native")
13341344
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
13351345
.run();
13361346
fingerprint_cleaner(p.target_debug_dir(), timestamp);
13371347
// This should not recompile!
1338-
p.cargo("build")
1348+
p.cargo("build -Z mtime-on-use")
1349+
.masquerade_as_nightly_cargo()
13391350
.env("RUSTFLAGS", "-C target-cpu=native")
13401351
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
13411352
.run();
13421353
// But this should be cleaned and so need a rebuild
1343-
p.cargo("build")
1354+
p.cargo("build -Z mtime-on-use")
1355+
.masquerade_as_nightly_cargo()
13441356
.with_stderr(
13451357
"\
13461358
[COMPILING] bar v0.0.1 ([..])

0 commit comments

Comments
 (0)