Skip to content

Commit 443afe5

Browse files
committed
Get rid of Deref/DerefMut impl for BootstrapCmd
1 parent a4c24e6 commit 443afe5

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

src/bootstrap/src/core/build_steps/suggest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
1616
.tool_cmd(Tool::SuggestTests)
1717
.env("SUGGEST_TESTS_GIT_REPOSITORY", git_config.git_repository)
1818
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch)
19+
.command
1920
.output()
2021
.expect("failed to run `suggest-tests` tool");
2122

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

+12-9
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,10 @@ impl Miri {
482482
String::new()
483483
} else {
484484
builder.verbose(|| println!("running: {cargo:?}"));
485-
let out =
486-
cargo.output().expect("We already ran `cargo miri setup` before and that worked");
485+
let out = cargo
486+
.command
487+
.output()
488+
.expect("We already ran `cargo miri setup` before and that worked");
487489
assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
488490
// Output is "<sysroot>\n".
489491
let stdout = String::from_utf8(out.stdout)
@@ -2067,7 +2069,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20672069
cmd.arg("--git-repository").arg(git_config.git_repository);
20682070
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);
20692071

2070-
builder.ci_env.force_coloring_in_ci(&mut cmd);
2072+
// FIXME: Move CiEnv back to bootstrap, it is only used here anyway
2073+
builder.ci_env.force_coloring_in_ci(&mut cmd.command);
20712074

20722075
#[cfg(feature = "build-metrics")]
20732076
builder.metrics.begin_test_suite(
@@ -2426,7 +2429,7 @@ impl Step for CrateLibrustc {
24262429
/// Returns whether the test succeeded.
24272430
#[allow(clippy::too_many_arguments)] // FIXME: reduce the number of args and remove this.
24282431
fn run_cargo_test<'a>(
2429-
cargo: impl Into<Command>,
2432+
cargo: impl Into<BootstrapCommand>,
24302433
libtest_args: &[&str],
24312434
crates: &[String],
24322435
primary_crate: &str,
@@ -2457,14 +2460,14 @@ fn run_cargo_test<'a>(
24572460

24582461
/// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
24592462
fn prepare_cargo_test(
2460-
cargo: impl Into<Command>,
2463+
cargo: impl Into<BootstrapCommand>,
24612464
libtest_args: &[&str],
24622465
crates: &[String],
24632466
primary_crate: &str,
24642467
compiler: Compiler,
24652468
target: TargetSelection,
24662469
builder: &Builder<'_>,
2467-
) -> Command {
2470+
) -> BootstrapCommand {
24682471
let mut cargo = cargo.into();
24692472

24702473
// Propegate `--bless` if it has not already been set/unset
@@ -2977,17 +2980,17 @@ impl Step for Bootstrap {
29772980
let compiler = builder.compiler(0, host);
29782981
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host);
29792982

2980-
let mut check_bootstrap = Command::new(builder.python());
2983+
let mut check_bootstrap = BootstrapCommand::new(builder.python());
29812984
check_bootstrap
29822985
.args(["-m", "unittest", "bootstrap_test.py"])
29832986
.env("BUILD_DIR", &builder.out)
29842987
.env("BUILD_PLATFORM", builder.build.build.triple)
29852988
.current_dir(builder.src.join("src/bootstrap/"));
29862989
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
29872990
// Use `python -m unittest` manually if you want to pass arguments.
2988-
builder.run(BootstrapCommand::from(&mut check_bootstrap).delay_failure());
2991+
builder.run(check_bootstrap.delay_failure());
29892992

2990-
let mut cmd = Command::new(&builder.initial_cargo);
2993+
let mut cmd = BootstrapCommand::new(&builder.initial_cargo);
29912994
cmd.arg("test")
29922995
.args(["--features", "bootstrap-self-test"])
29932996
.current_dir(builder.src.join("src/bootstrap"))

src/bootstrap/src/core/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ impl<'a> Builder<'a> {
20852085
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
20862086
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());
20872087

2088-
self.ci_env.force_coloring_in_ci(&mut cargo);
2088+
self.ci_env.force_coloring_in_ci(&mut cargo.command);
20892089

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

src/bootstrap/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ impl Build {
935935
}
936936

937937
/// Adds the `RUST_TEST_THREADS` env var if necessary
938-
fn add_rust_test_threads(&self, cmd: &mut Command) {
938+
fn add_rust_test_threads(&self, cmd: &mut BootstrapCommand) {
939939
if env::var_os("RUST_TEST_THREADS").is_none() {
940940
cmd.env("RUST_TEST_THREADS", self.jobs().to_string());
941941
}

src/bootstrap/src/utils/exec.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::ffi::OsStr;
2-
use std::ops::{Deref, DerefMut};
32
use std::path::Path;
4-
use std::process::{Command, ExitStatus, Output};
3+
use std::process::{Command, CommandArgs, CommandEnvs, ExitStatus, Output};
54

65
/// What should be done when the command fails.
76
#[derive(Debug, Copy, Clone)]
@@ -74,6 +73,19 @@ impl BootstrapCommand {
7473
self
7574
}
7675

76+
pub fn get_envs(&self) -> CommandEnvs<'_> {
77+
self.command.get_envs()
78+
}
79+
80+
pub fn get_args(&self) -> CommandArgs<'_> {
81+
self.command.get_args()
82+
}
83+
84+
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self {
85+
self.command.env_remove(key);
86+
self
87+
}
88+
7789
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
7890
self.command.current_dir(dir);
7991
self
@@ -134,24 +146,6 @@ impl<'a> From<&'a mut BootstrapCommand> for BootstrapCommand {
134146
}
135147
}
136148

137-
/// This implementation is temporary, until all `Command` invocations are migrated to
138-
/// `BootstrapCommand`.
139-
impl Deref for BootstrapCommand {
140-
type Target = Command;
141-
142-
fn deref(&self) -> &Self::Target {
143-
&self.command
144-
}
145-
}
146-
147-
/// This implementation is temporary, until all `Command` invocations are migrated to
148-
/// `BootstrapCommand`.
149-
impl DerefMut for BootstrapCommand {
150-
fn deref_mut(&mut self) -> &mut Self::Target {
151-
&mut self.command
152-
}
153-
}
154-
155149
impl From<Command> for BootstrapCommand {
156150
fn from(command: Command) -> Self {
157151
Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: None }

src/bootstrap/src/utils/helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
8282
}
8383

8484
/// Adds a list of lookup paths to `cmd`'s link library lookup path.
85-
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
85+
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
8686
let mut list = link_lib_path();
8787
for path in path {
8888
list.insert(0, path);
@@ -439,7 +439,7 @@ pub fn linker_flags(
439439
}
440440

441441
pub fn add_rustdoc_cargo_linker_args(
442-
cmd: &mut Command,
442+
cmd: &mut BootstrapCommand,
443443
builder: &Builder<'_>,
444444
target: TargetSelection,
445445
lld_threads: LldThreads,

src/bootstrap/src/utils/render_tests.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
//! to reimplement all the rendering logic in this module because of that.
88
99
use crate::core::builder::Builder;
10+
use crate::utils::exec::BootstrapCommand;
1011
use std::io::{BufRead, BufReader, Read, Write};
11-
use std::process::{ChildStdout, Command, Stdio};
12+
use std::process::{ChildStdout, Stdio};
1213
use std::time::Duration;
1314
use termcolor::{Color, ColorSpec, WriteColor};
1415

1516
const TERSE_TESTS_PER_LINE: usize = 88;
1617

17-
pub(crate) fn add_flags_and_try_run_tests(builder: &Builder<'_>, cmd: &mut Command) -> bool {
18+
pub(crate) fn add_flags_and_try_run_tests(
19+
builder: &Builder<'_>,
20+
cmd: &mut BootstrapCommand,
21+
) -> bool {
1822
if !cmd.get_args().any(|arg| arg == "--") {
1923
cmd.arg("--");
2024
}
@@ -23,7 +27,11 @@ pub(crate) fn add_flags_and_try_run_tests(builder: &Builder<'_>, cmd: &mut Comma
2327
try_run_tests(builder, cmd, false)
2428
}
2529

26-
pub(crate) fn try_run_tests(builder: &Builder<'_>, cmd: &mut Command, stream: bool) -> bool {
30+
pub(crate) fn try_run_tests(
31+
builder: &Builder<'_>,
32+
cmd: &mut BootstrapCommand,
33+
stream: bool,
34+
) -> bool {
2735
if builder.config.dry_run() {
2836
return true;
2937
}
@@ -41,7 +49,8 @@ pub(crate) fn try_run_tests(builder: &Builder<'_>, cmd: &mut Command, stream: bo
4149
}
4250
}
4351

44-
fn run_tests(builder: &Builder<'_>, cmd: &mut Command, stream: bool) -> bool {
52+
fn run_tests(builder: &Builder<'_>, cmd: &mut BootstrapCommand, stream: bool) -> bool {
53+
let cmd = &mut cmd.command;
4554
cmd.stdout(Stdio::piped());
4655

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

0 commit comments

Comments
 (0)