-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
207 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use std::env; | ||
use std::path::Path; | ||
use std::process::{Command, Output}; | ||
|
||
use crate::{add_host_rpath_env, handle_failed_output}; | ||
|
||
pub fn rustdoc() -> RustdocInvocationBuilder { | ||
RustdocInvocationBuilder::new() | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct RustdocInvocationBuilder { | ||
cmd: Command, | ||
} | ||
|
||
impl RustdocInvocationBuilder { | ||
fn new() -> Self { | ||
let cmd = setup_common_rustdoc_build_cmd(); | ||
Self { cmd } | ||
} | ||
|
||
pub fn arg(&mut self, arg: &str) -> &mut RustdocInvocationBuilder { | ||
self.cmd.arg(arg); | ||
self | ||
} | ||
|
||
pub fn arg_file(&mut self, arg: &Path) -> &mut RustdocInvocationBuilder { | ||
self.cmd.arg(arg); | ||
self | ||
} | ||
|
||
pub fn env(&mut self, key: &str, value: &str) -> &mut RustdocInvocationBuilder { | ||
self.cmd.env(key, value); | ||
self | ||
} | ||
|
||
#[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(); | ||
let caller_line_number = caller_location.line(); | ||
|
||
let output = self.cmd.output().unwrap(); | ||
if output.status.code().unwrap() != code { | ||
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); | ||
} | ||
output | ||
} | ||
} | ||
|
||
fn setup_common_rustdoc_build_cmd() -> Command { | ||
use std::env::VarError; | ||
|
||
let rustdoc = env::var("RUSTDOC").unwrap(); | ||
let target_rpath_dir = env::var("TARGET_RPATH_DIR").unwrap(); | ||
|
||
let mut cmd = Command::new(rustdoc); | ||
|
||
add_host_rpath_env(&mut cmd); | ||
|
||
cmd.arg("-L").arg(target_rpath_dir); | ||
|
||
match std::env::var("RUSTC_LINKER") { | ||
Ok(rustc_linker) => { | ||
cmd.arg(&format!("-Clinker='{rustc_linker}'")); | ||
} | ||
Err(VarError::NotPresent) => {} | ||
Err(VarError::NotUnicode(s)) => { | ||
panic!("RUSTC_LINKER was found, but set to non-unicode string {s:?}"); | ||
} | ||
} | ||
|
||
cmd | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations | ||
|
||
extern crate run_make_support; | ||
|
||
use run_make_support::{rustc, rustdoc, out_dir}; | ||
|
||
fn main() { | ||
rustc() | ||
.arg("success.rs") | ||
.run(); | ||
|
||
rustc() | ||
.arg("--invalid-arg-foo") | ||
.run_fail_assert_exit_code(1); | ||
|
||
rustc() | ||
.arg("compile-error.rs") | ||
.run_fail_assert_exit_code(1); | ||
|
||
rustc() | ||
.env("RUSTC_ICE", "0") | ||
.arg("-Ztreat-err-as-bug") | ||
.arg("compile-error.rs") | ||
.run_fail_assert_exit_code(101); | ||
|
||
std::fs::remove_file(out_dir().join("success")).unwrap(); | ||
|
||
rustdoc() | ||
.arg("success.rs") | ||
.run(); | ||
|
||
rustdoc() | ||
.arg("--invalid-arg-foo") | ||
.run_fail_assert_exit_code(1); | ||
|
||
rustdoc() | ||
.arg("compile-error.rs") | ||
.run_fail_assert_exit_code(1); | ||
|
||
rustdoc() | ||
.arg("lint-failure.rs") | ||
.run_fail_assert_exit_code(1); | ||
} |