Auto merge of #127680 - Kobzol:bootstrap-cmd-refactor-6, r=onur-ozkan · rust-lang/rust@2823cfb (original) (raw)
`@@ -8,6 +8,7 @@
`
8
8
`use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
`
9
9
`use crate::t;
`
10
10
`use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY;
`
``
11
`+
use crate::utils::exec::command;
`
11
12
`use crate::utils::helpers::{self, hex_encode};
`
12
13
`use crate::Config;
`
13
14
`use sha2::Digest;
`
`@@ -16,7 +17,6 @@ use std::fmt::Write as _;
`
16
17
`use std::fs::File;
`
17
18
`use std::io::Write;
`
18
19
`use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR};
`
19
``
`-
use std::process::Command;
`
20
20
`use std::str::FromStr;
`
21
21
`use std::{fmt, fs, io};
`
22
22
``
`@@ -266,20 +266,16 @@ impl Step for Link {
`
266
266
`}
`
267
267
`let stage_path =
`
268
268
`["build", config.build.rustc_target_arg(), "stage1"].join(MAIN_SEPARATOR_STR);
`
269
``
`-
if !rustup_installed() {
`
``
269
`+
if !rustup_installed(builder) {
`
270
270
`` eprintln!("rustup is not installed; cannot link stage1 toolchain");
``
271
271
`} else if stage_dir_exists(&stage_path[..]) && !config.dry_run() {
`
272
``
`-
attempt_toolchain_link(&stage_path[..]);
`
``
272
`+
attempt_toolchain_link(builder, &stage_path[..]);
`
273
273
`}
`
274
274
`}
`
275
275
`}
`
276
276
``
277
``
`-
fn rustup_installed() -> bool {
`
278
``
`-
Command::new("rustup")
`
279
``
`-
.arg("--version")
`
280
``
`-
.stdout(std::process::Stdio::null())
`
281
``
`-
.output()
`
282
``
`-
.map_or(false, |output| output.status.success())
`
``
277
`+
fn rustup_installed(builder: &Builder<'_>) -> bool {
`
``
278
`+
command("rustup").capture_stdout().arg("--version").run(builder).is_success()
`
283
279
`}
`
284
280
``
285
281
`fn stage_dir_exists(stage_path: &str) -> bool {
`
`@@ -289,8 +285,8 @@ fn stage_dir_exists(stage_path: &str) -> bool {
`
289
285
`}
`
290
286
`}
`
291
287
``
292
``
`-
fn attempt_toolchain_link(stage_path: &str) {
`
293
``
`-
if toolchain_is_linked() {
`
``
288
`+
fn attempt_toolchain_link(builder: &Builder<'_>, stage_path: &str) {
`
``
289
`+
if toolchain_is_linked(builder) {
`
294
290
`return;
`
295
291
`}
`
296
292
``
`@@ -301,7 +297,7 @@ fn attempt_toolchain_link(stage_path: &str) {
`
301
297
`return;
`
302
298
`}
`
303
299
``
304
``
`-
if try_link_toolchain(stage_path) {
`
``
300
`+
if try_link_toolchain(builder, stage_path) {
`
305
301
`println!(
`
306
302
`` "Added stage1 rustup toolchain; try cargo +stage1 build on a separate rust project to run a newly-built toolchain"
``
307
303
`);
`
`@@ -315,22 +311,24 @@ fn attempt_toolchain_link(stage_path: &str) {
`
315
311
`}
`
316
312
`}
`
317
313
``
318
``
`-
fn toolchain_is_linked() -> bool {
`
319
``
`-
match Command::new("rustup")
`
``
314
`+
fn toolchain_is_linked(builder: &Builder<'_>) -> bool {
`
``
315
`+
match command("rustup")
`
``
316
`+
.capture_stdout()
`
``
317
`+
.allow_failure()
`
320
318
`.args(["toolchain", "list"])
`
321
``
`-
.stdout(std::process::Stdio::piped())
`
322
``
`-
.output()
`
``
319
`+
.run(builder)
`
``
320
`+
.stdout_if_ok()
`
323
321
`{
`
324
``
`-
Ok(toolchain_list) => {
`
325
``
`-
if !String::from_utf8_lossy(&toolchain_list.stdout).contains("stage1") {
`
``
322
`+
Some(toolchain_list) => {
`
``
323
`+
if !toolchain_list.contains("stage1") {
`
326
324
`return false;
`
327
325
`}
`
328
326
`// The toolchain has already been linked.
`
329
327
`println!(
`
330
328
`` "stage1 toolchain already linked; not attempting to link stage1 toolchain"
``
331
329
`);
`
332
330
`}
`
333
``
`-
Err(_) => {
`
``
331
`+
None => {
`
334
332
`` // In this case, we don't know if the stage1 toolchain has been linked;
``
335
333
`` // but rustup failed, so let's not go any further.
``
336
334
`println!(
`
`@@ -341,12 +339,12 @@ fn toolchain_is_linked() -> bool {
`
341
339
`true
`
342
340
`}
`
343
341
``
344
``
`-
fn try_link_toolchain(stage_path: &str) -> bool {
`
345
``
`-
Command::new("rustup")
`
346
``
`-
.stdout(std::process::Stdio::null())
`
``
342
`+
fn try_link_toolchain(builder: &Builder<'_>, stage_path: &str) -> bool {
`
``
343
`+
command("rustup")
`
``
344
`+
.capture_stdout()
`
347
345
`.args(["toolchain", "link", "stage1", stage_path])
`
348
``
`-
.output()
`
349
``
`-
.map_or(false, |output| output.status.success())
`
``
346
`+
.run(builder)
`
``
347
`+
.is_success()
`
350
348
`}
`
351
349
``
352
350
`fn ensure_stage1_toolchain_placeholder_exists(stage_path: &str) -> bool {
`
`@@ -476,20 +474,18 @@ impl Step for Hook {
`
476
474
`if config.dry_run() {
`
477
475
`return;
`
478
476
`}
`
479
``
`-
t!(install_git_hook_maybe(config));
`
``
477
`+
t!(install_git_hook_maybe(builder, config));
`
480
478
`}
`
481
479
`}
`
482
480
``
483
481
`// install a git hook to automatically run tidy, if they want
`
484
``
`-
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
`
``
482
`+
fn install_git_hook_maybe(builder: &Builder<'_>, config: &Config) -> io::Result<()> {
`
485
483
`let git = helpers::git(Some(&config.src))
`
``
484
`+
.capture()
`
486
485
`.args(["rev-parse", "--git-common-dir"])
`
487
``
`-
.as_command_mut()
`
488
``
`-
.output()
`
489
``
`-
.map(|output| {
`
490
``
`` -
assert!(output.status.success(), "failed to run git");
``
491
``
`-
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
`
492
``
`-
})?;
`
``
486
`+
.run(builder)
`
``
487
`+
.stdout();
`
``
488
`+
let git = PathBuf::from(git.trim());
`
493
489
`let hooks_dir = git.join("hooks");
`
494
490
`let dst = hooks_dir.join("pre-push");
`
495
491
`if dst.exists() {
`