Skip to content

Commit 8e7dd32

Browse files
committed
Make command field of BootstrapCommand private to force access to it through the as_command_mut method
This will be useful for disarming drop bombs when the inner command is accessed.
1 parent 341cebf commit 8e7dd32

File tree

14 files changed

+62
-44
lines changed

14 files changed

+62
-44
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,8 @@ pub fn stream_cargo(
20802080
tail_args: Vec<String>,
20812081
cb: &mut dyn FnMut(CargoMessage<'_>),
20822082
) -> bool {
2083-
let mut cargo = cargo.into_cmd().command;
2083+
let mut cmd = cargo.into_cmd();
2084+
let cargo = cmd.as_command_mut();
20842085
// Instruct Cargo to give us json messages on stdout, critically leaving
20852086
// stderr as piped so we can get those pretty colors.
20862087
let mut message_format = if builder.config.json_output {

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
172172
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
173173
config.src.join("src/version"),
174174
]);
175-
output(&mut rev_list.command).trim().to_owned()
175+
output(rev_list.as_command_mut()).trim().to_owned()
176176
} else if let Some(info) = channel::read_commit_info_file(&config.src) {
177177
info.sha.trim().to_owned()
178178
} else {
@@ -254,7 +254,7 @@ pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
254254
// `true` here.
255255
let llvm_sha = detect_llvm_sha(config, true);
256256
let head_sha =
257-
output(&mut helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").command);
257+
output(helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut());
258258
let head_sha = head_sha.trim();
259259
llvm_sha == head_sha
260260
}

src/bootstrap/src/core/build_steps/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl Step for Hook {
484484
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
485485
let git = helpers::git(Some(&config.src))
486486
.args(["rev-parse", "--git-common-dir"])
487-
.command
487+
.as_command_mut()
488488
.output()
489489
.map(|output| {
490490
assert!(output.status.success(), "failed to run `git`");

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
21052105
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);
21062106

21072107
// FIXME: Move CiEnv back to bootstrap, it is only used here anyway
2108-
builder.ci_env.force_coloring_in_ci(&mut cmd.command);
2108+
builder.ci_env.force_coloring_in_ci(cmd.as_command_mut());
21092109

21102110
#[cfg(feature = "build-metrics")]
21112111
builder.metrics.begin_test_suite(

src/bootstrap/src/core/build_steps/toolstate.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
106106
.arg("--name-status")
107107
.arg("HEAD")
108108
.arg("HEAD^")
109-
.command
109+
.as_command_mut()
110110
.output();
111111
let output = match output {
112112
Ok(o) => o,
@@ -329,7 +329,7 @@ fn checkout_toolstate_repo() {
329329
.arg("--depth=1")
330330
.arg(toolstate_repo())
331331
.arg(TOOLSTATE_DIR)
332-
.command
332+
.as_command_mut()
333333
.status();
334334
let success = match status {
335335
Ok(s) => s.success(),
@@ -343,8 +343,13 @@ fn checkout_toolstate_repo() {
343343
/// Sets up config and authentication for modifying the toolstate repo.
344344
fn prepare_toolstate_config(token: &str) {
345345
fn git_config(key: &str, value: &str) {
346-
let status =
347-
helpers::git(None).arg("config").arg("--global").arg(key).arg(value).command.status();
346+
let status = helpers::git(None)
347+
.arg("config")
348+
.arg("--global")
349+
.arg(key)
350+
.arg(value)
351+
.as_command_mut()
352+
.status();
348353
let success = match status {
349354
Ok(s) => s.success(),
350355
Err(_) => false,
@@ -413,7 +418,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
413418
.arg("-a")
414419
.arg("-m")
415420
.arg(&message)
416-
.command
421+
.as_command_mut()
417422
.status());
418423
if !status.success() {
419424
success = true;
@@ -424,7 +429,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
424429
.arg("push")
425430
.arg("origin")
426431
.arg("master")
427-
.command
432+
.as_command_mut()
428433
.status());
429434
// If we successfully push, exit.
430435
if status.success() {
@@ -437,14 +442,14 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
437442
.arg("fetch")
438443
.arg("origin")
439444
.arg("master")
440-
.command
445+
.as_command_mut()
441446
.status());
442447
assert!(status.success());
443448
let status = t!(helpers::git(Some(Path::new(TOOLSTATE_DIR)))
444449
.arg("reset")
445450
.arg("--hard")
446451
.arg("origin/master")
447-
.command
452+
.as_command_mut()
448453
.status());
449454
assert!(status.success());
450455
}
@@ -460,7 +465,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
460465
/// `publish_toolstate.py` script if the PR passes all tests and is merged to
461466
/// master.
462467
fn publish_test_results(current_toolstate: &ToolstateData) {
463-
let commit = t!(helpers::git(None).arg("rev-parse").arg("HEAD").command.output());
468+
let commit = t!(helpers::git(None).arg("rev-parse").arg("HEAD").as_command_mut().output());
464469
let commit = t!(String::from_utf8(commit.stdout));
465470

466471
let toolstate_serialized = t!(serde_json::to_string(&current_toolstate));

src/bootstrap/src/core/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ impl<'a> Builder<'a> {
21062106
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
21072107
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());
21082108

2109-
self.ci_env.force_coloring_in_ci(&mut cargo.command);
2109+
self.ci_env.force_coloring_in_ci(cargo.as_command_mut());
21102110

21112111
// When we build Rust dylibs they're all intended for intermediate
21122112
// usage, so make sure we pass the -Cprefer-dynamic flag instead of

src/bootstrap/src/core/config/config.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ impl Config {
12591259
cmd.arg("rev-parse").arg("--show-cdup");
12601260
// Discard stderr because we expect this to fail when building from a tarball.
12611261
let output = cmd
1262-
.command
1262+
.as_command_mut()
12631263
.stderr(std::process::Stdio::null())
12641264
.output()
12651265
.ok()
@@ -2142,7 +2142,7 @@ impl Config {
21422142

21432143
let mut git = helpers::git(Some(&self.src));
21442144
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
2145-
output(&mut git.command)
2145+
output(git.as_command_mut())
21462146
}
21472147

21482148
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -2447,7 +2447,7 @@ impl Config {
24472447

24482448
// Handle running from a directory other than the top level
24492449
let top_level = output(
2450-
&mut helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]).command,
2450+
helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]).as_command_mut(),
24512451
);
24522452
let top_level = top_level.trim_end();
24532453
let compiler = format!("{top_level}/compiler/");
@@ -2456,11 +2456,11 @@ impl Config {
24562456
// Look for a version to compare to based on the current commit.
24572457
// Only commits merged by bors will have CI artifacts.
24582458
let merge_base = output(
2459-
&mut helpers::git(Some(&self.src))
2459+
helpers::git(Some(&self.src))
24602460
.arg("rev-list")
24612461
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
24622462
.args(["-n1", "--first-parent", "HEAD"])
2463-
.command,
2463+
.as_command_mut(),
24642464
);
24652465
let commit = merge_base.trim_end();
24662466
if commit.is_empty() {
@@ -2474,7 +2474,7 @@ impl Config {
24742474
// Warn if there were changes to the compiler or standard library since the ancestor commit.
24752475
let has_changes = !t!(helpers::git(Some(&self.src))
24762476
.args(["diff-index", "--quiet", commit, "--", &compiler, &library])
2477-
.command
2477+
.as_command_mut()
24782478
.status())
24792479
.success();
24802480
if has_changes {
@@ -2547,18 +2547,18 @@ impl Config {
25472547
) -> Option<String> {
25482548
// Handle running from a directory other than the top level
25492549
let top_level = output(
2550-
&mut helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]).command,
2550+
helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]).as_command_mut(),
25512551
);
25522552
let top_level = top_level.trim_end();
25532553

25542554
// Look for a version to compare to based on the current commit.
25552555
// Only commits merged by bors will have CI artifacts.
25562556
let merge_base = output(
2557-
&mut helpers::git(Some(&self.src))
2557+
helpers::git(Some(&self.src))
25582558
.arg("rev-list")
25592559
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
25602560
.args(["-n1", "--first-parent", "HEAD"])
2561-
.command,
2561+
.as_command_mut(),
25622562
);
25632563
let commit = merge_base.trim_end();
25642564
if commit.is_empty() {
@@ -2577,7 +2577,7 @@ impl Config {
25772577
git.arg(format!("{top_level}/{path}"));
25782578
}
25792579

2580-
let has_changes = !t!(git.command.status()).success();
2580+
let has_changes = !t!(git.as_command_mut().status()).success();
25812581
if has_changes {
25822582
if if_unchanged {
25832583
if self.verbose > 0 {

src/bootstrap/src/core/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ than building it.
209209

210210
#[cfg(not(feature = "bootstrap-self-test"))]
211211
let stage0_supported_target_list: HashSet<String> = crate::utils::helpers::output(
212-
&mut command(&build.config.initial_rustc).args(["--print", "target-list"]).command,
212+
command(&build.config.initial_rustc).args(["--print", "target-list"]).as_command_mut(),
213213
)
214214
.lines()
215215
.map(|s| s.to_string())

src/bootstrap/src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,14 @@ impl Build {
493493
let submodule_git = || helpers::git(Some(&absolute_path));
494494

495495
// Determine commit checked out in submodule.
496-
let checked_out_hash = output(&mut submodule_git().args(["rev-parse", "HEAD"]).command);
496+
let checked_out_hash = output(submodule_git().args(["rev-parse", "HEAD"]).as_command_mut());
497497
let checked_out_hash = checked_out_hash.trim_end();
498498
// Determine commit that the submodule *should* have.
499499
let recorded = output(
500-
&mut helpers::git(Some(&self.src)).args(["ls-tree", "HEAD"]).arg(relative_path).command,
500+
helpers::git(Some(&self.src))
501+
.args(["ls-tree", "HEAD"])
502+
.arg(relative_path)
503+
.as_command_mut(),
501504
);
502505
let actual_hash = recorded
503506
.split_whitespace()
@@ -522,7 +525,7 @@ impl Build {
522525
let current_branch = {
523526
let output = helpers::git(Some(&self.src))
524527
.args(["symbolic-ref", "--short", "HEAD"])
525-
.command
528+
.as_command_mut()
526529
.stderr(Stdio::inherit())
527530
.output();
528531
let output = t!(output);
@@ -548,7 +551,7 @@ impl Build {
548551
git
549552
};
550553
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.
551-
if !update(true).command.status().map_or(false, |status| status.success()) {
554+
if !update(true).as_command_mut().status().map_or(false, |status| status.success()) {
552555
update(false).run(self);
553556
}
554557

@@ -941,10 +944,12 @@ impl Build {
941944

942945
self.verbose(|| println!("running: {command:?}"));
943946

944-
command.command.stdout(command.stdout.stdio());
945-
command.command.stderr(command.stderr.stdio());
947+
let stdout = command.stdout.stdio();
948+
command.as_command_mut().stdout(stdout);
949+
let stderr = command.stderr.stdio();
950+
command.as_command_mut().stderr(stderr);
946951

947-
let output = command.command.output();
952+
let output = command.as_command_mut().output();
948953

949954
use std::fmt::Write;
950955

@@ -1931,7 +1936,7 @@ fn envify(s: &str) -> String {
19311936
pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
19321937
let diff = helpers::git(Some(dir))
19331938
.arg("diff")
1934-
.command
1939+
.as_command_mut()
19351940
.output()
19361941
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
19371942
.unwrap_or_default();
@@ -1941,7 +1946,7 @@ pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
19411946
.arg("--porcelain")
19421947
.arg("-z")
19431948
.arg("--untracked-files=normal")
1944-
.command
1949+
.as_command_mut()
19451950
.output()
19461951
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
19471952
.unwrap_or_default();

src/bootstrap/src/utils/channel.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl GitInfo {
4545
}
4646

4747
// Make sure git commands work
48-
match helpers::git(Some(dir)).arg("rev-parse").command.output() {
48+
match helpers::git(Some(dir)).arg("rev-parse").as_command_mut().output() {
4949
Ok(ref out) if out.status.success() => {}
5050
_ => return GitInfo::Absent,
5151
}
@@ -63,11 +63,12 @@ impl GitInfo {
6363
.arg("-1")
6464
.arg("--date=short")
6565
.arg("--pretty=format:%cd")
66-
.command,
66+
.as_command_mut(),
6767
);
68-
let ver_hash = output(&mut helpers::git(Some(dir)).arg("rev-parse").arg("HEAD").command);
68+
let ver_hash =
69+
output(helpers::git(Some(dir)).arg("rev-parse").arg("HEAD").as_command_mut());
6970
let short_ver_hash = output(
70-
&mut helpers::git(Some(dir)).arg("rev-parse").arg("--short=9").arg("HEAD").command,
71+
helpers::git(Some(dir)).arg("rev-parse").arg("--short=9").arg("HEAD").as_command_mut(),
7172
);
7273
GitInfo::Present(Some(Info {
7374
commit_date: ver_date.trim().to_string(),

src/bootstrap/src/utils/exec.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl OutputMode {
5555
/// [delay_failure]: BootstrapCommand::delay_failure
5656
#[derive(Debug)]
5757
pub struct BootstrapCommand {
58-
pub command: Command,
58+
command: Command,
5959
pub failure_behavior: BehaviorOnFailure,
6060
pub stdout: OutputMode,
6161
pub stderr: OutputMode,
@@ -145,6 +145,12 @@ impl BootstrapCommand {
145145
pub fn run(&mut self, builder: &Build) -> CommandOutput {
146146
builder.run(self)
147147
}
148+
149+
/// Provides access to the stdlib Command inside.
150+
/// All usages of this function should be eventually removed from bootstrap.
151+
pub fn as_command_mut(&mut self) -> &mut Command {
152+
&mut self.command
153+
}
148154
}
149155

150156
impl From<Command> for BootstrapCommand {

src/bootstrap/src/utils/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
244244

245245
// FIXME: get rid of this function
246246
pub fn check_run(cmd: &mut BootstrapCommand, print_cmd_on_fail: bool) -> bool {
247-
let status = match cmd.command.status() {
247+
let status = match cmd.as_command_mut().status() {
248248
Ok(status) => status,
249249
Err(e) => {
250250
println!("failed to execute command: {cmd:?}\nERROR: {e}");

src/bootstrap/src/utils/render_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn try_run_tests(
5050
}
5151

5252
fn run_tests(builder: &Builder<'_>, cmd: &mut BootstrapCommand, stream: bool) -> bool {
53-
let cmd = &mut cmd.command;
53+
let cmd = cmd.as_command_mut();
5454
cmd.stdout(Stdio::piped());
5555

5656
builder.verbose(|| println!("running: {cmd:?}"));

src/bootstrap/src/utils/tarball.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ impl<'a> Tarball<'a> {
370370
if self.builder.rust_info().is_managed_git_subrepository() {
371371
// %ct means committer date
372372
let timestamp = helpers::output(
373-
&mut helpers::git(Some(&self.builder.src))
373+
helpers::git(Some(&self.builder.src))
374374
.arg("log")
375375
.arg("-1")
376376
.arg("--format=%ct")
377-
.command,
377+
.as_command_mut(),
378378
);
379379
cmd.args(["--override-file-mtime", timestamp.trim()]);
380380
}

0 commit comments

Comments
 (0)