Skip to content

Commit c90db3d

Browse files
committed
move exit-code to rmake
1 parent 48a15aa commit c90db3d

File tree

4 files changed

+160
-12
lines changed

4 files changed

+160
-12
lines changed

src/tools/run-make-support/src/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use std::env;
22
use std::path::{Path, PathBuf};
33
use std::process::{Command, Output};
44

5+
mod rustdoc;
6+
pub use rustdoc::rustdoc;
7+
58
fn setup_common_build_cmd() -> Command {
69
let rustc = env::var("RUSTC").unwrap();
710
let mut cmd = Command::new(rustc);
@@ -45,6 +48,11 @@ impl RustcInvocationBuilder {
4548
self
4649
}
4750

51+
pub fn env(&mut self, key: &str, value: &str) -> &mut RustcInvocationBuilder {
52+
self.cmd.env(key, value);
53+
self
54+
}
55+
4856
#[track_caller]
4957
pub fn run(&mut self) -> Output {
5058
let caller_location = std::panic::Location::caller();
@@ -56,6 +64,18 @@ impl RustcInvocationBuilder {
5664
}
5765
output
5866
}
67+
68+
#[track_caller]
69+
pub fn run_fail(&mut self) -> Output {
70+
let caller_location = std::panic::Location::caller();
71+
let caller_line_number = caller_location.line();
72+
73+
let output = self.cmd.output().unwrap();
74+
if output.status.success() {
75+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
76+
}
77+
output
78+
}
5979
}
6080

6181
#[derive(Debug)]
@@ -149,3 +169,7 @@ pub fn run_fail(bin_name: &str) -> Output {
149169
}
150170
output
151171
}
172+
173+
pub fn tempdir() -> PathBuf {
174+
PathBuf::from(env::var("TMPDIR").unwrap())
175+
}
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use std::env;
2+
use std::path::Path;
3+
use std::process::{Command, Output};
4+
5+
use crate::handle_failed_output;
6+
7+
pub fn rustdoc() -> RustdocInvocationBuilder {
8+
RustdocInvocationBuilder::new()
9+
}
10+
11+
#[derive(Debug)]
12+
pub struct RustdocInvocationBuilder {
13+
cmd: Command,
14+
}
15+
16+
impl RustdocInvocationBuilder {
17+
fn new() -> Self {
18+
let cmd = setup_common_rustdoc_build_cmd();
19+
Self { cmd }
20+
}
21+
22+
pub fn arg(&mut self, arg: &str) -> &mut RustdocInvocationBuilder {
23+
self.cmd.arg(arg);
24+
self
25+
}
26+
27+
pub fn arg_file(&mut self, arg: &Path) -> &mut RustdocInvocationBuilder {
28+
self.cmd.arg(arg);
29+
self
30+
}
31+
32+
pub fn env(&mut self, key: &str, value: &str) -> &mut RustdocInvocationBuilder {
33+
self.cmd.env(key, value);
34+
self
35+
}
36+
37+
#[track_caller]
38+
pub fn run(&mut self) -> Output {
39+
let caller_location = std::panic::Location::caller();
40+
let caller_line_number = caller_location.line();
41+
42+
let output = self.cmd.output().unwrap();
43+
if !output.status.success() {
44+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
45+
}
46+
output
47+
}
48+
49+
#[track_caller]
50+
pub fn run_fail(&mut self) -> Output {
51+
let caller_location = std::panic::Location::caller();
52+
let caller_line_number = caller_location.line();
53+
54+
let output = self.cmd.output().unwrap();
55+
if output.status.success() {
56+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
57+
}
58+
output
59+
}
60+
}
61+
62+
fn setup_common_rustdoc_build_cmd() -> Command {
63+
use std::env::VarError;
64+
65+
let rustdoc = env::var("RUSTDOC").unwrap();
66+
let target_rpath_dir = env::var("TARGET_RPATH_DIR").unwrap();
67+
68+
let mut cmd = Command::new(rustdoc);
69+
70+
cmd.arg("-L").arg(target_rpath_dir);
71+
72+
match std::env::var("RUSTC_LINKER") {
73+
Ok(rustc_linker) => {
74+
cmd.arg(&format!("-Clinker='{rustc_linker}'"));
75+
}
76+
Err(VarError::NotPresent) => {}
77+
Err(VarError::NotUnicode(s)) => {
78+
panic!("RUSTC_LINKER was found, but set to non-unicode string {s:?}");
79+
}
80+
}
81+
82+
cmd
83+
}

tests/run-make/exit-code/Makefile

-12
This file was deleted.

tests/run-make/exit-code/rmake.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
extern crate run_make_support;
2+
3+
use run_make_support::{rustc, rustdoc, tempdir};
4+
5+
fn main() {
6+
rustc()
7+
.arg("success.rs")
8+
.run();
9+
10+
assert_eq!(rustc()
11+
.arg("--invalid-arg-foo")
12+
.run_fail()
13+
.status
14+
.code().unwrap(), 1);
15+
16+
assert_eq!(rustc()
17+
.arg("compile-error.rs")
18+
.run_fail()
19+
.status
20+
.code().unwrap(), 1);
21+
22+
assert_eq!(rustc()
23+
.env("RUSTC_ICE", "0")
24+
.arg("-Ztreat-err-as-bug")
25+
.arg("compile-error.rs")
26+
.run_fail()
27+
.status
28+
.code().unwrap(), 101);
29+
30+
rustdoc()
31+
.arg("-o")
32+
.arg_file(&tempdir().join("exit-code"))
33+
.arg("success.rs")
34+
.run();
35+
36+
assert_eq!(rustdoc()
37+
.arg("--invalid-arg-foo")
38+
.run_fail()
39+
.status
40+
.code().unwrap(), 1);
41+
42+
assert_eq!(rustdoc()
43+
.arg("compile-error.rs")
44+
.run_fail()
45+
.status
46+
.code().unwrap(), 1);
47+
48+
assert_eq!(rustdoc()
49+
.arg("lint-failure.rs")
50+
.run_fail()
51+
.status
52+
.code().unwrap(), 1);
53+
}

0 commit comments

Comments
 (0)