Skip to content

Commit 5aa8cc8

Browse files
committed
Only set cwd for test process, not compiler
1 parent c35030a commit 5aa8cc8

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

src/tools/compiletest/src/procsrv.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
// except according to those terms.
1010

1111
use std::env;
12+
use std::ffi::OsString;
1213
use std::io::prelude::*;
1314
use std::io;
1415
use std::path::PathBuf;
1516
use std::process::{Child, Command, ExitStatus, Output, Stdio};
1617

18+
/// Get the name of the environment variable that holds dynamic library
19+
/// locations
1720
pub fn dylib_env_var() -> &'static str {
1821
if cfg!(windows) {
1922
"PATH"
@@ -26,11 +29,13 @@ pub fn dylib_env_var() -> &'static str {
2629
}
2730
}
2831

32+
/// Add `lib_path` and `aux_path` (if it is `Some`) to the dynamic library
33+
/// env var
2934
fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
3035
// Need to be sure to put both the lib_path and the aux path in the dylib
3136
// search path for the child.
3237
let var = dylib_env_var();
33-
let mut path = env::split_paths(&env::var_os(var).unwrap_or_default())
38+
let mut path = env::split_paths(&env::var_os(var).unwrap_or(OsString::new()))
3439
.collect::<Vec<_>>();
3540
if let Some(p) = aux_path {
3641
path.insert(0, PathBuf::from(p))
@@ -42,12 +47,26 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
4247
cmd.env(var, newpath);
4348
}
4449

50+
/// Represents exit status, stdout and stderr of a completed process
4551
pub struct Result {
4652
pub status: ExitStatus,
4753
pub out: String,
4854
pub err: String,
4955
}
5056

57+
/// Runs a test program
58+
///
59+
/// # Params
60+
/// - `lib_path` Path to search for required library
61+
/// - `prog` command to run
62+
/// - `aux_path` Optional extra path to search for required
63+
/// auxiliary libraries
64+
/// - `args` List of arguments to pass to `prog`
65+
/// - `env` List of environment variables to set, `.0` is variable name,
66+
/// `.1` is value
67+
/// - `input` String to be fed as stdin
68+
/// - `current_dir` Optional working dir to run command in
69+
///
5170
pub fn run(lib_path: &str,
5271
prog: &str,
5372
aux_path: Option<&str>,
@@ -69,7 +88,6 @@ pub fn run(lib_path: &str,
6988
}
7089
if let Some(cwd) = current_dir {
7190
cmd.current_dir(cwd);
72-
panic!("Backtrace");
7391
}
7492

7593
let mut process = cmd.spawn()?;
@@ -85,6 +103,7 @@ pub fn run(lib_path: &str,
85103
})
86104
}
87105

106+
/// Same as `run`, but return process rather than waiting on completion
88107
pub fn run_background(lib_path: &str,
89108
prog: &str,
90109
aux_path: Option<&str>,

src/tools/compiletest/src/runtest.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ impl<'test> TestCx<'test> {
334334
self.props.exec_env.clone(),
335335
self.config.compile_lib_path.to_str().unwrap(),
336336
Some(aux_dir.to_str().unwrap()),
337-
Some(src))
337+
Some(src),
338+
None)
338339
}
339340

340341
fn make_pp_args(&self,
@@ -690,6 +691,7 @@ actual:\n\
690691
environment,
691692
self.config.run_lib_path.to_str().unwrap(),
692693
None,
694+
None,
693695
None);
694696
}
695697
}
@@ -1235,15 +1237,21 @@ actual:\n\
12351237
env,
12361238
self.config.run_lib_path.to_str().unwrap(),
12371239
Some(aux_dir.to_str().unwrap()),
1240+
None,
12381241
None)
12391242
}
12401243
_ => {
12411244
let aux_dir = self.aux_output_dir_name();
1245+
let working_dir =
1246+
Some(self.output_base_name()
1247+
.parent().unwrap()
1248+
.to_str().unwrap().to_owned());
12421249
self.compose_and_run(self.make_run_args(),
12431250
env,
12441251
self.config.run_lib_path.to_str().unwrap(),
12451252
Some(aux_dir.to_str().unwrap()),
1246-
None)
1253+
None,
1254+
working_dir)
12471255
}
12481256
}
12491257
}
@@ -1321,6 +1329,7 @@ actual:\n\
13211329
Vec::new(),
13221330
aux_cx.config.compile_lib_path.to_str().unwrap(),
13231331
Some(aux_dir.to_str().unwrap()),
1332+
None,
13241333
None);
13251334
if !auxres.status.success() {
13261335
self.fatal_proc_rec(
@@ -1334,16 +1343,18 @@ actual:\n\
13341343
self.props.rustc_env.clone(),
13351344
self.config.compile_lib_path.to_str().unwrap(),
13361345
Some(aux_dir.to_str().unwrap()),
1337-
input)
1346+
input,
1347+
None)
13381348
}
13391349

13401350
fn compose_and_run(&self,
13411351
ProcArgs{ args, prog }: ProcArgs,
13421352
procenv: Vec<(String, String)> ,
13431353
lib_path: &str,
13441354
aux_path: Option<&str>,
1345-
input: Option<String>) -> ProcRes {
1346-
self.program_output(lib_path, prog, aux_path, args, procenv, input)
1355+
input: Option<String>,
1356+
working_dir: Option<String>) -> ProcRes {
1357+
self.program_output(lib_path, prog, aux_path, args, procenv, input, working_dir)
13471358
}
13481359

13491360
fn make_compile_args(&self,
@@ -1536,7 +1547,8 @@ actual:\n\
15361547
aux_path: Option<&str>,
15371548
args: Vec<String>,
15381549
env: Vec<(String, String)>,
1539-
input: Option<String>)
1550+
input: Option<String>,
1551+
working_dir: Option<String>)
15401552
-> ProcRes {
15411553
let cmdline =
15421554
{
@@ -1546,8 +1558,6 @@ actual:\n\
15461558
logv(self.config, format!("executing {}", cmdline));
15471559
cmdline
15481560
};
1549-
let working_dir =
1550-
Some(self.output_base_name().parent().unwrap().to_str().unwrap().to_owned());
15511561

15521562
let procsrv::Result {
15531563
out,
@@ -1723,7 +1733,7 @@ actual:\n\
17231733
args: vec![format!("-input-file={}", irfile.to_str().unwrap()),
17241734
self.testpaths.file.to_str().unwrap().to_owned()]
17251735
};
1726-
self.compose_and_run(proc_args, Vec::new(), "", None, None)
1736+
self.compose_and_run(proc_args, Vec::new(), "", None, None, None)
17271737
}
17281738

17291739
fn run_codegen_test(&self) {

0 commit comments

Comments
 (0)