Skip to content

Commit 914e43a

Browse files
committed
extend run-make test runner with some helper functions
1 parent 11853ec commit 914e43a

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

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

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

@@ -86,6 +86,33 @@ impl Rustc {
8686
self
8787
}
8888

89+
/// Specify number of codegen units
90+
pub fn codegen_units(&mut self, units: usize) -> &mut Self {
91+
self.cmd.arg(format!("-Ccodegen-units={units}"));
92+
self
93+
}
94+
95+
/// Specify directory path used for incremental cache
96+
pub fn incremental<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
97+
let mut arg = OsString::new();
98+
arg.push("-Cincremental=");
99+
arg.push(path.as_ref());
100+
self.cmd.arg(&arg);
101+
self
102+
}
103+
104+
/// Specify error format to use
105+
pub fn error_format(&mut self, format: &str) -> &mut Self {
106+
self.cmd.arg(format!("--error-format={format}"));
107+
self
108+
}
109+
110+
/// Specify json messages printed by the compiler
111+
pub fn json(&mut self, items: &str) -> &mut Self {
112+
self.cmd.arg(format!("--json={items}"));
113+
self
114+
}
115+
89116
/// Specify target triple.
90117
pub fn target(&mut self, target: &str) -> &mut Self {
91118
assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces");
@@ -94,13 +121,7 @@ impl Rustc {
94121
}
95122

96123
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
97-
/// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
98-
/// is passed (note the space).
99-
pub fn arg(&mut self, arg: &str) -> &mut Self {
100-
assert!(
101-
!(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")),
102-
"use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
103-
);
124+
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
104125
self.cmd.arg(arg);
105126
self
106127
}
@@ -120,16 +141,7 @@ impl Rustc {
120141
}
121142

122143
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
123-
/// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
124-
/// is passed (note the space).
125-
pub fn args(&mut self, args: &[&str]) -> &mut Self {
126-
for arg in args {
127-
assert!(
128-
!(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")),
129-
"use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
130-
);
131-
}
132-
144+
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Self {
133145
self.cmd.args(args);
134146
self
135147
}

0 commit comments

Comments
 (0)