Skip to content

Commit e4a65b9

Browse files
committed
Fix several bugs when checking wasmtime repo:
* Docscrape unit not having dev-dependencies included * Sources for reverse-dependencies generated to the wrong directory * Incorrect features being selected for Docscrape units * Panics from Docscrape-dependent packages not being available
1 parent b948fc8 commit e4a65b9

File tree

6 files changed

+39
-15
lines changed

6 files changed

+39
-15
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ impl<'cfg> Compilation<'cfg> {
188188
unit: &Unit,
189189
script_meta: Option<Metadata>,
190190
) -> CargoResult<ProcessBuilder> {
191-
let rustdoc = ProcessBuilder::new(&*self.config.rustdoc()?);
191+
let mut rustdoc = ProcessBuilder::new(&*self.config.rustdoc()?);
192+
if self.config.extra_verbose() {
193+
rustdoc.display_env_vars();
194+
}
195+
192196
let cmd = fill_rustc_tool_env(rustdoc, unit);
193197
let mut p = self.fill_env(cmd, &unit.pkg, script_meta, unit.kind, true)?;
194198
unit.target.edition().cmd_edition_arg(&mut p);

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
191191
/// Returns the directory where the artifacts for the given unit are
192192
/// initially created.
193193
pub fn out_dir(&self, unit: &Unit) -> PathBuf {
194-
if unit.mode.is_doc() {
194+
if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
195195
self.layout(unit.kind).doc().to_path_buf()
196196
} else if unit.mode.is_doc_test() {
197197
panic!("doc tests do not have an out dir");
@@ -418,9 +418,15 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
418418
vec![]
419419
}
420420
CompileMode::Docscrape => {
421-
// Docscrape only generates temporary *.examples files to pass to rustdoc
422-
// so they're not important to track
423-
vec![]
421+
let path = self
422+
.deps_dir(unit)
423+
.join(format!("{}.examples", unit.buildkey()));
424+
vec![OutputFile {
425+
path,
426+
hardlink: None,
427+
export_path: None,
428+
flavor: FileFlavor::Normal,
429+
}]
424430
}
425431
CompileMode::Test
426432
| CompileMode::Build

src/cargo/core/compiler/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,13 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
652652
rustdoc.arg("-C").arg(format!("metadata={}", metadata));
653653

654654
let scrape_output_path = |unit: &Unit| -> CargoResult<PathBuf> {
655-
let layout = cx.files().layout(unit.kind);
656-
let output_dir = layout.prepare_tmp()?;
655+
let output_dir = cx.files().deps_dir(unit);
657656
Ok(output_dir.join(format!("{}.examples", unit.buildkey())))
658657
};
659658

660659
if unit.mode.is_doc_scrape() {
660+
debug_assert!(cx.bcx.scrape_units.contains(unit));
661+
661662
rustdoc.arg("-Zunstable-options");
662663

663664
rustdoc

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ fn compute_deps(
256256
if !dep.is_transitive()
257257
&& !unit.target.is_test()
258258
&& !unit.target.is_example()
259+
&& !unit.mode.is_doc_scrape()
259260
&& !unit.mode.is_any_test()
260261
{
261262
return false;
@@ -473,7 +474,8 @@ fn compute_deps_doc(
473474

474475
// Add all units being scraped for examples as a dependency of Doc units.
475476
for scrape_unit in state.scrape_units.iter() {
476-
let unit_for = UnitFor::new_normal();
477+
// This needs to match the FeaturesFor used in cargo_compile::generate_targets.
478+
let unit_for = UnitFor::new_host(scrape_unit.target.proc_macro());
477479
deps_of(scrape_unit, state, unit_for)?;
478480
ret.push(new_unit_dep(
479481
state,

src/cargo/ops/cargo_compile.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,27 @@ pub fn create_bcx<'a, 'cfg>(
368368

369369
let target_data = RustcTargetData::new(ws, &build_config.requested_kinds)?;
370370

371-
let specs = spec.to_package_id_specs(ws)?;
372-
let has_dev_units = if filter.need_dev_deps(build_config.mode) {
373-
HasDevUnits::Yes
371+
let all_packages = &Packages::All;
372+
let full_specs = if rustdoc_scrape_examples.is_some() {
373+
all_packages
374374
} else {
375-
HasDevUnits::No
375+
spec
376376
};
377+
378+
let specs = spec.to_package_id_specs(ws)?;
379+
let resolve_specs = full_specs.to_package_id_specs(ws)?;
380+
let has_dev_units =
381+
if filter.need_dev_deps(build_config.mode) || rustdoc_scrape_examples.is_some() {
382+
HasDevUnits::Yes
383+
} else {
384+
HasDevUnits::No
385+
};
377386
let resolve = ops::resolve_ws_with_opts(
378387
ws,
379388
&target_data,
380389
&build_config.requested_kinds,
381390
cli_features,
382-
&specs,
391+
&resolve_specs,
383392
has_dev_units,
384393
crate::core::resolver::features::ForceAllTargets::No,
385394
)?;
@@ -494,8 +503,7 @@ pub fn create_bcx<'a, 'cfg>(
494503

495504
let mut scrape_units = match rustdoc_scrape_examples {
496505
Some(scrape_filter) => {
497-
let specs = Packages::All.to_package_id_specs(ws)?;
498-
let to_build_ids = resolve.specs_to_ids(&specs)?;
506+
let to_build_ids = resolve.specs_to_ids(&resolve_specs)?;
499507
let to_builds = pkg_set.get_many(to_build_ids)?;
500508
let mode = CompileMode::Docscrape;
501509

tests/testsuite/doc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,9 @@ fn scrape_examples_basic() {
21842184
let doc_html = p.read_file("target/doc/foo/fn.foo.html");
21852185
assert!(doc_html.contains("Examples found in repository"));
21862186
assert!(doc_html.contains("More examples"));
2187+
2188+
// Ensure that the reverse-dependency has its sources generated
2189+
assert!(p.build_dir().join("doc/src/ex/ex.rs.html").exists());
21872190
}
21882191

21892192
#[cargo_test]

0 commit comments

Comments
 (0)