about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-07-29 12:30:12 +0000
committerbors <bors@rust-lang.org>2017-07-29 12:30:12 +0000
commitad36f8febad77942b4f1f0e2ba0f422b69276d7b (patch)
tree88762c0feeff2b04d3d99fc489e24a36f4dd9cea
parent91aff5775d3b4a95e2b0c2fe50785f3d28fa3dd8 (diff)
parent8e7849e766730f9e210330485386731cac40d346 (diff)
downloadrust-ad36f8febad77942b4f1f0e2ba0f422b69276d7b.tar.gz
rust-ad36f8febad77942b4f1f0e2ba0f422b69276d7b.zip
Auto merge of #43534 - alexcrichton:cargo-target-runner, r=Mark-Simulacrum
rustbuild: Use Cargo's "target runner"

This commit leverages a relatively new feature in Cargo to execute
cross-compiled tests, the `target.$target.runner` configuration. We configure it
through environment variables in rustbuild and this avoids the need for us to
locate and run tests after-the-fact, instead relying on Cargo to do all that
execution for us.
-rw-r--r--src/bootstrap/check.rs80
-rw-r--r--src/libstd/process.rs15
2 files changed, 26 insertions, 69 deletions
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index b04e4de7744..c65f5a9fb48 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -1050,11 +1050,8 @@ impl Step for Crate {
         dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
         cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
 
-        if target.contains("emscripten") || build.remote_tested(target) {
-            cargo.arg("--no-run");
-        }
-
         cargo.arg("--");
+        cargo.args(&build.flags.cmd.test_args());
 
         if build.config.quiet_tests {
             cargo.arg("--quiet");
@@ -1063,75 +1060,24 @@ impl Step for Crate {
         let _time = util::timeit();
 
         if target.contains("emscripten") {
-            build.run(&mut cargo);
-            krate_emscripten(build, compiler, target, mode);
+            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
+                      build.config.nodejs.as_ref().expect("nodejs not configured"));
         } else if build.remote_tested(target) {
-            build.run(&mut cargo);
-            krate_remote(builder, compiler, target, mode);
-        } else {
-            cargo.args(&build.flags.cmd.test_args());
-            try_run(build, &mut cargo);
-        }
-    }
-}
-
-fn krate_emscripten(build: &Build,
-                    compiler: Compiler,
-                    target: Interned<String>,
-                    mode: Mode) {
-    let out_dir = build.cargo_out(compiler, mode, target);
-    let tests = find_tests(&out_dir.join("deps"), target);
-
-    let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
-    for test in tests {
-        println!("running {}", test.display());
-        let mut cmd = Command::new(nodejs);
-        cmd.arg(&test);
-        if build.config.quiet_tests {
-            cmd.arg("--quiet");
-        }
-        try_run(build, &mut cmd);
-    }
-}
-
-fn krate_remote(builder: &Builder,
-                compiler: Compiler,
-                target: Interned<String>,
-                mode: Mode) {
-    let build = builder.build;
-    let out_dir = build.cargo_out(compiler, mode, target);
-    let tests = find_tests(&out_dir.join("deps"), target);
-
-    let tool = builder.tool_exe(Tool::RemoteTestClient);
-    for test in tests {
-        let mut cmd = Command::new(&tool);
-        cmd.arg("run")
-           .arg(&test);
-        if build.config.quiet_tests {
-            cmd.arg("--quiet");
+            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
+                      format!("{} run",
+                              builder.tool_exe(Tool::RemoteTestClient).display()));
         }
-        cmd.args(&build.flags.cmd.test_args());
-        try_run(build, &mut cmd);
+        try_run(build, &mut cargo);
     }
 }
 
-fn find_tests(dir: &Path, target: Interned<String>) -> Vec<PathBuf> {
-    let mut dst = Vec::new();
-    for e in t!(dir.read_dir()).map(|e| t!(e)) {
-        let file_type = t!(e.file_type());
-        if !file_type.is_file() {
-            continue
-        }
-        let filename = e.file_name().into_string().unwrap();
-        if (target.contains("windows") && filename.ends_with(".exe")) ||
-           (!target.contains("windows") && !filename.contains(".")) ||
-           (target.contains("emscripten") &&
-            filename.ends_with(".js") &&
-            !filename.ends_with(".asm.js")) {
-            dst.push(e.path());
+fn envify(s: &str) -> String {
+    s.chars().map(|c| {
+        match c {
+            '-' => '_',
+            c => c,
         }
-    }
-    dst
+    }).flat_map(|c| c.to_uppercase()).collect()
 }
 
 /// Some test suites are run inside emulators or on remote devices, and most
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index 31809e38239..a872e7eee06 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -1417,8 +1417,19 @@ mod tests {
         let output = String::from_utf8(result.stdout).unwrap();
 
         for (ref k, ref v) in env::vars() {
-            // don't check android RANDOM variables
-            if cfg!(target_os = "android") && *k == "RANDOM" {
+            // Don't check android RANDOM variable which seems to change
+            // whenever the shell runs, and our `env_cmd` is indeed running a
+            // shell which means it'll get a different RANDOM than we probably
+            // have.
+            //
+            // Also skip env vars with `-` in the name on android because, well,
+            // I'm not sure. It appears though that the `set` command above does
+            // not print env vars with `-` in the name, so we just skip them
+            // here as we won't find them in the output. Note that most env vars
+            // use `_` instead of `-`, but our build system sets a few env vars
+            // with `-` in the name.
+            if cfg!(target_os = "android") &&
+               (*k == "RANDOM" || k.contains("-")) {
                 continue
             }