From d8e43e812850664ff03059c973098dd76f0ce315 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 24 Sep 2018 09:24:20 -0700 Subject: [PATCH] Fix `--build-plan` with dev-dependencies Regressed in #6005 it looks like the build plan requires all packages to be downloaded rather than just those coming out of `unit_dependenices`, so let's make sure to download everything! Closes #6082 --- src/cargo/core/compiler/context/mod.rs | 12 ++++++++---- tests/testsuite/build_plan.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index eb31fcfa6d2..a5b6231e86a 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -167,7 +167,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { queue.execute(&mut self, &mut plan)?; if build_plan { - plan.set_inputs(self.inputs()?); + plan.set_inputs(self.build_plan_inputs()?); plan.output_plan(); } @@ -512,10 +512,14 @@ impl<'a, 'cfg> Context<'a, 'cfg> { /// Return the list of filenames read by cargo to generate the BuildContext /// (all Cargo.toml, etc). - pub fn inputs(&self) -> CargoResult> { + pub fn build_plan_inputs(&self) -> CargoResult> { let mut inputs = Vec::new(); - for id in self.bcx.packages.package_ids() { - let pkg = self.get_package(id)?; + // Note that we're using the `package_cache`, which should have been + // populated by `build_unit_dependencies`, and only those packages are + // considered as all the inputs. + // + // (notably we skip dev-deps here if they aren't present) + for pkg in self.package_cache.values() { inputs.push(pkg.manifest_path().to_path_buf()); } inputs.sort(); diff --git a/tests/testsuite/build_plan.rs b/tests/testsuite/build_plan.rs index 40a13c4d25b..fa17a79067d 100644 --- a/tests/testsuite/build_plan.rs +++ b/tests/testsuite/build_plan.rs @@ -1,3 +1,4 @@ +use support::registry::Package; use support::{basic_bin_manifest, basic_manifest, main_file, project}; #[test] @@ -180,3 +181,28 @@ fn cargo_build_plan_build_script() { "#, ).run(); } + +#[test] +fn build_plan_with_dev_dep() { + Package::new("bar", "0.1.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dev-dependencies] + bar = "*" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build --build-plan -Zunstable-options") + .masquerade_as_nightly_cargo() + .run(); +}