2024-05-17 05:12:44 -05:00
|
|
|
use std::path::Path;
|
|
|
|
|
2024-08-10 13:06:10 -05:00
|
|
|
use run_make_support::{htmldocck, rfs, rustc, rustdoc};
|
2024-07-28 17:13:50 -05:00
|
|
|
|
2024-05-19 07:00:12 -05:00
|
|
|
pub fn scrape(extra_args: &[&str]) {
|
2024-06-06 14:34:34 -05:00
|
|
|
let out_dir = Path::new("rustdoc");
|
2024-05-17 05:12:44 -05:00
|
|
|
let crate_name = "foobar";
|
2024-07-17 07:42:06 -05:00
|
|
|
let deps = rfs::read_dir("examples")
|
2024-05-17 05:12:44 -05:00
|
|
|
.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")
|
2024-08-15 07:44:48 -05:00
|
|
|
.out_dir(&out_dir)
|
2024-06-06 14:34:34 -05:00
|
|
|
.extern_(crate_name, format!("lib{crate_name}.rmeta"))
|
2024-05-17 05:12:44 -05:00
|
|
|
.arg("-Zunstable-options")
|
|
|
|
.arg("--scrape-examples-output-path")
|
|
|
|
.arg(&out_example)
|
|
|
|
.arg("--scrape-examples-target-crate")
|
|
|
|
.arg(crate_name)
|
2024-05-19 07:00:12 -05:00
|
|
|
.args(extra_args)
|
2024-05-17 05:12:44 -05:00
|
|
|
.run();
|
|
|
|
out_deps.push(out_example);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut rustdoc = rustdoc();
|
|
|
|
rustdoc
|
|
|
|
.input("src/lib.rs")
|
2024-08-15 07:44:48 -05:00
|
|
|
.out_dir(&out_dir)
|
2024-05-17 05:12:44 -05:00
|
|
|
.crate_name(crate_name)
|
|
|
|
.crate_type("lib")
|
|
|
|
.arg("-Zunstable-options");
|
|
|
|
for dep in out_deps {
|
|
|
|
rustdoc.arg("--with-examples").arg(dep);
|
|
|
|
}
|
|
|
|
rustdoc.run();
|
|
|
|
|
2024-06-09 10:45:57 -05:00
|
|
|
htmldocck().arg(out_dir).arg("src/lib.rs").run();
|
2024-05-17 05:12:44 -05:00
|
|
|
}
|