Skip to content

Commit

Permalink
Auto merge of #5490 - alexcrichton:fix-thrash, r=matklad
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 5, 2018
2 parents 2912a58 + 9df7370 commit 757112c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
68 changes: 68 additions & 0 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
);
}

0 comments on commit 757112c

Please sign in to comment.