Skip to content

Commit 3d115b9

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

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);
@@ -133,12 +135,6 @@ impl Rustc {
133135
self
134136
}
135137

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

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

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
let mut cmd = Command::new(rustdoc);
@@ -61,25 +62,6 @@ impl Rustdoc {
6162
self
6263
}
6364

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

0 commit comments

Comments
 (0)