Skip to content

Commit 236d580

Browse files
committed
migrate Builder::clear_if_dirty
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 9e92975 commit 236d580

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::core::builder::{
2121
};
2222
use crate::core::config::TargetSelection;
2323
use crate::core::config::flags::{Subcommand, get_completion};
24-
use crate::utils::build_stamp::BuildStamp;
24+
use crate::utils::build_stamp::{self, BuildStamp};
2525
use crate::utils::exec::{BootstrapCommand, command};
2626
use crate::utils::helpers::{
2727
self, LldThreads, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
@@ -545,7 +545,7 @@ impl Step for Miri {
545545
// The mtime of `miri_sysroot` changes when the sysroot gets rebuilt (also see
546546
// <https://github.com/RalfJung/rustc-build-sysroot/commit/10ebcf60b80fe2c3dc765af0ff19fdc0da4b7466>).
547547
// We can hence use that directly as a signal to clear the ui test dir.
548-
builder.clear_if_dirty(&ui_test_dep_dir, &miri_sysroot);
548+
build_stamp::clear_if_dirty(builder, &ui_test_dep_dir, &miri_sysroot);
549549
}
550550

551551
// Run `cargo test`.
@@ -982,7 +982,7 @@ impl Step for RustdocGUI {
982982
let mut cmd = builder.tool_cmd(Tool::RustdocGUITest);
983983

984984
let out_dir = builder.test_out(self.target).join("rustdoc-gui");
985-
builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
985+
build_stamp::clear_if_dirty(builder, &out_dir, &builder.rustdoc(self.compiler));
986986

987987
if let Some(src) = builder.config.src.to_str() {
988988
cmd.arg("--rust-src").arg(src);

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::core::build_steps::tool::SourceType;
77
use crate::core::build_steps::{compile, test};
88
use crate::core::config::SplitDebuginfo;
99
use crate::core::config::flags::Color;
10+
use crate::utils::build_stamp;
1011
use crate::utils::helpers::{
1112
self, LldThreads, add_link_lib_path, check_cfg_arg, linker_args, linker_flags,
1213
};
@@ -454,7 +455,7 @@ impl Builder<'_> {
454455
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
455456
// so we need to explicitly clear out if they've been updated.
456457
for backend in self.codegen_backends(compiler) {
457-
self.clear_if_dirty(&out_dir, &backend);
458+
build_stamp::clear_if_dirty(self, &out_dir, &backend);
458459
}
459460

460461
if cmd_kind == Kind::Doc {
@@ -471,7 +472,7 @@ impl Builder<'_> {
471472
_ => panic!("doc mode {mode:?} not expected"),
472473
};
473474
let rustdoc = self.rustdoc(compiler);
474-
self.clear_if_dirty(&my_out, &rustdoc);
475+
build_stamp::clear_if_dirty(self, &my_out, &rustdoc);
475476
}
476477

477478
let profile_var = |name: &str| {
@@ -763,7 +764,7 @@ impl Builder<'_> {
763764
// Only clear out the directory if we're compiling std; otherwise, we
764765
// should let Cargo take care of things for us (via depdep info)
765766
if !self.config.dry_run() && mode == Mode::Std && cmd_kind == Kind::Build {
766-
self.clear_if_dirty(&out_dir, &self.rustc(compiler));
767+
build_stamp::clear_if_dirty(self, &out_dir, &self.rustc(compiler));
767768
}
768769

769770
let rustdoc_path = match cmd_kind {

src/bootstrap/src/lib.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
use std::cell::{Cell, RefCell};
2020
use std::collections::{BTreeSet, HashMap, HashSet};
2121
use std::fmt::Display;
22-
use std::fs::{self, File};
2322
use std::path::{Path, PathBuf};
2423
use std::process::Command;
2524
use std::sync::OnceLock;
2625
use std::time::SystemTime;
27-
use std::{env, io, str};
26+
use std::{env, fs, io, str};
2827

2928
use build_helper::ci::gha;
3029
use build_helper::exit;
@@ -38,9 +37,7 @@ use crate::core::builder;
3837
use crate::core::builder::{Builder, Kind};
3938
use crate::core::config::{DryRun, LldMode, LlvmLibunwind, Target, TargetSelection, flags};
4039
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command};
41-
use crate::utils::helpers::{
42-
self, dir_is_empty, exe, libdir, mtime, output, set_file_times, symlink_dir,
43-
};
40+
use crate::utils::helpers::{self, dir_is_empty, exe, libdir, output, set_file_times, symlink_dir};
4441

4542
mod core;
4643
mod utils;
@@ -599,24 +596,6 @@ impl Build {
599596
self.metrics.persist(self);
600597
}
601598

602-
/// Clear out `dir` if `input` is newer.
603-
///
604-
/// After this executes, it will also ensure that `dir` exists.
605-
fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
606-
let stamp = BuildStamp::new(dir);
607-
let mut cleared = false;
608-
if mtime(stamp.as_ref()) < mtime(input) {
609-
self.verbose(|| println!("Dirty - {}", dir.display()));
610-
let _ = fs::remove_dir_all(dir);
611-
cleared = true;
612-
} else if stamp.as_ref().exists() {
613-
return cleared;
614-
}
615-
t!(fs::create_dir_all(dir));
616-
t!(File::create(stamp));
617-
cleared
618-
}
619-
620599
fn rust_info(&self) -> &GitInfo {
621600
&self.config.rust_info
622601
}

src/bootstrap/src/utils/build_stamp.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::{fs, io};
33

44
use crate::core::builder::Builder;
55
use crate::core::config::TargetSelection;
6-
use crate::{Compiler, Mode};
6+
use crate::utils::helpers::mtime;
7+
use crate::{Compiler, Mode, t};
78

89
#[derive(Clone)]
910
pub struct BuildStamp {
@@ -74,6 +75,24 @@ impl BuildStamp {
7475
}
7576
}
7677

78+
/// Clear out `dir` if `input` is newer.
79+
///
80+
/// After this executes, it will also ensure that `dir` exists.
81+
pub fn clear_if_dirty(builder: &Builder<'_>, dir: &Path, input: &Path) -> bool {
82+
let stamp = BuildStamp::new(dir);
83+
let mut cleared = false;
84+
if mtime(stamp.as_ref()) < mtime(input) {
85+
builder.verbose(|| println!("Dirty - {}", dir.display()));
86+
let _ = fs::remove_dir_all(dir);
87+
cleared = true;
88+
} else if stamp.as_ref().exists() {
89+
return cleared;
90+
}
91+
t!(fs::create_dir_all(dir));
92+
t!(fs::File::create(stamp));
93+
cleared
94+
}
95+
7796
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
7897
/// compiler for the specified target and backend.
7998
pub fn codegen_backend_stamp(

0 commit comments

Comments
 (0)