Skip to content

Commit 19c8f05

Browse files
committed
Fix issues compiling build scripts
1 parent 223adac commit 19c8f05

File tree

4 files changed

+54
-64
lines changed

4 files changed

+54
-64
lines changed

src/bin/cargo/commands/doc.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,21 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5656
args.compile_options(config, mode, Some(&ws), ProfileChecking::Custom)?;
5757
compile_opts.rustdoc_document_private_items = args.is_present("document-private-items");
5858
compile_opts.rustdoc_scrape_examples = match args.value_of("scrape-examples") {
59-
Some(s) => {
60-
let (examples, lib) = match s {
61-
"all" => (true, true),
62-
"examples" => (true, false),
63-
"lib" => (false, true),
64-
_ => {
65-
return Err(CliError::from(anyhow!(
66-
r#"--scrape-examples must take "all", "examples", or "lib" as an argument"#
67-
)));
68-
}
69-
};
70-
Some(CompileFilter::Only {
71-
all_targets: false,
72-
lib: if lib { LibRule::True } else { LibRule::False },
73-
bins: FilterRule::none(),
74-
examples: if examples {
75-
FilterRule::All
76-
} else {
77-
FilterRule::none()
78-
},
79-
benches: FilterRule::none(),
80-
tests: FilterRule::none(),
81-
})
82-
}
59+
Some(s) => Some(match s {
60+
"all" => CompileFilter::new_all_targets(),
61+
"examples" => CompileFilter::new(
62+
LibRule::False,
63+
FilterRule::none(),
64+
FilterRule::none(),
65+
FilterRule::All,
66+
FilterRule::none(),
67+
),
68+
_ => {
69+
return Err(CliError::from(anyhow!(
70+
r#"--scrape-examples must take "all", "examples", or "lib" as an argument"#
71+
)));
72+
}
73+
}),
8374
None => None,
8475
};
8576

src/cargo/core/compiler/mod.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod unit;
2121
pub mod unit_dependencies;
2222
pub mod unit_graph;
2323

24+
use std::collections::HashSet;
2425
use std::env;
2526
use std::ffi::{OsStr, OsString};
2627
use std::fs::{self, File};
@@ -660,33 +661,37 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
660661
.arg("--scrape-examples-output-path")
661662
.arg(scrape_output_path(unit)?);
662663

663-
for root in &cx.bcx.roots {
664-
rustdoc
665-
.arg("--scrape-examples-target-crate")
666-
.arg(root.pkg.name());
664+
let root_packages = cx
665+
.bcx
666+
.roots
667+
.iter()
668+
.map(|root| root.pkg.name())
669+
.collect::<HashSet<_>>();
670+
for pkg in root_packages {
671+
rustdoc.arg("--scrape-examples-target-crate").arg(pkg);
667672
}
668673
} else if cx.bcx.scrape_units.len() > 0 && cx.bcx.roots.contains(unit) {
669-
rustdoc.arg("-Zunstable-options");
670-
671-
for scrape_unit in &cx.bcx.scrape_units {
672-
rustdoc
673-
.arg("--with-examples")
674-
.arg(scrape_output_path(scrape_unit)?);
675-
}
676-
677-
let mut all_units = cx
674+
let all_units = cx
678675
.bcx
679676
.unit_graph
680677
.values()
681678
.map(|deps| deps.iter().map(|dep| &dep.unit))
682679
.flatten();
683-
let check_unit = all_units
684-
.find(|other| {
685-
unit.pkg == other.pkg && unit.target == other.target && other.mode.is_check()
686-
})
687-
.with_context(|| format!("Could not find check unit for {:?}", unit))?;
688-
let metadata = cx.files().metadata(check_unit);
689-
rustdoc.arg("-C").arg(format!("metadata={}", metadata));
680+
let check_unit = all_units.into_iter().find(|other| {
681+
unit.pkg == other.pkg && unit.target == other.target && other.mode.is_check()
682+
});
683+
if let Some(check_unit) = check_unit {
684+
let metadata = cx.files().metadata(check_unit);
685+
rustdoc.arg("-C").arg(format!("metadata={}", metadata));
686+
687+
rustdoc.arg("-Zunstable-options");
688+
689+
for scrape_unit in &cx.bcx.scrape_units {
690+
rustdoc
691+
.arg("--with-examples")
692+
.arg(scrape_output_path(scrape_unit)?);
693+
}
694+
}
690695
}
691696

692697
build_deps_args(&mut rustdoc, cx, unit)?;

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub fn build_unit_dependencies<'a, 'cfg>(
100100
let std_unit_deps = calc_deps_of_std(&mut state, std_roots)?;
101101

102102
deps_of_roots(roots, &mut state)?;
103-
deps_of_roots(scrape_roots, &mut state)?;
104103
super::links::validate_links(state.resolve(), &state.unit_dependencies)?;
105104
// Hopefully there aren't any links conflicts with the standard library?
106105

@@ -425,15 +424,7 @@ fn compute_deps_doc(
425424
) -> CargoResult<Vec<UnitDep>> {
426425
// FIXME(wcrichto): target.is_lib() is probably not the correct way to check
427426
// if the unit needs dev-dependencies
428-
let deps = state.deps(
429-
unit,
430-
unit_for,
431-
&|dep| match (unit.target.is_lib(), dep.kind()) {
432-
(_, DepKind::Normal) => true,
433-
(false, DepKind::Development) => true,
434-
_ => false,
435-
},
436-
);
427+
let deps = state.deps(unit, unit_for, &|dep| dep.kind() == DepKind::Normal);
437428

438429
// To document a library, we depend on dependencies actually being
439430
// built. If we're documenting *all* libraries, then we also depend on
@@ -483,13 +474,17 @@ fn compute_deps_doc(
483474
}
484475

485476
for scrape_unit in state.scrape_roots.iter() {
486-
ret.push(UnitDep {
487-
unit: scrape_unit.clone(),
488-
unit_for: unit_for.with_dependency(scrape_unit, &scrape_unit.target),
489-
extern_crate_name: InternedString::new(""),
490-
public: false,
491-
noprelude: false,
492-
});
477+
let unit_for = UnitFor::new_normal();
478+
deps_of(scrape_unit, state, unit_for)?;
479+
ret.push(new_unit_dep(
480+
state,
481+
scrape_unit,
482+
&scrape_unit.pkg,
483+
&scrape_unit.target,
484+
unit_for,
485+
scrape_unit.kind,
486+
scrape_unit.mode,
487+
)?);
493488
}
494489

495490
Ok(ret)
@@ -720,6 +715,7 @@ fn connect_run_custom_build_deps(state: &mut State<'_, '_>) {
720715
&& other.unit.target.is_linkable()
721716
&& other.unit.pkg.manifest().links().is_some()
722717
})
718+
.filter(|(_, other)| !other.unit.mode.is_doc_scrape())
723719
// Skip dependencies induced via dev-dependencies since
724720
// connections between `links` and build scripts only happens
725721
// via normal dependencies. Otherwise since dev-dependencies can

src/cargo/ops/cargo_compile.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,9 +1514,7 @@ fn rebuild_unit_graph_shared(
15141514
.collect();
15151515
let new_scrape_units = scrape_units
15161516
.iter()
1517-
.map(|unit| {
1518-
traverse_and_share(interner, &mut memo, &mut result, &unit_graph, unit, to_host)
1519-
})
1517+
.map(|unit| memo.get(unit).unwrap().clone())
15201518
.collect();
15211519
(new_roots, new_scrape_units, result)
15221520
}

0 commit comments

Comments
 (0)