From f817f1c66072e5830a1a0162a63baa05450df9a3 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 28 Aug 2017 17:32:21 +0200 Subject: [PATCH] Get rid of env var race condition once and for all --- Cargo.lock | 40 ++++++++++++++++++++-------------------- miri/bin/miri.rs | 28 +++++++++++++++++++++------- rustc_tests/src/main.rs | 26 +++++++++++++++++++------- tests/compiletest.rs | 7 +++---- 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e41c301087..00ae333b467 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,24 +21,24 @@ dependencies = [ [[package]] name = "backtrace" version = "0.3.2" -source = "git+https://github.com/alexcrichton/backtrace-rs#3d96a9242ed2096984d15d177f4762b699bee6d4" +source = "git+https://github.com/alexcrichton/backtrace-rs#ac8f8d150ad114b735a020c37762426fc7ad18c4" dependencies = [ "backtrace-sys 0.1.12 (git+https://github.com/alexcrichton/backtrace-rs)", "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "backtrace-sys" version = "0.1.12" -source = "git+https://github.com/alexcrichton/backtrace-rs#3d96a9242ed2096984d15d177f4762b699bee6d4" +source = "git+https://github.com/alexcrichton/backtrace-rs#ac8f8d150ad114b735a020c37762426fc7ad18c4" dependencies = [ - "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -99,7 +99,7 @@ dependencies = [ [[package]] name = "dtoa" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -113,12 +113,12 @@ dependencies = [ [[package]] name = "gcc" -version = "0.3.51" +version = "0.3.53" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "itoa" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -137,7 +137,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.28" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -175,7 +175,7 @@ name = "memchr" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -207,7 +207,7 @@ name = "rand" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -230,7 +230,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc-demangle" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -267,8 +267,8 @@ name = "serde_json" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -353,13 +353,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" "checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" -"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" +"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" -"checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" -"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c" +"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" +"checksum itoa 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f74cf6ca1bdbc28496a2b9798ab7fccc2ca5a42cace95bb2b219577216a5fb90" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb7b49972ee23d8aa1026c365a5b440ba08e35075f18c459980c7395c221ec48" +"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" @@ -370,7 +370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" -"checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" +"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f7726f29ddf9731b17ff113c461e362c381d9d69433f79de4f3dd572488823e9" "checksum serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cf823e706be268e73e7747b147aa31c8f633ab4ba31f115efb57e5047c3a76dd" diff --git a/miri/bin/miri.rs b/miri/bin/miri.rs index 29c47e35570..337a723a40d 100644 --- a/miri/bin/miri.rs +++ b/miri/bin/miri.rs @@ -19,7 +19,11 @@ use rustc::ty::TyCtxt; use syntax::ast::{self, MetaItemKind, NestedMetaItemKind}; use std::path::PathBuf; -struct MiriCompilerCalls(RustcDefaultCalls); +struct MiriCompilerCalls { + default: RustcDefaultCalls, + /// whether we are building for the host + host_target: bool, +} impl<'a> CompilerCalls<'a> for MiriCompilerCalls { fn early_callback( @@ -30,7 +34,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { descriptions: &rustc_errors::registry::Registry, output: ErrorOutputType, ) -> Compilation { - self.0.early_callback( + self.default.early_callback( matches, sopts, cfg, @@ -47,7 +51,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { ofile: &Option, descriptions: &rustc_errors::registry::Registry, ) -> Option<(Input, Option)> { - self.0.no_input( + self.default.no_input( matches, sopts, cfg, @@ -64,17 +68,17 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { odir: &Option, ofile: &Option, ) -> Compilation { - self.0.late_callback(matches, sess, input, odir, ofile) + self.default.late_callback(matches, sess, input, odir, ofile) } fn build_controller( &mut self, sess: &Session, matches: &getopts::Matches, ) -> CompileController<'a> { - let mut control = self.0.build_controller(sess, matches); + let mut control = self.default.build_controller(sess, matches); control.after_hir_lowering.callback = Box::new(after_hir_lowering); control.after_analysis.callback = Box::new(after_analysis); - if std::env::var("MIRI_HOST_TARGET") != Ok("yes".to_owned()) { + if !self.host_target { // only fully compile targets on the host control.after_analysis.stop = Compilation::Stop; } @@ -254,6 +258,16 @@ fn main() { // for auxilary builds in unit tests args.push("-Zalways-encode-mir".to_owned()); + let mut host_target = false; + args.retain(|arg| if arg == "--miri_host_target" { + host_target = true; + false // remove the flag, rustc doesn't know it + } else { + true + }); - rustc_driver::run_compiler(&args, &mut MiriCompilerCalls(RustcDefaultCalls), None, None); + rustc_driver::run_compiler(&args, &mut MiriCompilerCalls { + default: RustcDefaultCalls, + host_target, + }, None, None); } diff --git a/rustc_tests/src/main.rs b/rustc_tests/src/main.rs index 4cff381b332..a44880f1125 100644 --- a/rustc_tests/src/main.rs +++ b/rustc_tests/src/main.rs @@ -20,7 +20,11 @@ use rustc::hir::{self, itemlikevisit}; use rustc::ty::TyCtxt; use syntax::ast; -struct MiriCompilerCalls(RustcDefaultCalls); +struct MiriCompilerCalls { + default: RustcDefaultCalls, + /// whether we are building for the host + host_target: bool, +} impl<'a> CompilerCalls<'a> for MiriCompilerCalls { fn early_callback( @@ -31,7 +35,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { descriptions: &rustc_errors::registry::Registry, output: ErrorOutputType ) -> Compilation { - self.0.early_callback(matches, sopts, cfg, descriptions, output) + self.default.early_callback(matches, sopts, cfg, descriptions, output) } fn no_input( &mut self, @@ -42,7 +46,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { ofile: &Option, descriptions: &rustc_errors::registry::Registry ) -> Option<(Input, Option)> { - self.0.no_input(matches, sopts, cfg, odir, ofile, descriptions) + self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions) } fn late_callback( &mut self, @@ -52,13 +56,13 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { odir: &Option, ofile: &Option ) -> Compilation { - self.0.late_callback(matches, sess, input, odir, ofile) + self.default.late_callback(matches, sess, input, odir, ofile) } fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> CompileController<'a> { - let mut control = self.0.build_controller(sess, matches); + let mut control = self.default.build_controller(sess, matches); control.after_hir_lowering.callback = Box::new(after_hir_lowering); control.after_analysis.callback = Box::new(after_analysis); - if std::env::var("MIRI_HOST_TARGET") != Ok("yes".to_owned()) { + if !self.host_target { // only fully compile targets on the host control.after_analysis.stop = Compilation::Stop; } @@ -139,7 +143,15 @@ fn main() { } let stderr = std::io::stderr(); write!(stderr.lock(), "test [miri-pass] {} ... ", path.display()).unwrap(); - let mut args: Vec = std::env::args().collect(); + let mut host_target = false; + let mut args: Vec = std::env::args().filter(|arg| { + if arg == "--miri_host_target" { + host_target = true; + false // remove the flag, rustc doesn't know it + } else { + true + } + }).collect(); // file to process args.push(path.display().to_string()); diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 7a220ec7627..e7c82367b29 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -126,15 +126,14 @@ fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) { // For now, only validate without optimizations. Inlining breaks validation. flags.push("-Zmir-emit-validate=1".to_owned()); } + if target == host { + flags.push("--miri_host_target".to_owned()); + } config.target_rustcflags = Some(flags.join(" ")); // don't actually execute the final binary, it might be for other targets and we only care // about running miri, not the binary. config.runtool = Some("echo \"\" || ".to_owned()); - if target == host { - std::env::set_var("MIRI_HOST_TARGET", "yes"); - } compiletest::run_tests(&config); - std::env::set_var("MIRI_HOST_TARGET", ""); } fn is_target_dir>(path: P) -> bool {