Fix mixing-formats
run-make test
This commit is contained in:
parent
585c898495
commit
3f20c721ce
@ -227,7 +227,7 @@ pub fn set_host_rpath(cmd: &mut Command) {
|
||||
let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR");
|
||||
cmd.env(&ld_lib_path_envvar, {
|
||||
let mut paths = vec![];
|
||||
paths.push(PathBuf::from(env_var("TMPDIR")));
|
||||
paths.push(env::current_dir().unwrap());
|
||||
paths.push(PathBuf::from(env_var("HOST_RPATH_DIR")));
|
||||
for p in env::split_paths(&env_var(&ld_lib_path_envvar)) {
|
||||
paths.push(p.to_path_buf());
|
||||
@ -315,6 +315,28 @@ pub fn assert_not_contains(haystack: &str, needle: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is designed for running commands in a temporary directory
|
||||
/// that is cleared after the function ends.
|
||||
///
|
||||
/// What this function does:
|
||||
/// 1) Creates a temporary directory (`tmpdir`)
|
||||
/// 2) Copies all files from the current directory to `tmpdir`
|
||||
/// 3) Changes the current working directory to `tmpdir`
|
||||
/// 4) Calls `callback`
|
||||
/// 5) Switches working directory back to the original one
|
||||
/// 6) Removes `tmpdir`
|
||||
/// Switch current working directory to a temporary directory
|
||||
pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
|
||||
let original_dir = env::current_dir().unwrap();
|
||||
let tmpdir = original_dir.join("../temporary-directory");
|
||||
copy_dir_all(".", &tmpdir);
|
||||
|
||||
env::set_current_dir(&tmpdir).unwrap();
|
||||
callback();
|
||||
env::set_current_dir(original_dir).unwrap();
|
||||
fs::remove_dir_all(tmpdir).unwrap();
|
||||
}
|
||||
|
||||
/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
|
||||
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
|
||||
///
|
||||
|
@ -1,9 +1,10 @@
|
||||
use std::env;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output, Stdio};
|
||||
|
||||
use crate::{env_var, handle_failed_output, set_host_rpath, tmp_dir};
|
||||
use crate::{env_var, handle_failed_output, set_host_rpath};
|
||||
|
||||
/// Construct a new `rustc` invocation.
|
||||
pub fn rustc() -> Rustc {
|
||||
@ -28,7 +29,7 @@ fn setup_common() -> Command {
|
||||
let rustc = env_var("RUSTC");
|
||||
let mut cmd = Command::new(rustc);
|
||||
set_host_rpath(&mut cmd);
|
||||
cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir());
|
||||
cmd.arg("-L").arg(env::current_dir().unwrap());
|
||||
cmd
|
||||
}
|
||||
|
||||
|
@ -12,31 +12,24 @@
|
||||
|
||||
//@ ignore-cross-compile
|
||||
|
||||
use run_make_support::{rustc, tmp_dir};
|
||||
use run_make_support::{rustc, tmp_dir, run_in_tmpdir};
|
||||
use std::fs;
|
||||
|
||||
fn test_with_teardown(rustc_calls: impl Fn()) {
|
||||
rustc_calls();
|
||||
//FIXME(Oneirical): This should be replaced with the run-make-support fs wrappers.
|
||||
fs::remove_dir_all(tmp_dir()).unwrap();
|
||||
fs::create_dir(tmp_dir()).unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
// Building just baz
|
||||
rustc().crate_type("rlib").input("foo.rs").run();
|
||||
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("bin").input("baz.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("dylib").input("foo.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("rlib").input("bar1.rs").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("bin").input("baz.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
// Building baz2
|
||||
rustc().crate_type("rlib").input("foo.rs").run();
|
||||
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
|
||||
@ -44,42 +37,42 @@ fn main() {
|
||||
rustc().crate_type("dylib").input("baz2.rs").run_fail_assert_exit_code(1);
|
||||
rustc().crate_type("bin").input("baz2.rs").run_fail_assert_exit_code(1);
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("rlib").input("foo.rs").run();
|
||||
rustc().crate_type("rlib").input("bar1.rs").run();
|
||||
rustc().crate_type("dylib").input("bar2.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz2.rs").run();
|
||||
rustc().crate_type("bin").input("baz2.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("rlib").input("foo.rs").run();
|
||||
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("rlib").input("bar2.rs").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz2.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("bin").input("baz2.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("rlib").input("foo.rs").run();
|
||||
rustc().crate_type("rlib").input("bar1.rs").run();
|
||||
rustc().crate_type("rlib").input("bar2.rs").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz2.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("bin").input("baz2.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("dylib").input("foo.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("rlib").input("bar1.rs").run();
|
||||
rustc().crate_type("rlib").input("bar2.rs").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz2.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("bin").input("baz2.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("dylib").input("foo.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("rlib").input("bar2.rs").run();
|
||||
rustc().crate_type("dylib,rlib").input("baz2.rs").run();
|
||||
rustc().crate_type("bin").input("baz2.rs").run();
|
||||
});
|
||||
test_with_teardown(|| {
|
||||
run_in_tmpdir(|| {
|
||||
rustc().crate_type("dylib").input("foo.rs").arg("-Cprefer-dynamic").run();
|
||||
rustc().crate_type("rlib").input("bar1.rs").run();
|
||||
rustc().crate_type("dylib").input("bar2.rs").arg("-Cprefer-dynamic").run();
|
||||
|
Loading…
Reference in New Issue
Block a user