From da6d82e465f94202dd1bacc6f5d61e0dcb1f3e7c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 10 Jul 2021 21:09:51 +0200 Subject: [PATCH] Simplify build system for rustdoc-gui test crates --- .gitignore | 3 +++ src/bootstrap/test.rs | 26 +++++++++---------- src/test/rustdoc-gui/src/Cargo.lock | 18 +++++++++++++ src/test/rustdoc-gui/src/Cargo.toml | 6 +++++ src/test/rustdoc-gui/src/lib2/Cargo.toml | 10 +++++++ .../rustdoc-gui/src/{lib2.rs => lib2/lib.rs} | 2 ++ src/test/rustdoc-gui/src/lib2/src/lib.rs | 7 +++++ src/test/rustdoc-gui/src/test_docs/Cargo.toml | 7 +++++ .../rustdoc-gui/src/{ => test_docs}/lib.rs | 0 9 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 src/test/rustdoc-gui/src/Cargo.lock create mode 100644 src/test/rustdoc-gui/src/Cargo.toml create mode 100644 src/test/rustdoc-gui/src/lib2/Cargo.toml rename src/test/rustdoc-gui/src/{lib2.rs => lib2/lib.rs} (91%) create mode 100644 src/test/rustdoc-gui/src/lib2/src/lib.rs create mode 100644 src/test/rustdoc-gui/src/test_docs/Cargo.toml rename src/test/rustdoc-gui/src/{ => test_docs}/lib.rs (100%) diff --git a/.gitignore b/.gitignore index 0cd6b9f648d..b7e8e8fa157 100644 --- a/.gitignore +++ b/.gitignore @@ -72,4 +72,7 @@ __pycache__/ **node_modules **package-lock.json +## Rustdoc GUI tests +src/test/rustdoc-gui/src/**.lock + # Before adding new lines, see the comment at the top. diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index e4d6a3f587b..61ffae47e2a 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -907,27 +907,25 @@ fn run(self, builder: &Builder<'_>) { // We remove existing folder to be sure there won't be artifacts remaining. let _ = fs::remove_dir_all(&out_dir); - let mut nb_generated = 0; + let src_path = "src/test/rustdoc-gui/src"; // We generate docs for the libraries present in the rustdoc-gui's src folder. - let libs_dir = builder.build.src.join("src/test/rustdoc-gui/src"); - for entry in libs_dir.read_dir().expect("read_dir call failed") { - let entry = entry.expect("invalid entry"); - let path = entry.path(); - if path.extension().map(|e| e == "rs").unwrap_or(false) { - let mut command = builder.rustdoc_cmd(self.compiler); - command.arg(path).arg("-o").arg(&out_dir); - builder.run(&mut command); - nb_generated += 1; - } - } - assert!(nb_generated > 0, "no documentation was generated..."); + let mut cargo = Command::new(&builder.initial_cargo); + cargo + .arg("doc") + .arg("--workspace") + .arg("--target-dir") + .arg(&out_dir) + .env("RUSTDOC", builder.rustdoc(self.compiler)) + .env("RUSTC", builder.rustc(self.compiler)) + .current_dir(&builder.build.src.join(src_path)); + builder.run(&mut cargo); // We now run GUI tests. let mut command = Command::new(&nodejs); command .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js")) .arg("--doc-folder") - .arg(out_dir) + .arg(out_dir.join("doc")) .arg("--tests-folder") .arg(builder.build.src.join("src/test/rustdoc-gui")); for path in &builder.paths { diff --git a/src/test/rustdoc-gui/src/Cargo.lock b/src/test/rustdoc-gui/src/Cargo.lock new file mode 100644 index 00000000000..a72ccffc6dd --- /dev/null +++ b/src/test/rustdoc-gui/src/Cargo.lock @@ -0,0 +1,18 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "implementors" +version = "0.1.0" + +[[package]] +name = "lib2" +version = "0.1.0" +dependencies = [ + "implementors", +] + +[[package]] +name = "test_docs" +version = "0.1.0" diff --git a/src/test/rustdoc-gui/src/Cargo.toml b/src/test/rustdoc-gui/src/Cargo.toml new file mode 100644 index 00000000000..9c8c0c636f0 --- /dev/null +++ b/src/test/rustdoc-gui/src/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = [ + "test_docs", + "lib2", + "implementors", +] diff --git a/src/test/rustdoc-gui/src/lib2/Cargo.toml b/src/test/rustdoc-gui/src/lib2/Cargo.toml new file mode 100644 index 00000000000..6041a793f08 --- /dev/null +++ b/src/test/rustdoc-gui/src/lib2/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "lib2" +version = "0.1.0" +edition = "2018" + +[lib] +path = "lib.rs" + +[dependencies] +implementors = { path = "../implementors" } diff --git a/src/test/rustdoc-gui/src/lib2.rs b/src/test/rustdoc-gui/src/lib2/lib.rs similarity index 91% rename from src/test/rustdoc-gui/src/lib2.rs rename to src/test/rustdoc-gui/src/lib2/lib.rs index 77d384f3113..72ef3cbd202 100644 --- a/src/test/rustdoc-gui/src/lib2.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -31,3 +31,5 @@ impl Trait for Foo { type X = u32; const Y: u32 = 0; } + +impl implementors::Whatever for Foo {} diff --git a/src/test/rustdoc-gui/src/lib2/src/lib.rs b/src/test/rustdoc-gui/src/lib2/src/lib.rs new file mode 100644 index 00000000000..31e1bb209f9 --- /dev/null +++ b/src/test/rustdoc-gui/src/lib2/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/test/rustdoc-gui/src/test_docs/Cargo.toml b/src/test/rustdoc-gui/src/test_docs/Cargo.toml new file mode 100644 index 00000000000..7f3c65746fc --- /dev/null +++ b/src/test/rustdoc-gui/src/test_docs/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "test_docs" +version = "0.1.0" +edition = "2018" + +[lib] +path = "lib.rs" diff --git a/src/test/rustdoc-gui/src/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs similarity index 100% rename from src/test/rustdoc-gui/src/lib.rs rename to src/test/rustdoc-gui/src/test_docs/lib.rs