|
18 | 18 | use crate::core::compiler::unit_graph::{UnitDep, UnitGraph};
|
19 | 19 | use crate::core::compiler::UnitInterner;
|
20 | 20 | use crate::core::compiler::{CompileKind, CompileMode, RustcTargetData, Unit};
|
21 |
| -use crate::core::dependency::DepKind; |
22 | 21 | use crate::core::profiles::{Profile, Profiles, UnitFor};
|
23 | 22 | use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
|
24 | 23 | use crate::core::resolver::Resolve;
|
@@ -243,29 +242,7 @@ fn compute_deps(
|
243 | 242 | }
|
244 | 243 |
|
245 | 244 | let id = unit.pkg.package_id();
|
246 |
| - let filtered_deps = state.deps(unit, unit_for, &|dep| { |
247 |
| - // If this target is a build command, then we only want build |
248 |
| - // dependencies, otherwise we want everything *other than* build |
249 |
| - // dependencies. |
250 |
| - if unit.target.is_custom_build() != dep.is_build() { |
251 |
| - return false; |
252 |
| - } |
253 |
| - |
254 |
| - // If this dependency is **not** a transitive dependency, then it |
255 |
| - // only applies to test/example targets. |
256 |
| - if !dep.is_transitive() |
257 |
| - && !unit.target.is_test() |
258 |
| - && !unit.target.is_example() |
259 |
| - && !unit.mode.is_doc_scrape() |
260 |
| - && !unit.mode.is_any_test() |
261 |
| - { |
262 |
| - return false; |
263 |
| - } |
264 |
| - |
265 |
| - // If we've gotten past all that, then this dependency is |
266 |
| - // actually used! |
267 |
| - true |
268 |
| - }); |
| 245 | + let filtered_deps = non_custom_build_and_non_transitive_deps(unit, state, unit_for); |
269 | 246 |
|
270 | 247 | let mut ret = Vec::new();
|
271 | 248 | let mut dev_deps = Vec::new();
|
@@ -372,6 +349,37 @@ fn compute_deps(
|
372 | 349 | Ok(ret)
|
373 | 350 | }
|
374 | 351 |
|
| 352 | +/// Returns non-custom and non-transitive dependencies. |
| 353 | +fn non_custom_build_and_non_transitive_deps<'a>( |
| 354 | + unit: &Unit, |
| 355 | + state: &'a State<'_, '_>, |
| 356 | + unit_for: UnitFor, |
| 357 | +) -> Vec<(PackageId, &'a HashSet<Dependency>)> { |
| 358 | + state.deps(unit, unit_for, &|dep| { |
| 359 | + // If this target is a build command, then we only want build |
| 360 | + // dependencies, otherwise we want everything *other than* build |
| 361 | + // dependencies. |
| 362 | + if unit.target.is_custom_build() != dep.is_build() { |
| 363 | + return false; |
| 364 | + } |
| 365 | + |
| 366 | + // If this dependency is **not** a transitive dependency, then it |
| 367 | + // only applies to test/example targets. |
| 368 | + if !dep.is_transitive() |
| 369 | + && !unit.target.is_test() |
| 370 | + && !unit.target.is_example() |
| 371 | + && !unit.mode.is_doc_scrape() |
| 372 | + && !unit.mode.is_any_test() |
| 373 | + { |
| 374 | + return false; |
| 375 | + } |
| 376 | + |
| 377 | + // If we've gotten past all that, then this dependency is |
| 378 | + // actually used! |
| 379 | + true |
| 380 | + }) |
| 381 | +} |
| 382 | + |
375 | 383 | /// Returns the dependencies needed to run a build script.
|
376 | 384 | ///
|
377 | 385 | /// The `unit` provided must represent an execution of a build script, and
|
@@ -423,7 +431,7 @@ fn compute_deps_doc(
|
423 | 431 | state: &mut State<'_, '_>,
|
424 | 432 | unit_for: UnitFor,
|
425 | 433 | ) -> CargoResult<Vec<UnitDep>> {
|
426 |
| - let deps = state.deps(unit, unit_for, &|dep| dep.kind() == DepKind::Normal); |
| 434 | + let deps = non_custom_build_and_non_transitive_deps(unit, state, unit_for); |
427 | 435 |
|
428 | 436 | // To document a library, we depend on dependencies actually being
|
429 | 437 | // built. If we're documenting *all* libraries, then we also depend on
|
|
0 commit comments