Skip to content

Commit 5571a35

Browse files
committed
Forward env vars to executable
1 parent 93e2f7f commit 5571a35

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
* `OutputConflictHandling` has been replaced by `error_on_output_conflict`, `bless_output_files`,
1919
and `ignore_output_conflict` functions. Custom functions can now be used to implement special
2020
handling of output conflicts.
21+
* `Run` now forwards env vars passed to the compiler to the executable, too
2122

2223
### Removed
2324

src/custom_flags/run.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
33
use bstr::ByteSlice;
44
use spanned::Spanned;
5-
use std::process::{Command, Output};
5+
use std::{path::Path, process::Output};
66

77
use crate::{
88
build_manager::BuildManager, display, per_test_config::TestConfig,
9-
status_emitter::RevisionStyle, Error, Errored, TestOk, TestRun,
9+
status_emitter::RevisionStyle, CommandBuilder, Error, Errored, TestOk, TestRun,
1010
};
1111

1212
use super::Flag;
@@ -35,7 +35,7 @@ impl Flag for Run {
3535
let mut cmd = config.build_command(build_manager)?;
3636
let exit_code = self.exit_code;
3737
let revision = config.extension("run");
38-
let config = TestConfig {
38+
let mut config = TestConfig {
3939
config: config.config.clone(),
4040
comments: config.comments.clone(),
4141
aux_dir: config.aux_dir.clone(),
@@ -57,18 +57,25 @@ impl Flag for Run {
5757
let file = files.next().unwrap();
5858
assert_eq!(files.next(), None);
5959
let file = std::str::from_utf8(file).unwrap();
60-
let exe_file = config.config.out_dir.join(file);
61-
let mut exe = Command::new(&exe_file);
60+
let mut envs = std::mem::take(&mut config.config.program.envs);
61+
config.config.program = CommandBuilder::cmd(config.config.out_dir.join(file));
62+
envs.extend(config.envs().map(|(k, v)| (k.into(), Some(v.into()))));
63+
config.config.program.envs = envs;
64+
65+
let mut exe = config.config.program.build(Path::new(""));
6266
let stdin = config
6367
.status
6468
.path()
6569
.with_extension(format!("{revision}.stdin"));
6670
if stdin.exists() {
6771
exe.stdin(std::fs::File::open(stdin).unwrap());
6872
}
69-
let output = exe
70-
.output()
71-
.unwrap_or_else(|err| panic!("exe file: {}: {err}", display(&exe_file)));
73+
let output = exe.output().unwrap_or_else(|err| {
74+
panic!(
75+
"exe file: {}: {err}",
76+
display(&config.config.program.program)
77+
)
78+
});
7279

7380
if config.aborted() {
7481
return TestRun {

src/per_test_config.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,7 @@ impl TestConfig {
153153
}
154154
}
155155

156-
// False positive in miri, our `map` uses a ref pattern to get the references to the tuple fields instead
157-
// of a reference to a tuple
158-
#[allow(clippy::map_identity)]
159-
cmd.envs(
160-
self.comments()
161-
.flat_map(|r| r.env_vars.iter())
162-
.map(|(k, v)| (k, v)),
163-
);
156+
cmd.envs(self.envs());
164157

165158
Ok(cmd)
166159
}
@@ -426,4 +419,11 @@ impl TestConfig {
426419
pub(crate) fn aborted(&self) -> bool {
427420
self.config.aborted()
428421
}
422+
423+
/// All the environment variables set for the given revision
424+
pub fn envs(&self) -> impl Iterator<Item = (&str, &str)> {
425+
self.comments()
426+
.flat_map(|r| r.env_vars.iter())
427+
.map(|(k, v)| (k.as_ref(), v.as_ref()))
428+
}
429429
}

0 commit comments

Comments
 (0)