Skip to content

Commit

Permalink
compiletest: detect nodejs binary, allow override
Browse files Browse the repository at this point in the history
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 rust-lang#34188.
  • Loading branch information
tari committed Jun 12, 2016
1 parent 5c2a5d4 commit a27667a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

// the path containing LLDB's Python module
pub lldb_python_dir: Option<String>,

Expand Down
23 changes: 23 additions & 0 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub fn parse_config(args: Vec<String> ) -> 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"),
Expand Down Expand Up @@ -179,6 +180,7 @@ pub fn parse_config(args: Vec<String> ) -> 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"),
Expand Down Expand Up @@ -524,3 +526,24 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
}
None
}

fn detect_node() -> Option<String> {
// 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
}

6 changes: 5 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a27667a

Please sign in to comment.