Skip to content

Commit

Permalink
[nextest-runner] fix order of cli config and env parsing
Browse files Browse the repository at this point in the history
See inline comments for more.
  • Loading branch information
sunshowers committed Jun 19, 2023
1 parent b62fda5 commit 1b3a820
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 9 additions & 4 deletions nextest-runner/src/cargo_config/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ impl CargoConfigs {
pub(crate) fn discovered_configs(
&self,
) -> impl Iterator<Item = DiscoveredConfig<'_>> + DoubleEndedIterator + '_ {
// TODO/NOTE: https://github.com/rust-lang/cargo/issues/10992 means that currently
// environment variables are privileged over files passed in over the CLI. Once this
// behavior is fixed in upstream cargo, it should also be fixed here.
// NOTE: The order is:
// 1. --config k=v
// 2. --config <file>
// 3. Environment variables
// 4. .cargo/configs.
//
// 2 and 3 used to be reversed in older versions of Rust, but this has been fixed as of Rust
// 1.68 (https://github.com/rust-lang/cargo/pull/11077).
let cli_option_iter = self.cli_configs.iter().filter_map(|(source, config)| {
matches!(source, CargoConfigSource::CliOption)
.then(|| DiscoveredConfig::CliOption { config, source })
Expand All @@ -96,8 +101,8 @@ impl CargoConfigs {
.map(|(source, config)| DiscoveredConfig::File { config, source });

cli_option_iter
.chain(std::iter::once(DiscoveredConfig::Env))
.chain(cli_file_iter)
.chain(std::iter::once(DiscoveredConfig::Env))
.chain(cargo_config_file_iter)
}
}
Expand Down
12 changes: 8 additions & 4 deletions nextest-runner/src/cargo_config/target_triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ mod tests {
})
);

// --config <path> should be parsed correctly. Config files currently come after
// keys and values passed in via --config, and after the environment.
// --config <path> should be parsed correctly. Config files passed in via --config currently
// come after keys and values passed in via --config, and before the environment (this
// didn't used to be the case in older versions of Rust, but is now the case as of Rust 1.68
// with https://github.com/rust-lang/cargo/pull/11077).
assert_eq!(
find_target_triple(&["extra-config.toml"], None, &dir_foo_path, &dir_path),
Some(TargetTriple {
Expand All @@ -320,8 +322,10 @@ mod tests {
&dir_path
),
Some(TargetTriple {
platform: platform("aarch64-pc-windows-msvc"),
source: TargetTripleSource::Env,
platform: platform("aarch64-unknown-linux-gnu"),
source: TargetTripleSource::CargoConfig {
source: CargoConfigSource::File(dir_foo_path.join("extra-config.toml")),
},
})
);
assert_eq!(
Expand Down

0 comments on commit 1b3a820

Please sign in to comment.