Skip to content

Commit 39a329c

Browse files
xtask: Fix channel of cargo operations
It seems that some recent change (in cargo? or maybe rustc or rustup) broke the way we run cargo from xtask. The channel arg (e.g. "+nightly") is getting ignored due to the RUSTC env var and other similar vars, which contain full paths to a particular channel's binaries. Fix by unsetting those variables in the child cargo's env.
1 parent 35051a3 commit 39a329c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

xtask/src/cargo.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ impl Cargo {
101101
pub fn command(&self) -> Result<Command> {
102102
let mut cmd = Command::new("cargo");
103103

104+
// Cargo automatically sets some env vars that can prevent the
105+
// channel arg (e.g. "+nightly") from working. Unset them in the
106+
// child's environment.
107+
cmd.env_remove("RUSTC");
108+
cmd.env_remove("RUSTDOC");
109+
104110
if let Some(toolchain) = &self.toolchain {
105111
cmd.arg(&format!("+{}", toolchain));
106112
}
@@ -206,7 +212,7 @@ mod tests {
206212
};
207213
assert_eq!(
208214
command_to_string(&cargo.command().unwrap()),
209-
"RUSTDOCFLAGS=-Dwarnings cargo +nightly doc --package uefi --package xtask --features alloc --open"
215+
"RUSTC= RUSTDOC= RUSTDOCFLAGS=-Dwarnings cargo +nightly doc --package uefi --package xtask --features alloc --open"
210216
);
211217
}
212218
}

xtask/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ fn test_latest_release() -> Result<()> {
173173
// it explicit that it matches the command in `BUILDING.md`.
174174
let mut build_cmd = Command::new("cargo");
175175
build_cmd
176+
.env_remove("RUSTC")
176177
.args(&["+nightly", "build", "--target", "x86_64-unknown-uefi"])
177178
.current_dir(tmp_dir.join("template"));
178179

179180
// Check that the command is indeed in BUILDING.md, then verify the
180181
// build succeeds.
181182
let building_md = include_str!("../../BUILDING.md");
182-
assert!(building_md.contains(&command_to_string(&build_cmd)));
183+
let cmd_str = command_to_string(&build_cmd).replace("RUSTC= ", "");
184+
assert!(building_md.contains(&cmd_str));
183185
run_cmd(build_cmd)
184186
}
185187

0 commit comments

Comments
 (0)