From f4e329f178a9da9ae4cf844597bfd2261a365ad4 Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Wed, 17 May 2017 16:15:28 +0100 Subject: [PATCH 1/4] Make compiletest set cwd before running js tests --- .../target/wasm32_unknown_emscripten.rs | 2 ++ src/tools/compiletest/src/procsrv.rs | 12 ++++++++++-- src/tools/compiletest/src/runtest.rs | 13 ++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/librustc_back/target/wasm32_unknown_emscripten.rs b/src/librustc_back/target/wasm32_unknown_emscripten.rs index f5fb63038e9..c44095df400 100644 --- a/src/librustc_back/target/wasm32_unknown_emscripten.rs +++ b/src/librustc_back/target/wasm32_unknown_emscripten.rs @@ -18,6 +18,8 @@ pub fn target() -> Result { vec!["-s".to_string(), "BINARYEN=1".to_string(), "-s".to_string(), + "BINARYEN_METHOD='native-wasm,interpret-binary'".to_string(), + "-s".to_string(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()]); let opts = TargetOptions { diff --git a/src/tools/compiletest/src/procsrv.rs b/src/tools/compiletest/src/procsrv.rs index 35f6ed243fe..0ad52de6175 100644 --- a/src/tools/compiletest/src/procsrv.rs +++ b/src/tools/compiletest/src/procsrv.rs @@ -53,7 +53,8 @@ pub fn run(lib_path: &str, aux_path: Option<&str>, args: &[String], env: Vec<(String, String)>, - input: Option) + input: Option, + current_dir: Option) -> io::Result { let mut cmd = Command::new(prog); @@ -66,6 +67,9 @@ pub fn run(lib_path: &str, for (key, val) in env { cmd.env(&key, &val); } + if let Some(cwd) = current_dir { + cmd.current_dir(cwd); + } let mut process = cmd.spawn()?; if let Some(input) = input { @@ -85,7 +89,8 @@ pub fn run_background(lib_path: &str, aux_path: Option<&str>, args: &[String], env: Vec<(String, String)>, - input: Option) + input: Option, + current_dir: Option) -> io::Result { let mut cmd = Command::new(prog); @@ -96,6 +101,9 @@ pub fn run_background(lib_path: &str, for (key, val) in env { cmd.env(&key, &val); } + if let Some(cwd) = current_dir { + cmd.current_dir(cwd); + } let mut process = cmd.spawn()?; if let Some(input) = input { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 45a733d411a..0664525221f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -509,6 +509,7 @@ fn run_debuginfo_gdb_test_no_opt(&self) { self.config.adb_test_dir.clone() ], Vec::new(), + None, None) .expect(&format!("failed to exec `{:?}`", self.config.adb_path)); @@ -521,6 +522,7 @@ fn run_debuginfo_gdb_test_no_opt(&self) { "tcp:5039".to_owned() ], Vec::new(), + None, None) .expect(&format!("failed to exec `{:?}`", self.config.adb_path)); @@ -543,6 +545,7 @@ fn run_debuginfo_gdb_test_no_opt(&self) { adb_arg.clone() ], Vec::new(), + None, None) .expect(&format!("failed to exec `{:?}`", self.config.adb_path)); @@ -579,6 +582,7 @@ fn run_debuginfo_gdb_test_no_opt(&self) { None, &debugger_opts, Vec::new(), + None, None) .expect(&format!("failed to exec `{:?}`", gdb_path)); let cmdline = { @@ -1542,6 +1546,12 @@ fn program_output(&self, logv(self.config, format!("executing {}", cmdline)); cmdline }; + let working_dir = if self.config.target.contains("emscripten") { + Some(self.output_base_name().parent().unwrap().to_str().unwrap().to_owned()) + } else { + None + }; + let procsrv::Result { out, err, @@ -1551,7 +1561,8 @@ fn program_output(&self, aux_path, &args, env, - input).expect(&format!("failed to exec `{}`", prog)); + input, + working_dir).expect(&format!("failed to exec `{}`", prog)); self.dump_output(&out, &err); ProcRes { status: status, From c35030af87a5658929902cde18939145dcaed590 Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Tue, 30 May 2017 17:52:23 +0100 Subject: [PATCH 2/4] Try running all tests using cwd --- src/librustc_back/target/wasm32_unknown_emscripten.rs | 2 -- src/tools/compiletest/src/procsrv.rs | 1 + src/tools/compiletest/src/runtest.rs | 7 ++----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/librustc_back/target/wasm32_unknown_emscripten.rs b/src/librustc_back/target/wasm32_unknown_emscripten.rs index c44095df400..f5fb63038e9 100644 --- a/src/librustc_back/target/wasm32_unknown_emscripten.rs +++ b/src/librustc_back/target/wasm32_unknown_emscripten.rs @@ -18,8 +18,6 @@ pub fn target() -> Result { vec!["-s".to_string(), "BINARYEN=1".to_string(), "-s".to_string(), - "BINARYEN_METHOD='native-wasm,interpret-binary'".to_string(), - "-s".to_string(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()]); let opts = TargetOptions { diff --git a/src/tools/compiletest/src/procsrv.rs b/src/tools/compiletest/src/procsrv.rs index 0ad52de6175..aac2c87e5b3 100644 --- a/src/tools/compiletest/src/procsrv.rs +++ b/src/tools/compiletest/src/procsrv.rs @@ -69,6 +69,7 @@ pub fn run(lib_path: &str, } if let Some(cwd) = current_dir { cmd.current_dir(cwd); + panic!("Backtrace"); } let mut process = cmd.spawn()?; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 0664525221f..e9cab5be317 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1546,11 +1546,8 @@ fn program_output(&self, logv(self.config, format!("executing {}", cmdline)); cmdline }; - let working_dir = if self.config.target.contains("emscripten") { - Some(self.output_base_name().parent().unwrap().to_str().unwrap().to_owned()) - } else { - None - }; + let working_dir = + Some(self.output_base_name().parent().unwrap().to_str().unwrap().to_owned()); let procsrv::Result { out, From 5aa8cc8412862fb15e2961de56e9f7cba691603b Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Mon, 17 Jul 2017 16:54:38 +0100 Subject: [PATCH 3/4] Only set cwd for test process, not compiler --- src/tools/compiletest/src/procsrv.rs | 23 +++++++++++++++++++++-- src/tools/compiletest/src/runtest.rs | 28 +++++++++++++++++++--------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/tools/compiletest/src/procsrv.rs b/src/tools/compiletest/src/procsrv.rs index aac2c87e5b3..b6d89c1f51a 100644 --- a/src/tools/compiletest/src/procsrv.rs +++ b/src/tools/compiletest/src/procsrv.rs @@ -9,11 +9,14 @@ // except according to those terms. use std::env; +use std::ffi::OsString; use std::io::prelude::*; use std::io; use std::path::PathBuf; use std::process::{Child, Command, ExitStatus, Output, Stdio}; +/// Get the name of the environment variable that holds dynamic library +/// locations pub fn dylib_env_var() -> &'static str { if cfg!(windows) { "PATH" @@ -26,11 +29,13 @@ pub fn dylib_env_var() -> &'static str { } } +/// Add `lib_path` and `aux_path` (if it is `Some`) to the dynamic library +/// env var fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) { // Need to be sure to put both the lib_path and the aux path in the dylib // search path for the child. let var = dylib_env_var(); - let mut path = env::split_paths(&env::var_os(var).unwrap_or_default()) + let mut path = env::split_paths(&env::var_os(var).unwrap_or(OsString::new())) .collect::>(); if let Some(p) = aux_path { path.insert(0, PathBuf::from(p)) @@ -42,12 +47,26 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) { cmd.env(var, newpath); } +/// Represents exit status, stdout and stderr of a completed process pub struct Result { pub status: ExitStatus, pub out: String, pub err: String, } +/// Runs a test program +/// +/// # Params +/// - `lib_path` Path to search for required library +/// - `prog` command to run +/// - `aux_path` Optional extra path to search for required +/// auxiliary libraries +/// - `args` List of arguments to pass to `prog` +/// - `env` List of environment variables to set, `.0` is variable name, +/// `.1` is value +/// - `input` String to be fed as stdin +/// - `current_dir` Optional working dir to run command in +/// pub fn run(lib_path: &str, prog: &str, aux_path: Option<&str>, @@ -69,7 +88,6 @@ pub fn run(lib_path: &str, } if let Some(cwd) = current_dir { cmd.current_dir(cwd); - panic!("Backtrace"); } let mut process = cmd.spawn()?; @@ -85,6 +103,7 @@ pub fn run(lib_path: &str, }) } +/// Same as `run`, but return process rather than waiting on completion pub fn run_background(lib_path: &str, prog: &str, aux_path: Option<&str>, diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index e9cab5be317..c6dc78ef505 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -334,7 +334,8 @@ fn print_source(&self, self.props.exec_env.clone(), self.config.compile_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), - Some(src)) + Some(src), + None) } fn make_pp_args(&self, @@ -690,6 +691,7 @@ fn run_debuginfo_gdb_test_no_opt(&self) { environment, self.config.run_lib_path.to_str().unwrap(), None, + None, None); } } @@ -1235,15 +1237,21 @@ fn exec_compiled_test(&self) -> ProcRes { env, self.config.run_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), + None, None) } _ => { let aux_dir = self.aux_output_dir_name(); + let working_dir = + Some(self.output_base_name() + .parent().unwrap() + .to_str().unwrap().to_owned()); self.compose_and_run(self.make_run_args(), env, self.config.run_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), - None) + None, + working_dir) } } } @@ -1321,6 +1329,7 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option) -> Pro Vec::new(), aux_cx.config.compile_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), + None, None); if !auxres.status.success() { self.fatal_proc_rec( @@ -1334,7 +1343,8 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option) -> Pro self.props.rustc_env.clone(), self.config.compile_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), - input) + input, + None) } fn compose_and_run(&self, @@ -1342,8 +1352,9 @@ fn compose_and_run(&self, procenv: Vec<(String, String)> , lib_path: &str, aux_path: Option<&str>, - input: Option) -> ProcRes { - self.program_output(lib_path, prog, aux_path, args, procenv, input) + input: Option, + working_dir: Option) -> ProcRes { + self.program_output(lib_path, prog, aux_path, args, procenv, input, working_dir) } fn make_compile_args(&self, @@ -1536,7 +1547,8 @@ fn program_output(&self, aux_path: Option<&str>, args: Vec, env: Vec<(String, String)>, - input: Option) + input: Option, + working_dir: Option) -> ProcRes { let cmdline = { @@ -1546,8 +1558,6 @@ fn program_output(&self, logv(self.config, format!("executing {}", cmdline)); cmdline }; - let working_dir = - Some(self.output_base_name().parent().unwrap().to_str().unwrap().to_owned()); let procsrv::Result { out, @@ -1723,7 +1733,7 @@ fn check_ir_with_filecheck(&self) -> ProcRes { args: vec![format!("-input-file={}", irfile.to_str().unwrap()), self.testpaths.file.to_str().unwrap().to_owned()] }; - self.compose_and_run(proc_args, Vec::new(), "", None, None) + self.compose_and_run(proc_args, Vec::new(), "", None, None, None) } fn run_codegen_test(&self) { From 874ecdc09faf94d6591a803f7d73f60fd629cd70 Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Wed, 26 Jul 2017 09:43:09 +0100 Subject: [PATCH 4/4] Remove custom node script --- src/ci/docker/disabled/wasm32/Dockerfile | 2 +- src/ci/docker/disabled/wasm32/node.sh | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100755 src/ci/docker/disabled/wasm32/node.sh diff --git a/src/ci/docker/disabled/wasm32/Dockerfile b/src/ci/docker/disabled/wasm32/Dockerfile index 60b15d7afb4..bf9bf77e649 100644 --- a/src/ci/docker/disabled/wasm32/Dockerfile +++ b/src/ci/docker/disabled/wasm32/Dockerfile @@ -19,7 +19,6 @@ RUN sh /scripts/dumb-init.sh # emscripten COPY scripts/emscripten.sh /scripts/ RUN bash /scripts/emscripten.sh -COPY disabled/wasm32/node.sh /usr/local/bin/node COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh @@ -27,6 +26,7 @@ RUN sh /scripts/sccache.sh ENV PATH=$PATH:/emsdk-portable ENV PATH=$PATH:/emsdk-portable/clang/e1.37.13_64bit/ ENV PATH=$PATH:/emsdk-portable/emscripten/1.37.13/ +ENV PATH=$PATH:/node-v8.0.0-linux-x64/bin/ ENV EMSCRIPTEN=/emsdk-portable/emscripten/1.37.13/ ENV BINARYEN_ROOT=/emsdk-portable/clang/e1.37.13_64bit/binaryen/ ENV EM_CONFIG=/emsdk-portable/.emscripten diff --git a/src/ci/docker/disabled/wasm32/node.sh b/src/ci/docker/disabled/wasm32/node.sh deleted file mode 100755 index dfa7f221ffa..00000000000 --- a/src/ci/docker/disabled/wasm32/node.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -path="$(dirname $1)" -file="$(basename $1)" - -shift - -cd "$path" -exec /node-v8.0.0-linux-x64/bin/node "$file" "$@"