Skip to content

Commit

Permalink
extend run-make test runner with some helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pacak committed Mar 31, 2024
1 parent 3986132 commit 0ae288a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use object;
pub use wasmparser;

pub use run::{run, run_fail};
pub use rustc::{aux_build, rustc, Rustc};
pub use rustc::{aux_build, rustc, ErrorFormat, Rustc};
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};

/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`).
Expand Down
36 changes: 36 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ fn setup_common() -> Command {
cmd
}

#[derive(Copy, Clone)]
pub enum ErrorFormat {
Human,
Json,
Short,
}

impl Rustc {
// `rustc` invocation constructor methods

Expand Down Expand Up @@ -85,6 +92,35 @@ impl Rustc {
self
}

/// Specify number of codegen units
pub fn codegen_units(&mut self, units: usize) -> &mut Self {
self.cmd.arg(format!("-Ccodegen-units={units}"));
self
}

/// Specify directory path used for incremental cache
pub fn incremental(&mut self, path: impl AsRef<Path>) -> &mut Self {
let path = path.as_ref().to_string_lossy();
self.cmd.arg(format!("-Cincremental={}", path));
self
}

/// Specify error format to use
pub fn error_format(&mut self, format: ErrorFormat) -> &mut Self {
self.cmd.arg(match format {
ErrorFormat::Human => "--error-format=human",
ErrorFormat::Json => "--error-format=json",
ErrorFormat::Short => "--error-format=Short",
});
self
}

/// Specify json messages printed by the compiler
pub fn json(&mut self, items: &str) -> &mut Self {
self.cmd.arg(format!("--json={items}"));
self
}

/// Specify target triple.
pub fn target(&mut self, target: &str) -> &mut Self {
assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces");
Expand Down

0 comments on commit 0ae288a

Please sign in to comment.