forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#125022 - GuillaumeGomez:migrate-rustdoc-scrape-examples-ordering, r=jieyouxu Migrate rustdoc scrape examples ordering Part of rust-lang#121876. This one adds a lot of utility methods/functions. To prevent having too much changes at once, I didn't make the existing rmake tests use these yet but I'll send a follow-up so they all use it. r? `@jieyouxu`
- Loading branch information
Showing
6 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use run_make_support::{python_command, rustc, rustdoc, source_path, tmp_dir}; | ||
use std::fs::read_dir; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
let lib_dir = tmp_dir(); | ||
let out_dir = tmp_dir().join("rustdoc"); | ||
let crate_name = "foobar"; | ||
let deps = read_dir("examples") | ||
.unwrap() | ||
.filter_map(|entry| entry.ok().map(|e| e.path())) | ||
.filter(|path| path.is_file() && path.extension().is_some_and(|ext| ext == "rs")) | ||
.collect::<Vec<_>>(); | ||
|
||
rustc().input("src/lib.rs").crate_name(crate_name).crate_type("lib").emit("metadata").run(); | ||
|
||
let mut out_deps = Vec::with_capacity(deps.len()); | ||
for dep in deps { | ||
let dep_stem = dep.file_stem().unwrap(); | ||
let out_example = out_dir.join(format!("{}.calls", dep_stem.to_str().unwrap())); | ||
rustdoc() | ||
.input(&dep) | ||
.crate_name(&dep_stem) | ||
.crate_type("bin") | ||
.output(&out_dir) | ||
.extern_(crate_name, lib_dir.join(format!("lib{crate_name}.rmeta"))) | ||
.arg("-Zunstable-options") | ||
.arg("--scrape-examples-output-path") | ||
.arg(&out_example) | ||
.arg("--scrape-examples-target-crate") | ||
.arg(crate_name) | ||
.run(); | ||
out_deps.push(out_example); | ||
} | ||
|
||
let mut rustdoc = rustdoc(); | ||
rustdoc | ||
.input("src/lib.rs") | ||
.output(&out_dir) | ||
.crate_name(crate_name) | ||
.crate_type("lib") | ||
.arg("-Zunstable-options"); | ||
for dep in out_deps { | ||
rustdoc.arg("--with-examples").arg(dep); | ||
} | ||
rustdoc.run(); | ||
|
||
python_command() | ||
.arg(source_path().join("/src/etc/htmldocck.py")) | ||
.arg(out_dir) | ||
.arg("src/lib.rs") | ||
.status() | ||
.unwrap() | ||
.success(); | ||
} |