From 9aa7a4dce5f47e49c4100ff18a9dc0dc5a47efc4 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Thu, 20 Jun 2019 23:14:28 -0300 Subject: [PATCH 1/4] test(freshness): check that updating dependency mtime does not rebuild --- tests/testsuite/freshness.rs | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 6d3de5d30f6..0a519b87657 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1257,6 +1257,49 @@ fn simple_deps_cleaner_does_not_rebuild() { .run(); } +#[cargo_test] +fn update_dependency_mtime_does_not_rebuild() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = { path = "bar" } + "#, + ) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) + .file("bar/src/lib.rs", "") + .build(); + + p.cargo("build -Z mtime-on-use") + .masquerade_as_nightly_cargo() + .env("RUSTFLAGS", "-C target-cpu=native") + .with_stderr( + "\ +[COMPILING] bar v0.0.1 ([..]) +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", + ) + .run(); + // This does not make new files, but it does update the mtime of the dependency. + p.cargo("build -p bar -Z mtime-on-use") + .masquerade_as_nightly_cargo() + .env("RUSTFLAGS", "-C target-cpu=native") + .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") + .run(); + // This should not recompile! + 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(); +} + fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) { // Cargo is experimenting with letting outside projects develop some // limited forms of GC for target_dir. This is one of the forms. From 78927e6b15396ce0d1bb4837437bd0c3d004c7c5 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Mon, 17 Jun 2019 15:42:52 -0300 Subject: [PATCH 2/4] fix(fingerpring): do not touch intermediate artifacts --- src/cargo/core/compiler/fingerprint.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 4f1ad49c016..9f159d69c86 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -760,7 +760,6 @@ impl Fingerprint { &mut self, pkg_root: &Path, target_root: &Path, - mtime_on_use: bool, ) -> CargoResult<()> { assert!(!self.fs_status.up_to_date()); @@ -781,10 +780,6 @@ impl Fingerprint { return Ok(()); } }; - if mtime_on_use { - let t = FileTime::from_system_time(SystemTime::now()); - filetime::set_file_times(output, t, t)?; - } assert!(mtimes.insert(output.clone(), mtime).is_none()); } @@ -1024,8 +1019,7 @@ fn calculate<'a, 'cfg>( // After we built the initial `Fingerprint` be sure to update the // `fs_status` field of it. let target_root = target_root(cx, unit); - let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use; - fingerprint.check_filesystem(unit.pkg.root(), &target_root, mtime_on_use)?; + fingerprint.check_filesystem(unit.pkg.root(), &target_root)?; let fingerprint = Arc::new(fingerprint); cx.fingerprints.insert(*unit, Arc::clone(&fingerprint)); From 8343fb7396891251cedcb290909a99261719ac23 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Fri, 21 Jun 2019 00:15:59 -0300 Subject: [PATCH 3/4] test(freshness): remove `simple_deps_cleaner_does_not_rebuild` Now that the `mtime` of intermediate artifacts is not updated there's no need for this test anymore (it now fails because without the `mtime`s it cannot perform the intended GC operation). --- tests/testsuite/freshness.rs | 87 ------------------------------------ 1 file changed, 87 deletions(-) diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 0a519b87657..e87cc895e30 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1170,93 +1170,6 @@ fn changing_rustflags_is_cached() { .run(); } -fn simple_deps_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) { - // Cargo is experimenting with letting outside projects develop some - // limited forms of GC for target_dir. This is one of the forms. - // Specifically, Cargo is updating the mtime of files in - // target/profile/deps each time it uses the file. - // So a cleaner can remove files older then a time stamp without - // effecting any builds that happened since that time stamp. - let mut cleand = false; - dir.push("deps"); - for dep in fs::read_dir(&dir).unwrap() { - let dep = dep.unwrap(); - if filetime::FileTime::from_last_modification_time(&dep.metadata().unwrap()) <= timestamp { - fs::remove_file(dep.path()).unwrap(); - println!("remove: {:?}", dep.path()); - cleand = true; - } - } - assert!( - cleand, - "called simple_deps_cleaner, but there was nothing to remove" - ); -} - -#[cargo_test] -fn simple_deps_cleaner_does_not_rebuild() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - - [dependencies] - bar = { path = "bar" } - "#, - ) - .file("src/lib.rs", "") - .file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1")) - .file("bar/src/lib.rs", "") - .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( - "\ -[COMPILING] bar v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", - ) - .run(); - if is_coarse_mtime() { - sleep_ms(1000); - } - let timestamp = filetime::FileTime::from_system_time(SystemTime::now()); - if is_coarse_mtime() { - sleep_ms(1000); - } - // 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 -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 -Z mtime-on-use") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] bar v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", - ) - .run(); -} - #[cargo_test] fn update_dependency_mtime_does_not_rebuild() { let p = project() From 009876a88af659c10b022ec4c4956f77b983d531 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Fri, 21 Jun 2019 00:40:30 -0300 Subject: [PATCH 4/4] fix(fingerprint): rustfmt --- src/cargo/core/compiler/fingerprint.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 9f159d69c86..3738bcdd9ca 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -756,11 +756,7 @@ impl Fingerprint { /// dependencies up to this unit as well. This function assumes that the /// unit starts out as `FsStatus::Stale` and then it will optionally switch /// it to `UpToDate` if it can. - fn check_filesystem( - &mut self, - pkg_root: &Path, - target_root: &Path, - ) -> CargoResult<()> { + fn check_filesystem(&mut self, pkg_root: &Path, target_root: &Path) -> CargoResult<()> { assert!(!self.fs_status.up_to_date()); let mut mtimes = HashMap::new();