Skip to content

Commit 76e19ff

Browse files
committed
run-make-support: use macro to implement common methods
Removes the manual copy-pasta'd implementation of common methods.
1 parent c53d977 commit 76e19ff

File tree

3 files changed

+8
-112
lines changed

3 files changed

+8
-112
lines changed

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

+3-36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22
use std::path::Path;
3-
use std::process::{Command, Output};
3+
use std::process::Command;
44

55
use crate::{bin_name, cygpath_windows, handle_failed_output, is_msvc, is_windows, tmp_dir, uname};
66

@@ -19,6 +19,8 @@ pub struct Cc {
1919
cmd: Command,
2020
}
2121

22+
crate::impl_common_helpers!(Cc);
23+
2224
impl Cc {
2325
/// Construct a new platform-specific C compiler invocation.
2426
///
@@ -43,22 +45,6 @@ impl Cc {
4345
self
4446
}
4547

46-
/// Add a *platform-and-compiler-specific* argument. Please consult the docs for the various
47-
/// possible C compilers on the various platforms to check which arguments are legal for
48-
/// which compiler.
49-
pub fn arg(&mut self, flag: &str) -> &mut Self {
50-
self.cmd.arg(flag);
51-
self
52-
}
53-
54-
/// Add multiple *platform-and-compiler-specific* arguments. Please consult the docs for the
55-
/// various possible C compilers on the various platforms to check which arguments are legal
56-
/// for which compiler.
57-
pub fn args(&mut self, args: &[&str]) -> &mut Self {
58-
self.cmd.args(args);
59-
self
60-
}
61-
6248
/// Specify `-o` or `-Fe`/`-Fo` depending on platform/compiler. This assumes that the executable
6349
/// is under `$TMPDIR`.
6450
pub fn out_exe(&mut self, name: &str) -> &mut Self {
@@ -85,25 +71,6 @@ impl Cc {
8571

8672
self
8773
}
88-
89-
/// Run the constructed C invocation command and assert that it is successfully run.
90-
#[track_caller]
91-
pub fn run(&mut self) -> Output {
92-
let caller_location = std::panic::Location::caller();
93-
let caller_line_number = caller_location.line();
94-
95-
let output = self.cmd.output().unwrap();
96-
if !output.status.success() {
97-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
98-
}
99-
output
100-
}
101-
102-
/// Inspect what the underlying [`Command`] is up to the current construction.
103-
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
104-
f(&self.cmd);
105-
self
106-
}
10774
}
10875

10976
/// `EXTRACFLAGS`

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

+3-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use std::ffi::{OsStr, OsString};
2+
use std::ffi::OsString;
33
use std::path::Path;
44
use std::process::{Command, Output};
55

@@ -21,6 +21,8 @@ pub struct Rustc {
2121
cmd: Command,
2222
}
2323

24+
crate::impl_common_helpers!(Rustc);
25+
2426
fn setup_common() -> Command {
2527
let rustc = env::var("RUSTC").unwrap();
2628
let mut cmd = Command::new(rustc);
@@ -132,12 +134,6 @@ impl Rustc {
132134
self
133135
}
134136

135-
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
136-
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
137-
self.cmd.arg(arg);
138-
self
139-
}
140-
141137
/// Specify the crate type.
142138
pub fn crate_type(&mut self, crate_type: &str) -> &mut Self {
143139
self.cmd.arg("--crate-type");
@@ -152,49 +148,6 @@ impl Rustc {
152148
self
153149
}
154150

155-
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
156-
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Self {
157-
self.cmd.args(args);
158-
self
159-
}
160-
161-
pub fn env(&mut self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Self {
162-
self.cmd.env(name, value);
163-
self
164-
}
165-
166-
// Command inspection, output and running helper methods
167-
168-
/// Get the [`Output`][std::process::Output] of the finished `rustc` process.
169-
pub fn output(&mut self) -> Output {
170-
self.cmd.output().unwrap()
171-
}
172-
173-
/// Run the constructed `rustc` command and assert that it is successfully run.
174-
#[track_caller]
175-
pub fn run(&mut self) -> Output {
176-
let caller_location = std::panic::Location::caller();
177-
let caller_line_number = caller_location.line();
178-
179-
let output = self.cmd.output().unwrap();
180-
if !output.status.success() {
181-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
182-
}
183-
output
184-
}
185-
186-
#[track_caller]
187-
pub fn run_fail(&mut self) -> Output {
188-
let caller_location = std::panic::Location::caller();
189-
let caller_line_number = caller_location.line();
190-
191-
let output = self.cmd.output().unwrap();
192-
if output.status.success() {
193-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
194-
}
195-
output
196-
}
197-
198151
#[track_caller]
199152
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
200153
let caller_location = std::panic::Location::caller();
@@ -206,10 +159,4 @@ impl Rustc {
206159
}
207160
output
208161
}
209-
210-
/// Inspect what the underlying [`Command`] is up to the current construction.
211-
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
212-
f(&self.cmd);
213-
self
214-
}
215162
}

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

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
use std::ffi::OsStr;
32
use std::path::Path;
43
use std::process::{Command, Output};
54

@@ -20,6 +19,8 @@ pub struct Rustdoc {
2019
cmd: Command,
2120
}
2221

22+
crate::impl_common_helpers!(Rustdoc);
23+
2324
fn setup_common() -> Command {
2425
let rustdoc = env::var("RUSTDOC").unwrap();
2526
Command::new(rustdoc)
@@ -59,25 +60,6 @@ impl Rustdoc {
5960
self
6061
}
6162

62-
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
63-
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
64-
self.cmd.arg(arg);
65-
self
66-
}
67-
68-
/// Run the build `rustdoc` command and assert that the run is successful.
69-
#[track_caller]
70-
pub fn run(&mut self) -> Output {
71-
let caller_location = std::panic::Location::caller();
72-
let caller_line_number = caller_location.line();
73-
74-
let output = self.cmd.output().unwrap();
75-
if !output.status.success() {
76-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
77-
}
78-
output
79-
}
80-
8163
#[track_caller]
8264
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
8365
let caller_location = std::panic::Location::caller();

0 commit comments

Comments
 (0)