Get the sysroot in a better way (stolen from clippy).

This commit is contained in:
Scott Olson 2016-06-12 22:00:53 -06:00
parent 03745482a2
commit 82daebc5ce

View file

@ -3,26 +3,32 @@ extern crate compiletest_rs as compiletest;
use std::path::PathBuf;
fn run_mode(mode: &'static str) {
// Disable rustc's new error fomatting. It breaks these tests.
std::env::remove_var("RUST_NEW_ERROR_FORMAT");
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
let sysroot = match (home, toolchain) {
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
_ => option_env!("RUST_SYSROOT")
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
.to_owned(),
};
let sysroot_flag = format!("--sysroot {}", sysroot);
// FIXME: read directories in sysroot/lib/rustlib and generate the test targets from that
let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"];
for &target in targets {
let mut config = compiletest::default_config();
config.host_rustcflags = Some(sysroot_flag.clone());
config.mode = mode.parse().ok().expect("Invalid mode");
config.run_lib_path = format!("{}/lib/rustlib/{}/lib", sysroot, target);
config.rustc_path = "target/debug/miri".into();
let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
config.run_lib_path = format!("{}/lib/rustlib/{}/lib", path, target);
let path = format!("--sysroot {}", path);
config.target_rustcflags = Some(path.clone());
config.host_rustcflags = Some(path);
let cfg_mode = mode.parse().ok().expect("Invalid mode");
config.mode = cfg_mode;
config.src_base = PathBuf::from(format!("tests/{}", mode));
config.target = target.to_owned();
// Disable rustc's new error fomatting. It breaks these tests.
std::env::remove_var("RUST_NEW_ERROR_FORMAT");
config.target_rustcflags = Some(sysroot_flag.clone());
compiletest::run_tests(&config);
}
}