Skip to content

Commit

Permalink
Do not apply rustc_workspace_wrapper when getting rustc version
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 20, 2024
1 parent e03ea78 commit 7d75657
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Fix regression [when buggy rustc_workspace_wrapper is set](https://github.com/cuviper/autocfg/issues/58#issuecomment-2067625980), introduced in 0.1.25.

## [0.1.25] - 2024-04-17

- Respect rustc_wrapper and rustc_workspace_wrapper in `Config::{rustc_version, host_triple}` to match the [Cargo's new behavior](https://github.com/rust-lang/cargo/pull/13659). (Other APIs such as `Config::rustc` are already respecting wrappers.)
Expand Down
10 changes: 5 additions & 5 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl ProcessBuilder {
Self { cmd }
}

// /// Adds an argument to pass to the program.
// pub(crate) fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
// self.cmd.arg(arg.as_ref());
// self
// }
/// Adds an argument to pass to the program.
pub(crate) fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
self.cmd.arg(arg.as_ref());
self
}

/// Adds multiple arguments to pass to the program.
pub(crate) fn args(&mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> &mut Self {
Expand Down
26 changes: 20 additions & 6 deletions src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,25 @@ impl ResolveContext {
build_config.rustc.as_ref().map_or_else(|| rustc_path(&self.cargo), PathBuf::from);
let rustc_wrapper = build_config.rustc_wrapper.clone();
let rustc_workspace_wrapper = build_config.rustc_workspace_wrapper.clone();
let mut path_and_args =
let mut rustc =
rustc_wrapper.into_iter().chain(rustc_workspace_wrapper).chain(iter::once(rustc));
PathAndArgs {
path: path_and_args.next().unwrap(),
args: path_and_args.map(PathBuf::into_os_string).collect(),
path: rustc.next().unwrap(),
args: rustc.map(PathBuf::into_os_string).collect(),
}
})
}
pub(crate) fn rustc_for_version(&self, build_config: &easy::BuildConfig) -> PathAndArgs {
// Do not apply RUSTC_WORKSPACE_WRAPPER: https://github.com/cuviper/autocfg/issues/58#issuecomment-2067625980
let rustc =
build_config.rustc.as_ref().map_or_else(|| rustc_path(&self.cargo), PathBuf::from);
let rustc_wrapper = build_config.rustc_wrapper.clone();
let mut rustc = rustc_wrapper.into_iter().chain(iter::once(rustc));
PathAndArgs {
path: rustc.next().unwrap(),
args: rustc.map(PathBuf::into_os_string).collect(),
}
}
pub(crate) fn cargo_home(&self, cwd: &Path) -> &Option<PathBuf> {
self.cargo_home.get_or_init(|| walk::cargo_home_with_cwd(cwd))
}
Expand All @@ -190,7 +201,7 @@ impl ResolveContext {
let host = match cargo_host {
Ok(host) => host,
Err(_) => {
let vv = &verbose_version(self.rustc(build_config).into())?;
let vv = &verbose_version((&self.rustc_for_version(build_config)).into())?;
let r = self.rustc_version.set(rustc_version(vv)?);
debug_assert!(r.is_ok());
host_triple(vv)?
Expand All @@ -206,7 +217,7 @@ impl ResolveContext {
if let Some(&rustc_version) = self.rustc_version.get() {
return Ok(rustc_version);
}
let vv = &verbose_version(self.rustc(build_config).into())?;
let vv = &verbose_version((&self.rustc_for_version(build_config)).into())?;
let rustc_version = rustc_version(vv)?;
Ok(*self.rustc_version.get_or_init(|| rustc_version))
}
Expand Down Expand Up @@ -579,7 +590,10 @@ impl CargoVersion {
}

fn verbose_version(mut rustc_or_cargo: ProcessBuilder) -> Result<(String, ProcessBuilder)> {
rustc_or_cargo.args(["--version", "--verbose"]);
// Use verbose version output because the packagers add extra strings to the normal version output.
// Do not use long flags (--version --verbose) because clippy-deriver doesn't handle them properly.
// -vV is also matched with that cargo internally uses: https://github.com/rust-lang/cargo/blob/14b46ecc62aa671d7477beba237ad9c6a209cf5d/src/cargo/util/rustc.rs#L65
rustc_or_cargo.arg("-vV");
let verbose_version = rustc_or_cargo.read()?;
Ok((verbose_version, rustc_or_cargo))
}
Expand Down

0 comments on commit 7d75657

Please sign in to comment.