Skip to content

Commit df8c037

Browse files
Migrate rustdoc-scrape-examples-ordering to rmake
1 parent 0712ae8 commit df8c037

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

src/tools/run-make-support/src/rustc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use std::ffi::OsString;
2+
use std::ffi::{OsStr, OsString};
33
use std::io::Write;
44
use std::path::Path;
55
use std::process::{Command, Output, Stdio};
@@ -177,9 +177,9 @@ impl Rustc {
177177
}
178178

179179
/// Specify the crate name.
180-
pub fn crate_name(&mut self, name: &str) -> &mut Self {
180+
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
181181
self.cmd.arg("--crate-name");
182-
self.cmd.arg(name);
182+
self.cmd.arg(name.as_ref());
183183
self
184184
}
185185

src/tools/run-make-support/src/rustdoc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::ffi::OsStr;
23
use std::io::Write;
34
use std::path::Path;
45
use std::process::{Command, Output, Stdio};
@@ -130,9 +131,9 @@ impl Rustdoc {
130131
}
131132

132133
/// Specify the crate name.
133-
pub fn crate_name(&mut self, name: &str) -> &mut Self {
134+
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
134135
self.cmd.arg("--crate-name");
135-
self.cmd.arg(name);
136+
self.cmd.arg(name.as_ref());
136137
self
137138
}
138139

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ run-make/rustdoc-io-error/Makefile
248248
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
249249
run-make/rustdoc-scrape-examples-macros/Makefile
250250
run-make/rustdoc-scrape-examples-multiple/Makefile
251-
run-make/rustdoc-scrape-examples-ordering/Makefile
252251
run-make/rustdoc-scrape-examples-remap/Makefile
253252
run-make/rustdoc-scrape-examples-test/Makefile
254253
run-make/rustdoc-scrape-examples-whitespace/Makefile

tests/run-make/rustdoc-scrape-examples-ordering/Makefile

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use run_make_support::{python_command, rustc, rustdoc, source_path, tmp_dir};
2+
use std::fs::read_dir;
3+
use std::path::Path;
4+
5+
fn main() {
6+
let lib_dir = tmp_dir();
7+
let out_dir = tmp_dir().join("rustdoc");
8+
eprintln!("--> {out_dir:?}",);
9+
let crate_name = "foobar";
10+
let deps = read_dir("examples")
11+
.unwrap()
12+
.filter_map(|entry| entry.ok().map(|e| e.path()))
13+
.filter(|path| path.is_file() && path.extension().is_some_and(|ext| ext == "rs"))
14+
.collect::<Vec<_>>();
15+
16+
rustc().input("src/lib.rs").crate_name(crate_name).crate_type("lib").emit("metadata").run();
17+
18+
let mut out_deps = Vec::with_capacity(deps.len());
19+
for dep in deps {
20+
let dep_stem = dep.file_stem().unwrap();
21+
let out_example = out_dir.join(format!("{}.calls", dep_stem.to_str().unwrap()));
22+
rustdoc()
23+
.input(&dep)
24+
.crate_name(&dep_stem)
25+
.crate_type("bin")
26+
.output(&out_dir)
27+
.extern_(crate_name, lib_dir.join(format!("lib{crate_name}.rmeta")))
28+
.arg("-Zunstable-options")
29+
.arg("--scrape-examples-output-path")
30+
.arg(&out_example)
31+
.arg("--scrape-examples-target-crate")
32+
.arg(crate_name)
33+
.run();
34+
out_deps.push(out_example);
35+
}
36+
37+
let mut rustdoc = rustdoc();
38+
rustdoc
39+
.input("src/lib.rs")
40+
.output(&out_dir)
41+
.crate_name(crate_name)
42+
.crate_type("lib")
43+
.arg("-Zunstable-options");
44+
for dep in out_deps {
45+
rustdoc.arg("--with-examples").arg(dep);
46+
}
47+
rustdoc.run();
48+
49+
python_command()
50+
.arg(source_path().join("/src/etc/htmldocck.py"))
51+
.arg(out_dir)
52+
.arg("src/lib.rs")
53+
.status()
54+
.unwrap()
55+
.success();
56+
}

0 commit comments

Comments
 (0)