From a56ba918d226f2e210994f486d7dd3e06328b19f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 4 May 2024 23:19:12 +0200 Subject: [PATCH 1/5] Implement `edition` method on `Rustdoc` type as well --- src/tools/run-make-support/src/rustdoc.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index c2c4f2e68e2f8..6733925b74d03 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -93,6 +93,13 @@ impl Rustdoc { } } + /// Specify the edition year. + pub fn edition(&mut self, edition: &str) -> &mut Self { + self.cmd.arg("--edition"); + self.cmd.arg(edition); + self + } + #[track_caller] pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output { let caller_location = std::panic::Location::caller(); From 3c2cf2e50b83f24851c12286cab54f5fb20e1b13 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 4 May 2024 16:18:36 +0200 Subject: [PATCH 2/5] Migrate `run-make/doctests-runtool` to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/doctests-runtool/Makefile | 20 ---------- tests/run-make/doctests-runtool/rmake.rs | 39 +++++++++++++++++++ 3 files changed, 39 insertions(+), 21 deletions(-) delete mode 100644 tests/run-make/doctests-runtool/Makefile create mode 100644 tests/run-make/doctests-runtool/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index d4d6c1460ceec..f96386a143d23 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -44,7 +44,6 @@ run-make/dep-graph/Makefile run-make/dep-info-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile -run-make/doctests-runtool/Makefile run-make/dump-ice-to-disk/Makefile run-make/dump-mono-stats/Makefile run-make/duplicate-output-flavors/Makefile diff --git a/tests/run-make/doctests-runtool/Makefile b/tests/run-make/doctests-runtool/Makefile deleted file mode 100644 index 7d5df1e307fb8..0000000000000 --- a/tests/run-make/doctests-runtool/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Tests behavior of rustdoc --runtool - -MY_SRC_DIR := ${CURDIR} - -all: with_test_run_directory - -# Behavior with --runtool with relative paths and --test-run-directory. -with_test_run_directory: - mkdir -p $(TMPDIR)/rundir - mkdir -p $(TMPDIR)/runtool - $(RUSTC) --crate-type rlib t.rs - $(RUSTC) runtool.rs -o $(TMPDIR)/runtool/runtool - ( cd $(TMPDIR); \ - $(RUSTDOC) -Zunstable-options --test --test-run-directory rundir \ - --runtool runtool/runtool --extern t=libt.rlib $(MY_SRC_DIR)/t.rs \ - ) - rm -rf $(TMPDIR)/rundir $(TMPDIR)/runtool diff --git a/tests/run-make/doctests-runtool/rmake.rs b/tests/run-make/doctests-runtool/rmake.rs new file mode 100644 index 0000000000000..164514095289e --- /dev/null +++ b/tests/run-make/doctests-runtool/rmake.rs @@ -0,0 +1,39 @@ +// Tests behavior of rustdoc `--runtool`. + +use run_make_support::{rustc, rustdoc, tmp_dir}; +use std::env::current_dir; +use std::fs::{create_dir, remove_dir_all}; +use std::path::PathBuf; + +fn mkdir(name: &str) -> PathBuf { + let dir = tmp_dir().join(name); + create_dir(&dir).expect("failed to create doctests folder"); + dir +} + +// Behavior with --runtool with relative paths and --test-run-directory. +fn main() { + let run_dir_name = "rundir"; + let run_dir = mkdir(run_dir_name); + let run_tool = mkdir("runtool"); + let run_tool_binary = run_tool.join("runtool"); + + rustc().input("t.rs").crate_type("rlib").run(); + rustc().input("runtool.rs").arg("-o").arg(&run_tool_binary).run(); + + rustdoc() + .input(current_dir().unwrap().join("t.rs")) + .arg("-Zunstable-options") + .arg("--test") + .arg("--test-run-directory") + .arg(run_dir_name) + .arg("--runtool") + .arg(&run_tool_binary) + .arg("--extern") + .arg("t=libt.rlib") + .current_dir(tmp_dir()) + .run(); + + remove_dir_all(run_dir); + remove_dir_all(run_tool); +} From c04d09a76be381f2058a0421c745a1a697957969 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 5 May 2024 16:22:39 +0200 Subject: [PATCH 3/5] Rename `run-make-support` library `output` method to `command_output` --- src/tools/run-make-support/src/cc.rs | 2 +- src/tools/run-make-support/src/clang.rs | 2 +- src/tools/run-make-support/src/lib.rs | 6 +++--- src/tools/run-make-support/src/llvm_readobj.rs | 2 +- src/tools/run-make-support/src/rustc.rs | 4 ++-- src/tools/run-make-support/src/rustdoc.rs | 4 ++-- tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs | 3 ++- tests/run-make/wasm-abi/rmake.rs | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/tools/run-make-support/src/cc.rs b/src/tools/run-make-support/src/cc.rs index 4082639f618a1..a67f5c8a9ee43 100644 --- a/src/tools/run-make-support/src/cc.rs +++ b/src/tools/run-make-support/src/cc.rs @@ -73,7 +73,7 @@ impl Cc { } /// Get the [`Output`][::std::process::Output] of the finished process. - pub fn output(&mut self) -> ::std::process::Output { + pub fn command_output(&mut self) -> ::std::process::Output { self.cmd.output().expect("failed to get output of finished process") } } diff --git a/src/tools/run-make-support/src/clang.rs b/src/tools/run-make-support/src/clang.rs index c30ba29ed76d6..6ccce67b250db 100644 --- a/src/tools/run-make-support/src/clang.rs +++ b/src/tools/run-make-support/src/clang.rs @@ -72,7 +72,7 @@ impl Clang { } /// Get the [`Output`][::std::process::Output] of the finished process. - pub fn output(&mut self) -> ::std::process::Output { + pub fn command_output(&mut self) -> ::std::process::Output { self.cmd.output().expect("failed to get output of finished process") } } diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index d040b05f20e82..9888ca2d1ed95 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -164,7 +164,7 @@ pub fn set_host_rpath(cmd: &mut Command) { /// /// impl CommandWrapper { /// /// Get the [`Output`][::std::process::Output] of the finished process. -/// pub fn output(&mut self) -> Output { /* ... */ } // <- required `output()` method +/// pub fn command_output(&mut self) -> Output { /* ... */ } // <- required `command_output()` method /// } /// /// crate::impl_common_helpers!(CommandWrapper); @@ -242,7 +242,7 @@ macro_rules! impl_common_helpers { let caller_location = ::std::panic::Location::caller(); let caller_line_number = caller_location.line(); - let output = self.output(); + let output = self.command_output(); if !output.status.success() { handle_failed_output(&self.cmd, output, caller_line_number); } @@ -255,7 +255,7 @@ macro_rules! impl_common_helpers { let caller_location = ::std::panic::Location::caller(); let caller_line_number = caller_location.line(); - let output = self.output(); + let output = self.command_output(); if output.status.success() { handle_failed_output(&self.cmd, output, caller_line_number); } diff --git a/src/tools/run-make-support/src/llvm_readobj.rs b/src/tools/run-make-support/src/llvm_readobj.rs index 4e1f2b002f301..f114aacfa3fc7 100644 --- a/src/tools/run-make-support/src/llvm_readobj.rs +++ b/src/tools/run-make-support/src/llvm_readobj.rs @@ -44,7 +44,7 @@ impl LlvmReadobj { /// Get the [`Output`][::std::process::Output] of the finished process. #[track_caller] - pub fn output(&mut self) -> ::std::process::Output { + pub fn command_output(&mut self) -> ::std::process::Output { self.cmd.output().expect("failed to get output of finished process") } } diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 37539528ab3fc..dcd184ac5a458 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -171,7 +171,7 @@ impl Rustc { /// Get the [`Output`][::std::process::Output] of the finished process. #[track_caller] - pub fn output(&mut self) -> ::std::process::Output { + pub fn command_output(&mut self) -> ::std::process::Output { // let's make sure we piped all the input and outputs self.cmd.stdin(Stdio::piped()); self.cmd.stdout(Stdio::piped()); @@ -196,7 +196,7 @@ impl Rustc { let caller_location = std::panic::Location::caller(); let caller_line_number = caller_location.line(); - let output = self.output(); + let output = self.command_output(); if output.status.code().unwrap() != code { handle_failed_output(&self.cmd, output, caller_line_number); } diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index 6733925b74d03..ba8668a3b4c6f 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -73,7 +73,7 @@ impl Rustdoc { /// Get the [`Output`][::std::process::Output] of the finished process. #[track_caller] - pub fn output(&mut self) -> ::std::process::Output { + pub fn command_output(&mut self) -> ::std::process::Output { // let's make sure we piped all the input and outputs self.cmd.stdin(Stdio::piped()); self.cmd.stdout(Stdio::piped()); @@ -105,7 +105,7 @@ impl Rustdoc { let caller_location = std::panic::Location::caller(); let caller_line_number = caller_location.line(); - let output = self.output(); + let output = self.command_output(); if output.status.code().unwrap() != code { handle_failed_output(&self.cmd, output, caller_line_number); } diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs index 4b7ce4e57d57c..1bdb634757120 100644 --- a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs +++ b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs @@ -13,7 +13,8 @@ fn main() { let mut stable_path = PathBuf::from(env!("TMPDIR")); stable_path.push("libstable.rmeta"); - let output = rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).output(); + let output = + rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).command_output(); let stderr = String::from_utf8_lossy(&output.stderr); let version = include_str!(concat!(env!("S"), "/src/version")); diff --git a/tests/run-make/wasm-abi/rmake.rs b/tests/run-make/wasm-abi/rmake.rs index a2dcafbbe0f14..01f2b274423f4 100644 --- a/tests/run-make/wasm-abi/rmake.rs +++ b/tests/run-make/wasm-abi/rmake.rs @@ -25,7 +25,7 @@ fn run(file: &Path, method: &str, expected_output: &str) { .arg("--invoke") .arg(method) .arg(file) - .output() + .command_output() .unwrap(); assert!(output.status.success()); assert_eq!(expected_output, String::from_utf8_lossy(&output.stdout)); From 27e67414ae2c6d358883f1be3047b0b11d73c82a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 5 May 2024 16:26:35 +0200 Subject: [PATCH 4/5] Add new `output` method to `Rustc` and `Rustdoc` types --- src/tools/run-make-support/src/rustc.rs | 7 +++++++ src/tools/run-make-support/src/rustdoc.rs | 7 +++++++ tests/run-make/doctests-runtool/rmake.rs | 2 +- tests/run-make/exit-code/rmake.rs | 2 +- tests/run-make/repr128-dwarf/rmake.rs | 2 +- tests/run-make/rustdoc-determinism/rmake.rs | 23 +++++++++++---------- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index dcd184ac5a458..de773d688ef00 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -91,6 +91,13 @@ impl Rustc { self } + /// Specify path to the output file. + pub fn output>(&mut self, path: P) -> &mut Self { + self.cmd.arg("-o"); + self.cmd.arg(path.as_ref()); + self + } + /// This flag defers LTO optimizations to the linker. pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self { self.cmd.arg(format!("-Clinker-plugin-lto={option}")); diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index ba8668a3b4c6f..aa3c7dcf0e356 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -51,6 +51,13 @@ impl Rustdoc { self } + /// Specify path to the output folder. + pub fn output>(&mut self, path: P) -> &mut Self { + self.cmd.arg("-o"); + self.cmd.arg(path.as_ref()); + self + } + /// Specify output directory. pub fn out_dir>(&mut self, path: P) -> &mut Self { self.cmd.arg("--out-dir").arg(path.as_ref()); diff --git a/tests/run-make/doctests-runtool/rmake.rs b/tests/run-make/doctests-runtool/rmake.rs index 164514095289e..6f89bf23b47c4 100644 --- a/tests/run-make/doctests-runtool/rmake.rs +++ b/tests/run-make/doctests-runtool/rmake.rs @@ -19,7 +19,7 @@ fn main() { let run_tool_binary = run_tool.join("runtool"); rustc().input("t.rs").crate_type("rlib").run(); - rustc().input("runtool.rs").arg("-o").arg(&run_tool_binary).run(); + rustc().input("runtool.rs").output(&run_tool_binary).run(); rustdoc() .input(current_dir().unwrap().join("t.rs")) diff --git a/tests/run-make/exit-code/rmake.rs b/tests/run-make/exit-code/rmake.rs index b1143153d0af0..76d7777581b5e 100644 --- a/tests/run-make/exit-code/rmake.rs +++ b/tests/run-make/exit-code/rmake.rs @@ -15,7 +15,7 @@ fn main() { .arg("compile-error.rs") .run_fail_assert_exit_code(101); - rustdoc().arg("success.rs").arg("-o").arg(tmp_dir().join("exit-code")).run(); + rustdoc().arg("success.rs").output(tmp_dir().join("exit-code")).run(); rustdoc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1); diff --git a/tests/run-make/repr128-dwarf/rmake.rs b/tests/run-make/repr128-dwarf/rmake.rs index d734b2add79a2..fd5dd81044419 100644 --- a/tests/run-make/repr128-dwarf/rmake.rs +++ b/tests/run-make/repr128-dwarf/rmake.rs @@ -10,7 +10,7 @@ use std::rc::Rc; fn main() { let output = tmp_dir().join("repr128"); - rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run(); + rustc().input("main.rs").output(&output).arg("-Cdebuginfo=2").run(); // Mach-O uses packed debug info let dsym_location = output .with_extension("dSYM") diff --git a/tests/run-make/rustdoc-determinism/rmake.rs b/tests/run-make/rustdoc-determinism/rmake.rs index 38ae75199fd83..09097d4507daf 100644 --- a/tests/run-make/rustdoc-determinism/rmake.rs +++ b/tests/run-make/rustdoc-determinism/rmake.rs @@ -1,18 +1,19 @@ -use run_make_support::{diff, rustc, rustdoc, tmp_dir}; +// Assert that the search index is generated deterministically, regardless of the +// order that crates are documented in. + +use run_make_support::{diff, rustdoc, tmp_dir}; -/// Assert that the search index is generated deterministically, regardless of the -/// order that crates are documented in. fn main() { - let dir_first = tmp_dir().join("first"); - rustdoc().out_dir(&dir_first).input("foo.rs").run(); - rustdoc().out_dir(&dir_first).input("bar.rs").run(); + let foo_first = tmp_dir().join("foo_first"); + rustdoc().input("foo.rs").output(&foo_first).run(); + rustdoc().input("bar.rs").output(&foo_first).run(); - let dir_second = tmp_dir().join("second"); - rustdoc().out_dir(&dir_second).input("bar.rs").run(); - rustdoc().out_dir(&dir_second).input("foo.rs").run(); + let bar_first = tmp_dir().join("bar_first"); + rustdoc().input("bar.rs").output(&bar_first).run(); + rustdoc().input("foo.rs").output(&bar_first).run(); diff() - .expected_file(dir_first.join("search-index.js")) - .actual_file(dir_second.join("search-index.js")) + .expected_file(foo_first.join("search-index.js")) + .actual_file(bar_first.join("search-index.js")) .run(); } From bb474aa622098ca10792d0a8717d95dc0f3420fd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 5 May 2024 17:07:32 +0200 Subject: [PATCH 5/5] Migrate `run-make/rustdoc-error-lines` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/rustdoc-error-lines/Makefile | 13 ----------- tests/run-make/rustdoc-error-lines/rmake.rs | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) delete mode 100644 tests/run-make/rustdoc-error-lines/Makefile create mode 100644 tests/run-make/rustdoc-error-lines/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index f96386a143d23..f4ae7b06cdbb1 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -244,7 +244,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile run-make/rlib-format-packed-bundled-libs/Makefile run-make/rmeta-preferred/Makefile run-make/rustc-macro-dep-files/Makefile -run-make/rustdoc-error-lines/Makefile run-make/rustdoc-io-error/Makefile run-make/rustdoc-map-file/Makefile run-make/rustdoc-output-path/Makefile diff --git a/tests/run-make/rustdoc-error-lines/Makefile b/tests/run-make/rustdoc-error-lines/Makefile deleted file mode 100644 index 2dc30f56b833f..0000000000000 --- a/tests/run-make/rustdoc-error-lines/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -include ../tools.mk - -# Test that hir-tree output doesn't crash and includes -# the string constant we would expect to see. - -all: - $(RUSTDOC) --test input.rs > $(TMPDIR)/output || true - $(CGREP) 'input.rs - foo (line 5)' < $(TMPDIR)/output - $(CGREP) 'input.rs:7:15' < $(TMPDIR)/output - $(CGREP) 'input.rs - bar (line 15)' < $(TMPDIR)/output - $(CGREP) 'input.rs:17:15' < $(TMPDIR)/output - $(CGREP) 'input.rs - bar (line 24)' < $(TMPDIR)/output - $(CGREP) 'input.rs:26:15' < $(TMPDIR)/output diff --git a/tests/run-make/rustdoc-error-lines/rmake.rs b/tests/run-make/rustdoc-error-lines/rmake.rs new file mode 100644 index 0000000000000..31536c78dd460 --- /dev/null +++ b/tests/run-make/rustdoc-error-lines/rmake.rs @@ -0,0 +1,22 @@ +// Assert that the search index is generated deterministically, regardless of the +// order that crates are documented in. + +use run_make_support::rustdoc; + +fn main() { + let output = + String::from_utf8(rustdoc().input("input.rs").arg("--test").command_output().stdout) + .unwrap(); + + let should_contain = &[ + "input.rs - foo (line 5)", + "input.rs:7:15", + "input.rs - bar (line 15)", + "input.rs:17:15", + "input.rs - bar (line 24)", + "input.rs:26:15", + ]; + for text in should_contain { + assert!(output.contains(text), "output doesn't contains {:?}", text); + } +}