From 65df93bbb43c054cb413c8e22543e615d68957d8 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 25 Mar 2024 11:05:43 +0000 Subject: [PATCH 1/2] move exit-code to rmake --- src/tools/run-make-support/src/rustc.rs | 12 ++++++ src/tools/run-make-support/src/rustdoc.rs | 17 ++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/exit-code/Makefile | 12 ------ tests/run-make/exit-code/rmake.rs | 42 +++++++++++++++++++ 5 files changed, 71 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/exit-code/Makefile create mode 100644 tests/run-make/exit-code/rmake.rs diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 217da36ccc7d7..f3844477ac342 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -183,6 +183,18 @@ impl Rustc { output } + #[track_caller] + pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output { + let caller_location = std::panic::Location::caller(); + let caller_line_number = caller_location.line(); + + let output = self.cmd.output().unwrap(); + if output.status.code().unwrap() != code { + handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); + } + output + } + /// Inspect what the underlying [`Command`] is up to the current construction. pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self { f(&self.cmd); diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index 9607ff02f9686..cbf328b67fde2 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -65,6 +65,11 @@ impl Rustdoc { self } + pub fn arg_path>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } + /// Run the build `rustdoc` command and assert that the run is successful. #[track_caller] pub fn run(&mut self) -> Output { @@ -77,4 +82,16 @@ impl Rustdoc { } output } + + #[track_caller] + pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output { + let caller_location = std::panic::Location::caller(); + let caller_line_number = caller_location.line(); + + let output = self.cmd.output().unwrap(); + if output.status.code().unwrap() != code { + handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); + } + output + } } diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index dfd30d79abca9..3914feb3499dd 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -59,7 +59,6 @@ run-make/emit/Makefile run-make/env-dep-info/Makefile run-make/error-found-staticlib-instead-crate/Makefile run-make/error-writing-dependencies/Makefile -run-make/exit-code/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile diff --git a/tests/run-make/exit-code/Makefile b/tests/run-make/exit-code/Makefile deleted file mode 100644 index 155e5cd112344..0000000000000 --- a/tests/run-make/exit-code/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) success.rs; [ $$? -eq 0 ] - $(RUSTC) --invalid-arg-foo; [ $$? -eq 1 ] - $(RUSTC) compile-error.rs; [ $$? -eq 1 ] - RUSTC_ICE=0 $(RUSTC) -Ztreat-err-as-bug compile-error.rs; [ $$? -eq 101 ] - $(RUSTDOC) -o $(TMPDIR)/exit-code success.rs; [ $$? -eq 0 ] - $(RUSTDOC) --invalid-arg-foo; [ $$? -eq 1 ] - $(RUSTDOC) compile-error.rs; [ $$? -eq 1 ] - $(RUSTDOC) lint-failure.rs; [ $$? -eq 1 ] diff --git a/tests/run-make/exit-code/rmake.rs b/tests/run-make/exit-code/rmake.rs new file mode 100644 index 0000000000000..8fcdb4acdc587 --- /dev/null +++ b/tests/run-make/exit-code/rmake.rs @@ -0,0 +1,42 @@ +// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations + +extern crate run_make_support; + +use run_make_support::{rustc, rustdoc, tmp_dir}; + +fn main() { + rustc() + .arg("success.rs") + .run(); + + rustc() + .arg("--invalid-arg-foo") + .run_fail_assert_exit_code(1); + + rustc() + .arg("compile-error.rs") + .run_fail_assert_exit_code(1); + + rustc() + .env("RUSTC_ICE", "0") + .arg("-Ztreat-err-as-bug") + .arg("compile-error.rs") + .run_fail_assert_exit_code(101); + + rustdoc() + .arg("success.rs") + .arg("-o").arg_path(tmp_dir().join("exit-code")) + .run(); + + rustdoc() + .arg("--invalid-arg-foo") + .run_fail_assert_exit_code(1); + + rustdoc() + .arg("compile-error.rs") + .run_fail_assert_exit_code(1); + + rustdoc() + .arg("lint-failure.rs") + .run_fail_assert_exit_code(1); +} From de79a6c08405bbaaa7fa9431d26ae0bacdfb0213 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 9 Apr 2024 19:55:06 +0100 Subject: [PATCH 2/2] run-make: make arg take AsRef instead of str --- src/tools/run-make-support/src/rustdoc.rs | 11 +++-------- tests/run-make/exit-code/rmake.rs | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index cbf328b67fde2..1fb4b589d76af 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -1,4 +1,5 @@ use std::env; +use std::ffi::OsStr; use std::path::Path; use std::process::{Command, Output}; @@ -58,18 +59,12 @@ impl Rustdoc { self } - /// Fallback argument provider. Consider adding meaningfully named methods instead of using - /// this method. - pub fn arg(&mut self, arg: &str) -> &mut Self { + /// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`. + pub fn arg>(&mut self, arg: S) -> &mut Self { self.cmd.arg(arg); self } - pub fn arg_path>(&mut self, path: P) -> &mut Self { - self.cmd.arg(path.as_ref()); - self - } - /// Run the build `rustdoc` command and assert that the run is successful. #[track_caller] pub fn run(&mut self) -> Output { diff --git a/tests/run-make/exit-code/rmake.rs b/tests/run-make/exit-code/rmake.rs index 8fcdb4acdc587..f387626287e3f 100644 --- a/tests/run-make/exit-code/rmake.rs +++ b/tests/run-make/exit-code/rmake.rs @@ -25,7 +25,8 @@ fn main() { rustdoc() .arg("success.rs") - .arg("-o").arg_path(tmp_dir().join("exit-code")) + .arg("-o") + .arg(tmp_dir().join("exit-code")) .run(); rustdoc()