Skip to content

Commit 229e875

Browse files
committed
Auto merge of #104078 - jyn514:dry-run-progress, r=Mark-Simulacrum
Print "Checking/Building ..." message even when --dry-run is passed Print "Checking/Building ..." message even when --dry-run is passed This makes it a lot easier to understand what commands will be run without having to parse the `-vv` output, which isn't meant to be user facing. I also want to change these messages at some point (#102003) and this change will make it easier to paste a before/after comparison without having to actually build a stage 2 compiler.
2 parents fb6667a + 2437888 commit 229e875

15 files changed

+100
-80
lines changed

src/bootstrap/builder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,11 @@ impl<'a> Builder<'a> {
10741074
let mut hasher = sha2::Sha256::new();
10751075
// FIXME: this is ok for rustfmt (4.1 MB large at time of writing), but it seems memory-intensive for rustc and larger components.
10761076
// Consider using streaming IO instead?
1077-
let contents = if self.config.dry_run { vec![] } else { t!(fs::read(path)) };
1077+
let contents = if self.config.dry_run() { vec![] } else { t!(fs::read(path)) };
10781078
hasher.update(&contents);
10791079
let found = hex::encode(hasher.finalize().as_slice());
10801080
let verified = found == expected;
1081-
if !verified && !self.config.dry_run {
1081+
if !verified && !self.config.dry_run() {
10821082
println!(
10831083
"invalid checksum: \n\
10841084
found: {found}\n\
@@ -1292,7 +1292,7 @@ impl<'a> Builder<'a> {
12921292
/// Note that this returns `None` if LLVM is disabled, or if we're in a
12931293
/// check build or dry-run, where there's no need to build all of LLVM.
12941294
fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
1295-
if self.config.llvm_enabled() && self.kind != Kind::Check && !self.config.dry_run {
1295+
if self.config.llvm_enabled() && self.kind != Kind::Check && !self.config.dry_run() {
12961296
let llvm_config = self.ensure(native::Llvm { target });
12971297
if llvm_config.is_file() {
12981298
return Some(llvm_config);
@@ -1644,7 +1644,7 @@ impl<'a> Builder<'a> {
16441644
//
16451645
// Only clear out the directory if we're compiling std; otherwise, we
16461646
// should let Cargo take care of things for us (via depdep info)
1647-
if !self.config.dry_run && mode == Mode::Std && cmd == "build" {
1647+
if !self.config.dry_run() && mode == Mode::Std && cmd == "build" {
16481648
self.clear_if_dirty(&out_dir, &self.rustc(compiler));
16491649
}
16501650

@@ -2142,7 +2142,7 @@ impl<'a> Builder<'a> {
21422142
(out, dur - deps)
21432143
};
21442144

2145-
if self.config.print_step_timings && !self.config.dry_run {
2145+
if self.config.print_step_timings && !self.config.dry_run() {
21462146
let step_string = format!("{:?}", step);
21472147
let brace_index = step_string.find("{").unwrap_or(0);
21482148
let type_string = type_name::<S>();
@@ -2216,7 +2216,7 @@ impl<'a> Builder<'a> {
22162216
}
22172217

22182218
pub(crate) fn open_in_browser(&self, path: impl AsRef<Path>) {
2219-
if self.config.dry_run || !self.config.cmd.open() {
2219+
if self.config.dry_run() || !self.config.cmd.open() {
22202220
return;
22212221
}
22222222

src/bootstrap/builder/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
use crate::config::{Config, TargetSelection};
2+
use crate::config::{Config, DryRun, TargetSelection};
33
use std::thread;
44

55
fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
@@ -10,7 +10,7 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
1010
let mut config = Config::parse(cmd);
1111
// don't save toolstates
1212
config.save_toolstates = None;
13-
config.dry_run = true;
13+
config.dry_run = DryRun::SelfCheck;
1414

1515
// Ignore most submodules, since we don't need them for a dry run.
1616
// But make sure to check out the `doc` and `rust-analyzer` submodules, since some steps need them

src/bootstrap/compile.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ fn copy_sanitizers(
447447
) -> Vec<PathBuf> {
448448
let runtimes: Vec<native::SanitizerRuntime> = builder.ensure(native::Sanitizers { target });
449449

450-
if builder.config.dry_run {
450+
if builder.config.dry_run() {
451451
return Vec::new();
452452
}
453453

@@ -986,7 +986,7 @@ impl Step for CodegenBackend {
986986
compiler.stage, backend, &compiler.host, target
987987
));
988988
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false);
989-
if builder.config.dry_run {
989+
if builder.config.dry_run() {
990990
return;
991991
}
992992
let mut files = files.into_iter().filter(|f| {
@@ -1034,7 +1034,7 @@ fn copy_codegen_backends_to_sysroot(
10341034
let dst = builder.sysroot_codegen_backends(target_compiler);
10351035
t!(fs::create_dir_all(&dst), dst);
10361036

1037-
if builder.config.dry_run {
1037+
if builder.config.dry_run() {
10381038
return;
10391039
}
10401040

@@ -1332,7 +1332,7 @@ impl Step for Assemble {
13321332

13331333
if builder.config.rust_codegen_backends.contains(&INTERNER.intern_str("llvm")) {
13341334
let llvm_config_bin = builder.ensure(native::Llvm { target: target_compiler.host });
1335-
if !builder.config.dry_run {
1335+
if !builder.config.dry_run() {
13361336
let llvm_bin_dir = output(Command::new(llvm_config_bin).arg("--bindir"));
13371337
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
13381338

@@ -1402,7 +1402,7 @@ pub fn run_cargo(
14021402
additional_target_deps: Vec<(PathBuf, DependencyType)>,
14031403
is_check: bool,
14041404
) -> Vec<PathBuf> {
1405-
if builder.config.dry_run {
1405+
if builder.config.dry_run() {
14061406
return Vec::new();
14071407
}
14081408

@@ -1542,7 +1542,7 @@ pub fn stream_cargo(
15421542
cb: &mut dyn FnMut(CargoMessage<'_>),
15431543
) -> bool {
15441544
let mut cargo = Command::from(cargo);
1545-
if builder.config.dry_run {
1545+
if builder.config.dry_run() {
15461546
return true;
15471547
}
15481548
// Instruct Cargo to give us json messages on stdout, critically leaving

src/bootstrap/config.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ macro_rules! check_ci_llvm {
3333
};
3434
}
3535

36+
#[derive(Clone, Default)]
37+
pub enum DryRun {
38+
/// This isn't a dry run.
39+
#[default]
40+
Disabled,
41+
/// This is a dry run enabled by bootstrap itself, so it can verify that no work is done.
42+
SelfCheck,
43+
/// This is a dry run enabled by the `--dry-run` flag.
44+
UserSelected,
45+
}
46+
3647
/// Global configuration for the entire build and/or bootstrap.
3748
///
3849
/// This structure is derived from a combination of both `config.toml` and
@@ -84,7 +95,7 @@ pub struct Config {
8495
pub jobs: Option<u32>,
8596
pub cmd: Subcommand,
8697
pub incremental: bool,
87-
pub dry_run: bool,
98+
pub dry_run: DryRun,
8899
/// `None` if we shouldn't download CI compiler artifacts, or the commit to download if we should.
89100
#[cfg(not(test))]
90101
download_rustc_commit: Option<String>,
@@ -820,7 +831,7 @@ impl Config {
820831
config.jobs = flags.jobs.map(threads_from_config);
821832
config.cmd = flags.cmd;
822833
config.incremental = flags.incremental;
823-
config.dry_run = flags.dry_run;
834+
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
824835
config.keep_stage = flags.keep_stage;
825836
config.keep_stage_std = flags.keep_stage_std;
826837
config.color = flags.color;
@@ -965,7 +976,7 @@ impl Config {
965976
.unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/cargo"));
966977

967978
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
968-
if config.dry_run {
979+
if config.dry_run() {
969980
let dir = config.out.join("tmp-dry-run");
970981
t!(fs::create_dir_all(&dir));
971982
config.out = dir;
@@ -1372,6 +1383,13 @@ impl Config {
13721383
config
13731384
}
13741385

1386+
pub(crate) fn dry_run(&self) -> bool {
1387+
match self.dry_run {
1388+
DryRun::Disabled => false,
1389+
DryRun::SelfCheck | DryRun::UserSelected => true,
1390+
}
1391+
}
1392+
13751393
/// A git invocation which runs inside the source directory.
13761394
///
13771395
/// Use this rather than `Command::new("git")` in order to support out-of-tree builds.
@@ -1461,7 +1479,7 @@ impl Config {
14611479
/// This is computed on demand since LLVM might have to first be downloaded from CI.
14621480
pub(crate) fn llvm_link_shared(builder: &Builder<'_>) -> bool {
14631481
let mut opt = builder.config.llvm_link_shared.get();
1464-
if opt.is_none() && builder.config.dry_run {
1482+
if opt.is_none() && builder.config.dry_run() {
14651483
// just assume static for now - dynamic linking isn't supported on all platforms
14661484
return false;
14671485
}
@@ -1488,7 +1506,7 @@ impl Config {
14881506
/// Return whether we will use a downloaded, pre-compiled version of rustc, or just build from source.
14891507
pub(crate) fn download_rustc(builder: &Builder<'_>) -> bool {
14901508
static DOWNLOAD_RUSTC: OnceCell<bool> = OnceCell::new();
1491-
if builder.config.dry_run && DOWNLOAD_RUSTC.get().is_none() {
1509+
if builder.config.dry_run() && DOWNLOAD_RUSTC.get().is_none() {
14921510
// avoid trying to actually download the commit
14931511
return false;
14941512
}
@@ -1507,7 +1525,7 @@ impl Config {
15071525
RustfmtState::SystemToolchain(p) | RustfmtState::Downloaded(p) => Some(p.clone()),
15081526
RustfmtState::Unavailable => None,
15091527
r @ RustfmtState::LazyEvaluated => {
1510-
if builder.config.dry_run {
1528+
if builder.config.dry_run() {
15111529
return Some(PathBuf::new());
15121530
}
15131531
let path = maybe_download_rustfmt(builder);

src/bootstrap/dist.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ impl Step for PlainSourceTarball {
945945
.arg(builder.src.join("./src/bootstrap/Cargo.toml"))
946946
.current_dir(&plain_dst_src);
947947

948-
let config = if !builder.config.dry_run {
948+
let config = if !builder.config.dry_run() {
949949
t!(String::from_utf8(t!(cmd.output()).stdout))
950950
} else {
951951
String::new()
@@ -1386,7 +1386,7 @@ impl Step for Extended {
13861386
let etc = builder.src.join("src/etc/installer");
13871387

13881388
// Avoid producing tarballs during a dry run.
1389-
if builder.config.dry_run {
1389+
if builder.config.dry_run() {
13901390
return;
13911391
}
13921392

@@ -1818,7 +1818,7 @@ impl Step for Extended {
18181818
let _time = timeit(builder);
18191819
builder.run(&mut cmd);
18201820

1821-
if !builder.config.dry_run {
1821+
if !builder.config.dry_run() {
18221822
t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
18231823
}
18241824
}
@@ -1882,12 +1882,12 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
18821882
if llvm_dylib_path.exists() {
18831883
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
18841884
}
1885-
!builder.config.dry_run
1885+
!builder.config.dry_run()
18861886
} else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) {
18871887
let mut cmd = Command::new(llvm_config);
18881888
cmd.arg("--libfiles");
18891889
builder.verbose(&format!("running {:?}", cmd));
1890-
let files = if builder.config.dry_run { "".into() } else { output(&mut cmd) };
1890+
let files = if builder.config.dry_run() { "".into() } else { output(&mut cmd) };
18911891
let build_llvm_out = &builder.llvm_out(builder.config.build);
18921892
let target_llvm_out = &builder.llvm_out(target);
18931893
for file in files.trim_end().split(' ') {
@@ -1899,7 +1899,7 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
18991899
};
19001900
builder.install(&file, dst_libdir, 0o644);
19011901
}
1902-
!builder.config.dry_run
1902+
!builder.config.dry_run()
19031903
} else {
19041904
false
19051905
}

src/bootstrap/doc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Step for RustbookSrc {
151151
let index = out.join("index.html");
152152
let rustbook = builder.tool_exe(Tool::Rustbook);
153153
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
154-
if builder.config.dry_run || up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
154+
if builder.config.dry_run() || up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
155155
return;
156156
}
157157
builder.info(&format!("Rustbook ({}) - {}", target, name));
@@ -331,8 +331,8 @@ impl Step for Standalone {
331331
&& up_to_date(&footer, &html)
332332
&& up_to_date(&favicon, &html)
333333
&& up_to_date(&full_toc, &html)
334-
&& (builder.config.dry_run || up_to_date(&version_info, &html))
335-
&& (builder.config.dry_run || up_to_date(&rustdoc, &html))
334+
&& (builder.config.dry_run() || up_to_date(&version_info, &html))
335+
&& (builder.config.dry_run() || up_to_date(&rustdoc, &html))
336336
{
337337
continue;
338338
}
@@ -402,7 +402,7 @@ impl Step for SharedAssets {
402402

403403
let version_input = builder.src.join("src").join("doc").join("version_info.html.template");
404404
let version_info = out.join("version_info.html");
405-
if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
405+
if !builder.config.dry_run() && !up_to_date(&version_input, &version_info) {
406406
let info = t!(fs::read_to_string(&version_input))
407407
.replace("VERSION", &builder.rust_release())
408408
.replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
@@ -900,7 +900,7 @@ impl Step for UnstableBookGen {
900900
}
901901

902902
fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> {
903-
if config.dry_run {
903+
if config.dry_run() {
904904
return Ok(());
905905
}
906906
if let Ok(m) = fs::symlink_metadata(dst) {

src/bootstrap/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct RustfmtConfig {
4343
}
4444

4545
pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
46-
if build.config.dry_run {
46+
if build.config.dry_run() {
4747
return;
4848
}
4949
let mut builder = ignore::types::TypesBuilder::new();

0 commit comments

Comments
 (0)