Skip to content

Commit 6e52fb1

Browse files
Rollup merge of rust-lang#148268 - notriddle:emit-scraped-examples, r=GuillaumeGomez
rustdoc: fix `--emit=dep-info` on scraped examples Makes sure both stages (the scraping process itself, and the doc build) emit complete dependency lists. CC rust-lang#146220 Part of rust-lang#83784
2 parents 67cfef0 + 8611f0b commit 6e52fb1

File tree

12 files changed

+43
-9
lines changed

12 files changed

+43
-9
lines changed

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
896896
// Register the loaded external files in the source map so they show up in depinfo.
897897
// We can't load them via the source map because it gets created after we process the options.
898898
for external_path in &loaded_paths {
899-
let _ = sess.source_map().load_file(external_path);
899+
let _ = sess.source_map().load_binary_file(external_path);
900900
}
901901

902902
if sess.opts.describe_lints {

src/librustdoc/scrape_examples.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub(crate) fn run(
273273
bin_crate: bool,
274274
) {
275275
let inner = move || -> Result<(), String> {
276+
let emit_dep_info = renderopts.dep_info().is_some();
276277
// Generates source files for examples
277278
renderopts.no_emit_shared = true;
278279
let (cx, _) = Context::init(krate, renderopts, cache, tcx, Default::default())
@@ -320,6 +321,10 @@ pub(crate) fn run(
320321
calls.encode(&mut encoder);
321322
encoder.finish().map_err(|(_path, e)| e.to_string())?;
322323

324+
if emit_dep_info {
325+
rustc_interface::passes::write_dep_info(tcx);
326+
}
327+
323328
Ok(())
324329
};
325330

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {}
2+
3+
#[test]
4+
fn a_test() {
5+
foobar::ok();
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ needs-target-std
2+
use run_make_support::{assert_contains, rfs};
3+
4+
#[path = "../rustdoc-scrape-examples-remap/scrape.rs"]
5+
mod scrape;
6+
7+
fn main() {
8+
scrape::scrape(
9+
&["--scrape-tests", "--emit=dep-info"],
10+
&["--emit=dep-info,invocation-specific"],
11+
);
12+
13+
let content = rfs::read_to_string("foobar.d");
14+
assert_contains(&content, "lib.rs:");
15+
assert_contains(&content, "rustdoc/ex.calls:");
16+
17+
let content = rfs::read_to_string("ex.d");
18+
assert_contains(&content, "examples/ex.rs:");
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' ''
2+
3+
pub fn ok() {}

tests/run-make/rustdoc-scrape-examples-invalid-expr/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
mod scrape;
44

55
fn main() {
6-
scrape::scrape(&[]);
6+
scrape::scrape(&[], &[]);
77
}

tests/run-make/rustdoc-scrape-examples-multiple/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
mod scrape;
44

55
fn main() {
6-
scrape::scrape(&[]);
6+
scrape::scrape(&[], &[]);
77
}

tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
mod scrape;
44

55
fn main() {
6-
scrape::scrape(&[]);
6+
scrape::scrape(&[], &[]);
77
}

tests/run-make/rustdoc-scrape-examples-remap/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
mod scrape;
33

44
fn main() {
5-
scrape::scrape(&[]);
5+
scrape::scrape(&[], &[]);
66
}

tests/run-make/rustdoc-scrape-examples-remap/scrape.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::Path;
22

33
use run_make_support::{htmldocck, rfs, rustc, rustdoc};
44

5-
pub fn scrape(extra_args: &[&str]) {
5+
pub fn scrape(extra_args_scrape: &[&str], extra_args_doc: &[&str]) {
66
let out_dir = Path::new("rustdoc");
77
let crate_name = "foobar";
88
let deps = rfs::read_dir("examples")
@@ -27,7 +27,7 @@ pub fn scrape(extra_args: &[&str]) {
2727
.arg(&out_example)
2828
.arg("--scrape-examples-target-crate")
2929
.arg(crate_name)
30-
.args(extra_args)
30+
.args(extra_args_scrape)
3131
.run();
3232
out_deps.push(out_example);
3333
}
@@ -42,6 +42,7 @@ pub fn scrape(extra_args: &[&str]) {
4242
for dep in out_deps {
4343
rustdoc.arg("--with-examples").arg(dep);
4444
}
45+
rustdoc.args(extra_args_doc);
4546
rustdoc.run();
4647

4748
htmldocck().arg(out_dir).arg("src/lib.rs").run();

0 commit comments

Comments
 (0)