Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiletest: detect nodejs binary, allow override #34236

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may also be expressible as:

let path = env::var_os("PATH").unwrap_or(OsString::new());
env::split_paths(&path).flat_map(|p| {
    vec![p.join("nodejs"), p.join("node"), p.join("nodejs.exe"), p.join("node.exe")]
}).filter(|p| {
    p.exists()
}).next()

It's ok to not really optimize this much but we probably want to also handle windows as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I forgot about Windows so at least the .exe variants should be added. I also considered trying to run each instead of scanning PATH, which would free us from needing to know about a platform's executable suffix so I think that's a better solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm spawning processes here may be a bit expensive here so it may be best to just rely on file detection


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