Skip to content

Commit dc88875

Browse files
committed
Allow installing targets & components for CI toolchains
With this change, crater is able to successfully install alternative targets for use with the `+target` modifier syntax. While this works fine for crater, this doesn't work in the more general case as the API allows you to call it multiple times with the assumption being that doing so leaves the existing targets and components around and only installs the newly requested target/component. `rustup-toolchain-install-master` doesn't support this and instead replaces the previous state of the toolchain with the newly requested one. As a result, calling `add_target("foo"); add_target("bar");` leaves only the `bar` target installed. Since installing CI toolchains is gated behind the unstable feature flag, I think this is ok for now.
1 parent b354448 commit dc88875

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/toolchain.rs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,48 @@ impl Toolchain {
315315
RustupAction::Remove => ("remove", "removing"),
316316
};
317317

318-
let thing = thing.to_string();
319-
let action = action.to_string();
318+
let toolchain_name = self.rustup_name();
319+
info!("{log_action_ing} {thing} {name} for toolchain {toolchain_name}");
320320

321321
#[cfg(feature = "unstable-toolchain-ci")]
322-
if let ToolchainInner::CI { .. } = self.inner {
323-
failure::bail!(
324-
"{} {} on CI toolchains is not supported yet",
325-
log_action_ing,
326-
thing
327-
);
322+
if let ToolchainInner::CI(ci) = &self.inner {
323+
if let RustupAction::Remove = action {
324+
failure::bail!("removing {thing} on CI toolchains is not supported yet");
325+
}
326+
327+
let mut args = Vec::with_capacity(6);
328+
if ci.alt {
329+
args.push("--alt");
330+
}
331+
args.extend([
332+
// `-f` is required otherwise rustup-toolchain-install-master will early return
333+
// because the toolchain (but not the new component) is already installed.
334+
"-f",
335+
match thing {
336+
RustupThing::Target => "--targets",
337+
RustupThing::Component => "--component",
338+
},
339+
name,
340+
// We have to pass `--` otherwise the sha is interpreted as a target name.
341+
"--",
342+
&ci.sha,
343+
]);
344+
345+
Command::new(workspace, &RUSTUP_TOOLCHAIN_INSTALL_MASTER)
346+
.args(&args)
347+
.run()
348+
.with_context(|_| {
349+
format!(
350+
"unable to {log_action} {thing} {name} for CI toolchain {toolchain_name} \
351+
via rustup-toolchain-install-master"
352+
)
353+
})?;
354+
355+
return Ok(());
328356
}
329357

330-
let toolchain_name = self.rustup_name();
331-
info!(
332-
"{} {} {} for toolchain {}",
333-
log_action_ing, thing, name, toolchain_name
334-
);
358+
let thing = thing.to_string();
359+
let action = action.to_string();
335360

336361
Command::new(workspace, &RUSTUP)
337362
.args(&[
@@ -344,8 +369,7 @@ impl Toolchain {
344369
.run()
345370
.with_context(|_| {
346371
format!(
347-
"unable to {} {} {} for toolchain {} via rustup",
348-
log_action, thing, name, toolchain_name,
372+
"unable to {log_action} {thing} {name} for toolchain {toolchain_name} via rustup"
349373
)
350374
})?;
351375
Ok(())

0 commit comments

Comments
 (0)