From 9df7370733adf60c2cd7068523f7421d6e74ab41 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 5 May 2018 12:59:50 -0700 Subject: [PATCH] Factor in `used_in_plugin` to target filenames This prevents thrashing the cache of compiled libraries for when they're used in a plugin or not. --- .../compiler/context/compilation_files.rs | 1 + src/cargo/core/compiler/context/mod.rs | 4 +- tests/testsuite/freshness.rs | 68 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 3eb32c60e2f..e94a0aa4ffb 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -427,6 +427,7 @@ fn compute_metadata<'a, 'cfg>( // panic=abort and panic=unwind artifacts, additionally with various // settings like debuginfo and whatnot. unit.profile.hash(&mut hasher); + cx.used_in_plugin.contains(unit).hash(&mut hasher); unit.mode.hash(&mut hasher); if let Some(ref args) = bcx.extra_args_for(unit) { args.hash(&mut hasher); diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index 78c6d34fcce..af04750a858 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -123,7 +123,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let mut queue = JobQueue::new(self.bcx); self.prepare_units(export_dir, units)?; self.prepare()?; - self.build_used_in_plugin_map(units)?; custom_build::build_map(&mut self, units)?; for unit in units.iter() { @@ -261,6 +260,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { }; build_unit_dependencies(units, self.bcx, &mut self.unit_dependencies)?; + self.build_used_in_plugin_map(units)?; let files = CompilationFiles::new( units, host_layout, @@ -302,7 +302,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { /// /// This will recursively walk `units` and all of their dependencies to /// determine which crate are going to be used in plugins or not. - pub fn build_used_in_plugin_map(&mut self, units: &[Unit<'a>]) -> CargoResult<()> { + fn build_used_in_plugin_map(&mut self, units: &[Unit<'a>]) -> CargoResult<()> { let mut visited = HashSet::new(); for unit in units { self.walk_used_in_plugin_map(unit, unit.target.for_host(), &mut visited)?; diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 09f324d8ea7..88afde5617c 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1164,3 +1164,71 @@ fn change_panic_mode() { assert_that(p.cargo("build -p foo"), execs().with_status(0)); assert_that(p.cargo("build -p bar"), execs().with_status(0)); } + +#[test] +fn dont_rebuild_based_on_plugins() { + let p = project("p") + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.1" + + [workspace] + members = ['bar'] + + [dependencies] + proc-macro-thing = { path = 'proc-macro-thing' } + "#, + ) + .file("src/lib.rs", "") + .file( + "proc-macro-thing/Cargo.toml", + r#" + [package] + name = "proc-macro-thing" + version = "0.1.1" + + [lib] + proc-macro = true + + [dependencies] + baz = { path = '../baz' } + "#, + ) + .file("proc-macro-thing/src/lib.rs", "") + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.1" + + [dependencies] + baz = { path = '../baz' } + "#, + ) + .file("bar/src/main.rs", "fn main() {}") + .file( + "baz/Cargo.toml", + r#" + [package] + name = "baz" + version = "0.1.1" + "#, + ) + .file("baz/src/lib.rs", "") + .build(); + + assert_that(p.cargo("build"), execs().with_status(0)); + assert_that(p.cargo("build -p bar"), execs().with_status(0)); + assert_that( + p.cargo("build"), + execs().with_status(0).with_stderr("[FINISHED] [..]\n"), + ); + assert_that( + p.cargo("build -p bar"), + execs().with_status(0).with_stderr("[FINISHED] [..]\n"), + ); +}