run-make-support: use macro to implement common methods
Removes the manual copy-pasta'd implementation of common methods.
This commit is contained in:
parent
b22099d4e0
commit
3d115b9cc9
@ -1,6 +1,6 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
use std::process::Command;
|
||||
|
||||
use crate::{bin_name, cygpath_windows, handle_failed_output, is_msvc, is_windows, tmp_dir, uname};
|
||||
|
||||
@ -19,6 +19,8 @@ pub struct Cc {
|
||||
cmd: Command,
|
||||
}
|
||||
|
||||
crate::impl_common_helpers!(Cc);
|
||||
|
||||
impl Cc {
|
||||
/// Construct a new platform-specific C compiler invocation.
|
||||
///
|
||||
@ -43,22 +45,6 @@ impl Cc {
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a *platform-and-compiler-specific* argument. Please consult the docs for the various
|
||||
/// possible C compilers on the various platforms to check which arguments are legal for
|
||||
/// which compiler.
|
||||
pub fn arg(&mut self, flag: &str) -> &mut Self {
|
||||
self.cmd.arg(flag);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add multiple *platform-and-compiler-specific* arguments. Please consult the docs for the
|
||||
/// various possible C compilers on the various platforms to check which arguments are legal
|
||||
/// for which compiler.
|
||||
pub fn args(&mut self, args: &[&str]) -> &mut Self {
|
||||
self.cmd.args(args);
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify `-o` or `-Fe`/`-Fo` depending on platform/compiler. This assumes that the executable
|
||||
/// is under `$TMPDIR`.
|
||||
pub fn out_exe(&mut self, name: &str) -> &mut Self {
|
||||
@ -85,25 +71,6 @@ impl Cc {
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Run the constructed C invocation command and assert that it is successfully run.
|
||||
#[track_caller]
|
||||
pub fn run(&mut self) -> Output {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
let caller_line_number = caller_location.line();
|
||||
|
||||
let output = self.cmd.output().unwrap();
|
||||
if !output.status.success() {
|
||||
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);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// `EXTRACFLAGS`
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::env;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
@ -21,6 +21,8 @@ pub struct Rustc {
|
||||
cmd: Command,
|
||||
}
|
||||
|
||||
crate::impl_common_helpers!(Rustc);
|
||||
|
||||
fn setup_common() -> Command {
|
||||
let rustc = env::var("RUSTC").unwrap();
|
||||
let mut cmd = Command::new(rustc);
|
||||
@ -133,12 +135,6 @@ impl Rustc {
|
||||
self
|
||||
}
|
||||
|
||||
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
|
||||
self.cmd.arg(arg);
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify the crate type.
|
||||
pub fn crate_type(&mut self, crate_type: &str) -> &mut Self {
|
||||
self.cmd.arg("--crate-type");
|
||||
@ -153,49 +149,6 @@ impl Rustc {
|
||||
self
|
||||
}
|
||||
|
||||
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
|
||||
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Self {
|
||||
self.cmd.args(args);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn env(&mut self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Self {
|
||||
self.cmd.env(name, value);
|
||||
self
|
||||
}
|
||||
|
||||
// Command inspection, output and running helper methods
|
||||
|
||||
/// Get the [`Output`][std::process::Output] of the finished `rustc` process.
|
||||
pub fn output(&mut self) -> Output {
|
||||
self.cmd.output().unwrap()
|
||||
}
|
||||
|
||||
/// Run the constructed `rustc` command and assert that it is successfully run.
|
||||
#[track_caller]
|
||||
pub fn run(&mut self) -> Output {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
let caller_line_number = caller_location.line();
|
||||
|
||||
let output = self.cmd.output().unwrap();
|
||||
if !output.status.success() {
|
||||
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn run_fail(&mut self) -> Output {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
let caller_line_number = caller_location.line();
|
||||
|
||||
let output = self.cmd.output().unwrap();
|
||||
if output.status.success() {
|
||||
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
@ -207,10 +160,4 @@ impl Rustc {
|
||||
}
|
||||
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);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
@ -20,6 +19,8 @@ pub struct Rustdoc {
|
||||
cmd: Command,
|
||||
}
|
||||
|
||||
crate::impl_common_helpers!(Rustdoc);
|
||||
|
||||
fn setup_common() -> Command {
|
||||
let rustdoc = env::var("RUSTDOC").unwrap();
|
||||
let mut cmd = Command::new(rustdoc);
|
||||
@ -61,25 +62,6 @@ impl Rustdoc {
|
||||
self
|
||||
}
|
||||
|
||||
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
|
||||
self.cmd.arg(arg);
|
||||
self
|
||||
}
|
||||
|
||||
/// Run the build `rustdoc` command and assert that the run is successful.
|
||||
#[track_caller]
|
||||
pub fn run(&mut self) -> Output {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
let caller_line_number = caller_location.line();
|
||||
|
||||
let output = self.cmd.output().unwrap();
|
||||
if !output.status.success() {
|
||||
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
|
Loading…
x
Reference in New Issue
Block a user