From a27667a9e8d18a2960fc1ee477b941665e06992b Mon Sep 17 00:00:00 2001 From: Peter Marheine Date: Sat, 11 Jun 2016 20:03:58 -0600 Subject: [PATCH] compiletest: detect nodejs binary, allow override Rather than hardcoding the binary name for running asmjs tests, attempt to detect the name that should be used; either `nodejs` or `node`. Also add a command-line argument to manually specify what should be used, suppressing probing. Fixes #34188. --- src/tools/compiletest/src/common.rs | 3 +++ src/tools/compiletest/src/main.rs | 23 +++++++++++++++++++++++ src/tools/compiletest/src/runtest.rs | 6 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 5ec62e06e37ae..8f95d794c3767 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -160,6 +160,9 @@ pub struct Config { // status whether android device available or not pub adb_device_status: bool, + // Name with which to invoke Node for asmjs targets + pub node_path: Option, + // the path containing LLDB's Python module pub lldb_python_dir: Option, diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index cc687b532047e..a5157e8407299 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -102,6 +102,7 @@ pub fn parse_config(args: Vec ) -> Config { optopt("", "android-cross-path", "Android NDK standalone path", "PATH"), optopt("", "adb-path", "path to the android debugger", "PATH"), optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"), + optopt("", "nodejs-executable", "path to Node executable for asmjs tests", "PROGRAM"), optopt("", "lldb-python-dir", "directory containing LLDB's python module", "PATH"), reqopt("", "cc", "path to a C compiler", "PATH"), reqopt("", "cxx", "path to a C++ compiler", "PATH"), @@ -179,6 +180,7 @@ pub fn parse_config(args: Vec ) -> Config { opt_str2(matches.opt_str("target")).contains("android") && "(none)" != opt_str2(matches.opt_str("adb-test-dir")) && !opt_str2(matches.opt_str("adb-test-dir")).is_empty(), + node_path: matches.opt_str("nodejs-executable").or_else(detect_node), lldb_python_dir: matches.opt_str("lldb-python-dir"), verbose: matches.opt_present("verbose"), quiet: matches.opt_present("quiet"), @@ -524,3 +526,24 @@ fn extract_lldb_version(full_version_line: Option) -> Option { } None } + +fn detect_node() -> Option { + // Look for `nodejs` or `node` on PATH in that order, returning the name + // of whichever is found. + let path = match env::var_os("PATH") { + Some(x) => x, + None => return None + }; + + for mut dir in env::split_paths(&path) { + for bin in &["nodejs", "node"] { + dir.push(bin); + if dir.exists() { + return Some(bin.to_string()); + } + dir.pop(); + } + } + None +} + diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 953e060465a95..7b37e938244f9 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1405,7 +1405,11 @@ actual:\n\ // If this is emscripten, then run tests under nodejs if self.config.target == "asmjs-unknown-emscripten" { - args.push("nodejs".to_owned()); + if let Some(ref p) = self.config.node_path { + args.push(p.clone()); + } else { + self.fatal("no Node binary found (--nodejs-executable)"); + } } let exe_file = self.make_exe_name();