Skip to content

Commit 114e257

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

File tree

5 files changed

+61
-11
lines changed

5 files changed

+61
-11
lines changed

Diff for: 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

Diff for: 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

Diff for: 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

Diff for: tests/run-make/rustdoc-scrape-examples-ordering/Makefile

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

0 commit comments

Comments
 (0)