mirror of
https://github.com/rust-lang/cargo
synced 2024-09-13 04:51:31 +00:00
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
This commit is contained in:
parent
b948fc86c0
commit
e4a65b91be
|
@ -188,7 +188,11 @@ impl<'cfg> Compilation<'cfg> {
|
|||
unit: &Unit,
|
||||
script_meta: Option<Metadata>,
|
||||
) -> CargoResult<ProcessBuilder> {
|
||||
let rustdoc = ProcessBuilder::new(&*self.config.rustdoc()?);
|
||||
let mut rustdoc = ProcessBuilder::new(&*self.config.rustdoc()?);
|
||||
if self.config.extra_verbose() {
|
||||
rustdoc.display_env_vars();
|
||||
}
|
||||
|
||||
let cmd = fill_rustc_tool_env(rustdoc, unit);
|
||||
let mut p = self.fill_env(cmd, &unit.pkg, script_meta, unit.kind, true)?;
|
||||
unit.target.edition().cmd_edition_arg(&mut p);
|
||||
|
|
|
@ -191,7 +191,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
|
|||
/// Returns the directory where the artifacts for the given unit are
|
||||
/// initially created.
|
||||
pub fn out_dir(&self, unit: &Unit) -> PathBuf {
|
||||
if unit.mode.is_doc() {
|
||||
if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
|
||||
self.layout(unit.kind).doc().to_path_buf()
|
||||
} else if unit.mode.is_doc_test() {
|
||||
panic!("doc tests do not have an out dir");
|
||||
|
@ -418,9 +418,15 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
|
|||
vec![]
|
||||
}
|
||||
CompileMode::Docscrape => {
|
||||
// Docscrape only generates temporary *.examples files to pass to rustdoc
|
||||
// so they're not important to track
|
||||
vec![]
|
||||
let path = self
|
||||
.deps_dir(unit)
|
||||
.join(format!("{}.examples", unit.buildkey()));
|
||||
vec![OutputFile {
|
||||
path,
|
||||
hardlink: None,
|
||||
export_path: None,
|
||||
flavor: FileFlavor::Normal,
|
||||
}]
|
||||
}
|
||||
CompileMode::Test
|
||||
| CompileMode::Build
|
||||
|
|
|
@ -652,12 +652,13 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
|
|||
rustdoc.arg("-C").arg(format!("metadata={}", metadata));
|
||||
|
||||
let scrape_output_path = |unit: &Unit| -> CargoResult<PathBuf> {
|
||||
let layout = cx.files().layout(unit.kind);
|
||||
let output_dir = layout.prepare_tmp()?;
|
||||
let output_dir = cx.files().deps_dir(unit);
|
||||
Ok(output_dir.join(format!("{}.examples", unit.buildkey())))
|
||||
};
|
||||
|
||||
if unit.mode.is_doc_scrape() {
|
||||
debug_assert!(cx.bcx.scrape_units.contains(unit));
|
||||
|
||||
rustdoc.arg("-Zunstable-options");
|
||||
|
||||
rustdoc
|
||||
|
|
|
@ -256,6 +256,7 @@ fn compute_deps(
|
|||
if !dep.is_transitive()
|
||||
&& !unit.target.is_test()
|
||||
&& !unit.target.is_example()
|
||||
&& !unit.mode.is_doc_scrape()
|
||||
&& !unit.mode.is_any_test()
|
||||
{
|
||||
return false;
|
||||
|
@ -473,7 +474,8 @@ fn compute_deps_doc(
|
|||
|
||||
// Add all units being scraped for examples as a dependency of Doc units.
|
||||
for scrape_unit in state.scrape_units.iter() {
|
||||
let unit_for = UnitFor::new_normal();
|
||||
// This needs to match the FeaturesFor used in cargo_compile::generate_targets.
|
||||
let unit_for = UnitFor::new_host(scrape_unit.target.proc_macro());
|
||||
deps_of(scrape_unit, state, unit_for)?;
|
||||
ret.push(new_unit_dep(
|
||||
state,
|
||||
|
|
|
@ -368,18 +368,27 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
|
||||
let target_data = RustcTargetData::new(ws, &build_config.requested_kinds)?;
|
||||
|
||||
let specs = spec.to_package_id_specs(ws)?;
|
||||
let has_dev_units = if filter.need_dev_deps(build_config.mode) {
|
||||
HasDevUnits::Yes
|
||||
let all_packages = &Packages::All;
|
||||
let full_specs = if rustdoc_scrape_examples.is_some() {
|
||||
all_packages
|
||||
} else {
|
||||
HasDevUnits::No
|
||||
spec
|
||||
};
|
||||
|
||||
let specs = spec.to_package_id_specs(ws)?;
|
||||
let resolve_specs = full_specs.to_package_id_specs(ws)?;
|
||||
let has_dev_units =
|
||||
if filter.need_dev_deps(build_config.mode) || rustdoc_scrape_examples.is_some() {
|
||||
HasDevUnits::Yes
|
||||
} else {
|
||||
HasDevUnits::No
|
||||
};
|
||||
let resolve = ops::resolve_ws_with_opts(
|
||||
ws,
|
||||
&target_data,
|
||||
&build_config.requested_kinds,
|
||||
cli_features,
|
||||
&specs,
|
||||
&resolve_specs,
|
||||
has_dev_units,
|
||||
crate::core::resolver::features::ForceAllTargets::No,
|
||||
)?;
|
||||
|
@ -494,8 +503,7 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
|
||||
let mut scrape_units = match rustdoc_scrape_examples {
|
||||
Some(scrape_filter) => {
|
||||
let specs = Packages::All.to_package_id_specs(ws)?;
|
||||
let to_build_ids = resolve.specs_to_ids(&specs)?;
|
||||
let to_build_ids = resolve.specs_to_ids(&resolve_specs)?;
|
||||
let to_builds = pkg_set.get_many(to_build_ids)?;
|
||||
let mode = CompileMode::Docscrape;
|
||||
|
||||
|
|
|
@ -2184,6 +2184,9 @@ fn scrape_examples_basic() {
|
|||
let doc_html = p.read_file("target/doc/foo/fn.foo.html");
|
||||
assert!(doc_html.contains("Examples found in repository"));
|
||||
assert!(doc_html.contains("More examples"));
|
||||
|
||||
// Ensure that the reverse-dependency has its sources generated
|
||||
assert!(p.build_dir().join("doc/src/ex/ex.rs.html").exists());
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
|
|
Loading…
Reference in a new issue