From: Nipunn Koorapati Date: Tue, 5 Sep 2017 08:12:33 +0000 (-0700) Subject: Refactor to share code from dep_targets. Fixes the plat-specific case X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~6^2~58^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7336e3229e2cbb86ec1d5a3a0f47c78c32aab67b;p=cargo.git Refactor to share code from dep_targets. Fixes the plat-specific case --- diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 1f02d07a2..c11cbcfdf 100755 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -484,29 +484,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> { self.resolve.features_sorted(unit.pkg.package_id()).hash(&mut hasher); // Mix in the target-metadata of all the dependencies of this target - { - let id = unit.pkg.package_id(); - let deps = self.resolve.deps(id); - let mut deps = deps.filter_map(|id| { - match self.get_package(id) { - Ok(pkg) => { - pkg.targets().iter().find(|t| t.is_lib()).map(|t| { - let unit = Unit { - pkg: pkg, - target: t, - profile: self.lib_or_check_profile(unit, t), - kind: unit.kind.for_target(t), - }; - Some(self.target_metadata(&unit)) - }) - } - Err(_) => None - } - }).collect::>(); - + if let Ok(deps) = self.used_deps(unit) { debug!("Mixing in units {:?} to {:?}:{:?}", deps.len(), unit.target.name(), unit.target.kind()); - deps.sort(); - deps.hash(&mut hasher); + let mut deps_metadata = deps.into_iter().map(|dep_unit| { + self.target_metadata(&dep_unit) + }).collect::>(); + deps_metadata.sort(); + deps_metadata.hash(&mut hasher); } // Throw in the profile we're compiling with. This helps caching @@ -692,18 +676,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> { Ok(ret) } - /// For a package, return all targets which are registered as dependencies - /// for that package. - pub fn dep_targets(&self, unit: &Unit<'a>) -> CargoResult>> { - if unit.profile.run_custom_build { - return self.dep_run_custom_build(unit) - } else if unit.profile.doc && !unit.profile.test { - return self.doc_deps(unit); - } - + fn used_deps(&self, unit: &Unit<'a>) -> CargoResult>> { let id = unit.pkg.package_id(); let deps = self.resolve.deps(id); - let mut ret = deps.filter(|dep| { + deps.filter(|dep| { unit.pkg.dependencies().iter().filter(|d| { d.name() == dep.name() && d.version_req().matches(dep.version()) }).any(|d| { @@ -752,7 +728,20 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } Err(e) => Some(Err(e)) } - }).collect::>>()?; + }).collect::>>() + } + + /// For a package, return all targets which are registered as dependencies + /// for that package. + pub fn dep_targets(&self, unit: &Unit<'a>) -> CargoResult>> { + if unit.profile.run_custom_build { + return self.dep_run_custom_build(unit) + } else if unit.profile.doc && !unit.profile.test { + return self.doc_deps(unit); + } + + let id = unit.pkg.package_id(); + let mut ret = self.used_deps(unit)?; // If this target is a build script, then what we've collected so far is // all we need. If this isn't a build script, then it depends on the diff --git a/tests/workspaces.rs b/tests/workspaces.rs index 215af77ec..2e7660d16 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -1516,7 +1516,7 @@ fn dep_used_with_separate_features() { p.build(); // Build the entire workspace - assert_that(p.cargo("build"), + assert_that(p.cargo("build").arg("--all"), execs().with_status(0) .with_stderr("\ [..]Compiling feat_lib v0.1.0 ([..])