Factor in `used_in_plugin` to target filenames
authorAlex Crichton <alex@alexcrichton.com>
Sat, 5 May 2018 19:59:50 +0000 (12:59 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 5 May 2018 19:59:50 +0000 (12:59 -0700)
This prevents thrashing the cache of compiled libraries for when they're used in
a plugin or not.

src/cargo/core/compiler/context/compilation_files.rs
src/cargo/core/compiler/context/mod.rs
tests/testsuite/freshness.rs

index 3eb32c60e2fce98569ce28b90a0db4f1c88a6fb0..e94a0aa4ffbddaee582704bb35a6b9408dc385d3 100644 (file)
@@ -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);
index 78c6d34fcce0e87aabac70f468772dc7f2842f11..af04750a858081dcd1163013ccaf5c1526388c9c 100644 (file)
@@ -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)?;
index 09f324d8ea7efed5a7c657301e074f77606034fd..88afde5617c258912083a5fc6501af562b714a5d 100644 (file)
@@ -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"),
+    );
+}