about summary refs log tree commit diff
path: root/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-05-11 20:27:50 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-05-12 11:30:52 +0200
commit114e25761ff1cf1ee75aa85cabc197a5095cf484 (patch)
tree7617204367f04e6567d68e190d509eabc79541c8 /tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs
parent0712ae865f6658c5c36b5ccf347309a03742441d (diff)
downloadrust-114e25761ff1cf1ee75aa85cabc197a5095cf484.tar.gz
rust-114e25761ff1cf1ee75aa85cabc197a5095cf484.zip
Migrate `rustdoc-scrape-examples-ordering` to `rmake`
Diffstat (limited to 'tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs')
-rw-r--r--tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs b/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs
new file mode 100644
index 00000000000..edcf3406d47
--- /dev/null
+++ b/tests/run-make/rustdoc-scrape-examples-ordering/rmake.rs
@@ -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();
+}