From e509c24fbfddcc572d0b64df59c03d308eb13013 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 May 2024 12:12:44 +0200 Subject: [PATCH 1/2] Migrate `run-make/rustdoc-scrape-examples-remap` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../rustdoc-scrape-examples-remap/Makefile | 5 -- .../rustdoc-scrape-examples-remap/rmake.rs | 5 ++ .../rustdoc-scrape-examples-remap/scrape.rs | 49 +++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) delete mode 100644 tests/run-make/rustdoc-scrape-examples-remap/Makefile create mode 100644 tests/run-make/rustdoc-scrape-examples-remap/rmake.rs create mode 100644 tests/run-make/rustdoc-scrape-examples-remap/scrape.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1a3d6f8d81360..0594ee5c698d2 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -239,7 +239,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-remap/Makefile run-make/rustdoc-scrape-examples-test/Makefile run-make/rustdoc-scrape-examples-whitespace/Makefile run-make/rustdoc-verify-output-files/Makefile diff --git a/tests/run-make/rustdoc-scrape-examples-remap/Makefile b/tests/run-make/rustdoc-scrape-examples-remap/Makefile deleted file mode 100644 index 7786ff762cb30..0000000000000 --- a/tests/run-make/rustdoc-scrape-examples-remap/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -deps := ex - -include ../rustdoc-scrape-examples-multiple/scrape.mk - -all: scrape diff --git a/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs b/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs new file mode 100644 index 0000000000000..d9deaf279ce52 --- /dev/null +++ b/tests/run-make/rustdoc-scrape-examples-remap/rmake.rs @@ -0,0 +1,5 @@ +mod scrape; + +fn main() { + scrape::scrape(); +} diff --git a/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs b/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs new file mode 100644 index 0000000000000..709388b549214 --- /dev/null +++ b/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs @@ -0,0 +1,49 @@ +use run_make_support::{htmldocck, rustc, rustdoc, source_path, tmp_dir}; +use std::fs::read_dir; +use std::path::Path; + +pub fn scrape() { + 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::>(); + + 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(); + + assert!(htmldocck().arg(out_dir).arg("src/lib.rs").status().unwrap().success()); +} From 272fc89a1cad668c1fa6e789b51f07c5040e7fad Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 May 2024 12:13:22 +0200 Subject: [PATCH 2/2] Use common `scrape.rs` file --- .../rustdoc-scrape-examples-ordering/rmake.rs | 49 ++----------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs b/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs index 1bc23ec88817f..537d3e2d724a5 100644 --- a/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs @@ -1,49 +1,6 @@ -use run_make_support::{htmldocck, rustc, rustdoc, source_path, tmp_dir}; -use std::fs::read_dir; -use std::path::Path; +#[path = "../rustdoc-scrape-examples-remap/scrape.rs"] +mod scrape; 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::>(); - - 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(); - - assert!(htmldocck().arg(out_dir).arg("src/lib.rs").status().unwrap().success()); + scrape::scrape(); }