Skip to content

Commit 45c48c3

Browse files
committed
run-make-support: use macro to implement common methods
Removes the manual copy-pasta'd implementation of common methods.
1 parent 60c73ec commit 45c48c3

File tree

3 files changed

+10
-114
lines changed

3 files changed

+10
-114
lines changed

Diff for: 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`

Diff for: src/tools/run-make-support/src/rustc.rs

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

66
use crate::{handle_failed_output, tmp_dir};
77

@@ -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);
@@ -120,12 +122,6 @@ impl Rustc {
120122
self
121123
}
122124

123-
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
124-
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
125-
self.cmd.arg(arg);
126-
self
127-
}
128-
129125
/// Specify the crate type.
130126
pub fn crate_type(&mut self, crate_type: &str) -> &mut Self {
131127
self.cmd.arg("--crate-type");
@@ -139,53 +135,4 @@ impl Rustc {
139135
self.cmd.arg(edition);
140136
self
141137
}
142-
143-
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
144-
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Self {
145-
self.cmd.args(args);
146-
self
147-
}
148-
149-
pub fn env(&mut self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Self {
150-
self.cmd.env(name, value);
151-
self
152-
}
153-
154-
// Command inspection, output and running helper methods
155-
156-
/// Get the [`Output`][std::process::Output] of the finished `rustc` process.
157-
pub fn output(&mut self) -> Output {
158-
self.cmd.output().unwrap()
159-
}
160-
161-
/// Run the constructed `rustc` command and assert that it is successfully run.
162-
#[track_caller]
163-
pub fn run(&mut self) -> Output {
164-
let caller_location = std::panic::Location::caller();
165-
let caller_line_number = caller_location.line();
166-
167-
let output = self.cmd.output().unwrap();
168-
if !output.status.success() {
169-
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
170-
}
171-
output
172-
}
173-
174-
#[track_caller]
175-
pub fn run_fail(&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-
/// Inspect what the underlying [`Command`] is up to the current construction.
187-
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
188-
f(&self.cmd);
189-
self
190-
}
191138
}

Diff for: src/tools/run-make-support/src/rustdoc.rs

+3-21
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::handle_failed_output;
66

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

22+
crate::impl_common_helpers!(Rustdoc);
23+
2224
fn setup_common() -> Command {
2325
let rustdoc = env::var("RUSTDOC").unwrap();
2426
Command::new(rustdoc)
@@ -57,24 +59,4 @@ impl Rustdoc {
5759
self.cmd.arg(format!("@{}", path.as_ref().display()));
5860
self
5961
}
60-
61-
/// Fallback argument provider. Consider adding meaningfully named methods instead of using
62-
/// this method.
63-
pub fn arg(&mut self, arg: &str) -> &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-
}
8062
}

0 commit comments

Comments
 (0)