Skip to content

Commit

Permalink
Migrate rustdoc-scrape-examples-ordering to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 11, 2024
1 parent 0712ae8 commit df8c037
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use std::ffi::OsString;
use std::ffi::{OsStr, OsString};
use std::io::Write;
use std::path::Path;
use std::process::{Command, Output, Stdio};
Expand Down Expand Up @@ -177,9 +177,9 @@ impl Rustc {
}

/// Specify the crate name.
pub fn crate_name(&mut self, name: &str) -> &mut Self {
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
self.cmd.arg("--crate-name");
self.cmd.arg(name);
self.cmd.arg(name.as_ref());
self
}

Expand Down
5 changes: 3 additions & 2 deletions src/tools/run-make-support/src/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::ffi::OsStr;
use std::io::Write;
use std::path::Path;
use std::process::{Command, Output, Stdio};
Expand Down Expand Up @@ -130,9 +131,9 @@ impl Rustdoc {
}

/// Specify the crate name.
pub fn crate_name(&mut self, name: &str) -> &mut Self {
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
self.cmd.arg("--crate-name");
self.cmd.arg(name);
self.cmd.arg(name.as_ref());
self
}

Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ run-make/rustdoc-io-error/Makefile
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
run-make/rustdoc-scrape-examples-macros/Makefile
run-make/rustdoc-scrape-examples-multiple/Makefile
run-make/rustdoc-scrape-examples-ordering/Makefile
run-make/rustdoc-scrape-examples-remap/Makefile
run-make/rustdoc-scrape-examples-test/Makefile
run-make/rustdoc-scrape-examples-whitespace/Makefile
Expand Down
5 changes: 0 additions & 5 deletions tests/run-make/rustdoc-scrape-examples-ordering/Makefile

This file was deleted.

56 changes: 56 additions & 0 deletions tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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");
eprintln!("--> {out_dir:?}",);
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();
}

0 comments on commit df8c037

Please sign in to comment.