migrate Builder::clear_if_dirty
Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
parent
9e929754b2
commit
236d5804bf
4 changed files with 29 additions and 30 deletions
|
|
@ -21,7 +21,7 @@ use crate::core::builder::{
|
|||
};
|
||||
use crate::core::config::TargetSelection;
|
||||
use crate::core::config::flags::{Subcommand, get_completion};
|
||||
use crate::utils::build_stamp::BuildStamp;
|
||||
use crate::utils::build_stamp::{self, BuildStamp};
|
||||
use crate::utils::exec::{BootstrapCommand, command};
|
||||
use crate::utils::helpers::{
|
||||
self, LldThreads, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
|
||||
|
|
@ -545,7 +545,7 @@ impl Step for Miri {
|
|||
// The mtime of `miri_sysroot` changes when the sysroot gets rebuilt (also see
|
||||
// <https://github.com/RalfJung/rustc-build-sysroot/commit/10ebcf60b80fe2c3dc765af0ff19fdc0da4b7466>).
|
||||
// We can hence use that directly as a signal to clear the ui test dir.
|
||||
builder.clear_if_dirty(&ui_test_dep_dir, &miri_sysroot);
|
||||
build_stamp::clear_if_dirty(builder, &ui_test_dep_dir, &miri_sysroot);
|
||||
}
|
||||
|
||||
// Run `cargo test`.
|
||||
|
|
@ -982,7 +982,7 @@ impl Step for RustdocGUI {
|
|||
let mut cmd = builder.tool_cmd(Tool::RustdocGUITest);
|
||||
|
||||
let out_dir = builder.test_out(self.target).join("rustdoc-gui");
|
||||
builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
|
||||
build_stamp::clear_if_dirty(builder, &out_dir, &builder.rustdoc(self.compiler));
|
||||
|
||||
if let Some(src) = builder.config.src.to_str() {
|
||||
cmd.arg("--rust-src").arg(src);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use crate::core::build_steps::tool::SourceType;
|
|||
use crate::core::build_steps::{compile, test};
|
||||
use crate::core::config::SplitDebuginfo;
|
||||
use crate::core::config::flags::Color;
|
||||
use crate::utils::build_stamp;
|
||||
use crate::utils::helpers::{
|
||||
self, LldThreads, add_link_lib_path, check_cfg_arg, linker_args, linker_flags,
|
||||
};
|
||||
|
|
@ -454,7 +455,7 @@ impl Builder<'_> {
|
|||
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
|
||||
// so we need to explicitly clear out if they've been updated.
|
||||
for backend in self.codegen_backends(compiler) {
|
||||
self.clear_if_dirty(&out_dir, &backend);
|
||||
build_stamp::clear_if_dirty(self, &out_dir, &backend);
|
||||
}
|
||||
|
||||
if cmd_kind == Kind::Doc {
|
||||
|
|
@ -471,7 +472,7 @@ impl Builder<'_> {
|
|||
_ => panic!("doc mode {mode:?} not expected"),
|
||||
};
|
||||
let rustdoc = self.rustdoc(compiler);
|
||||
self.clear_if_dirty(&my_out, &rustdoc);
|
||||
build_stamp::clear_if_dirty(self, &my_out, &rustdoc);
|
||||
}
|
||||
|
||||
let profile_var = |name: &str| {
|
||||
|
|
@ -763,7 +764,7 @@ impl Builder<'_> {
|
|||
// Only clear out the directory if we're compiling std; otherwise, we
|
||||
// should let Cargo take care of things for us (via depdep info)
|
||||
if !self.config.dry_run() && mode == Mode::Std && cmd_kind == Kind::Build {
|
||||
self.clear_if_dirty(&out_dir, &self.rustc(compiler));
|
||||
build_stamp::clear_if_dirty(self, &out_dir, &self.rustc(compiler));
|
||||
}
|
||||
|
||||
let rustdoc_path = match cmd_kind {
|
||||
|
|
|
|||
|
|
@ -19,12 +19,11 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::fmt::Display;
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::sync::OnceLock;
|
||||
use std::time::SystemTime;
|
||||
use std::{env, io, str};
|
||||
use std::{env, fs, io, str};
|
||||
|
||||
use build_helper::ci::gha;
|
||||
use build_helper::exit;
|
||||
|
|
@ -38,9 +37,7 @@ use crate::core::builder;
|
|||
use crate::core::builder::{Builder, Kind};
|
||||
use crate::core::config::{DryRun, LldMode, LlvmLibunwind, Target, TargetSelection, flags};
|
||||
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command};
|
||||
use crate::utils::helpers::{
|
||||
self, dir_is_empty, exe, libdir, mtime, output, set_file_times, symlink_dir,
|
||||
};
|
||||
use crate::utils::helpers::{self, dir_is_empty, exe, libdir, output, set_file_times, symlink_dir};
|
||||
|
||||
mod core;
|
||||
mod utils;
|
||||
|
|
@ -599,24 +596,6 @@ impl Build {
|
|||
self.metrics.persist(self);
|
||||
}
|
||||
|
||||
/// Clear out `dir` if `input` is newer.
|
||||
///
|
||||
/// After this executes, it will also ensure that `dir` exists.
|
||||
fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
|
||||
let stamp = BuildStamp::new(dir);
|
||||
let mut cleared = false;
|
||||
if mtime(stamp.as_ref()) < mtime(input) {
|
||||
self.verbose(|| println!("Dirty - {}", dir.display()));
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
cleared = true;
|
||||
} else if stamp.as_ref().exists() {
|
||||
return cleared;
|
||||
}
|
||||
t!(fs::create_dir_all(dir));
|
||||
t!(File::create(stamp));
|
||||
cleared
|
||||
}
|
||||
|
||||
fn rust_info(&self) -> &GitInfo {
|
||||
&self.config.rust_info
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ use std::{fs, io};
|
|||
|
||||
use crate::core::builder::Builder;
|
||||
use crate::core::config::TargetSelection;
|
||||
use crate::{Compiler, Mode};
|
||||
use crate::utils::helpers::mtime;
|
||||
use crate::{Compiler, Mode, t};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BuildStamp {
|
||||
|
|
@ -74,6 +75,24 @@ impl BuildStamp {
|
|||
}
|
||||
}
|
||||
|
||||
/// Clear out `dir` if `input` is newer.
|
||||
///
|
||||
/// After this executes, it will also ensure that `dir` exists.
|
||||
pub fn clear_if_dirty(builder: &Builder<'_>, dir: &Path, input: &Path) -> bool {
|
||||
let stamp = BuildStamp::new(dir);
|
||||
let mut cleared = false;
|
||||
if mtime(stamp.as_ref()) < mtime(input) {
|
||||
builder.verbose(|| println!("Dirty - {}", dir.display()));
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
cleared = true;
|
||||
} else if stamp.as_ref().exists() {
|
||||
return cleared;
|
||||
}
|
||||
t!(fs::create_dir_all(dir));
|
||||
t!(fs::File::create(stamp));
|
||||
cleared
|
||||
}
|
||||
|
||||
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
|
||||
/// compiler for the specified target and backend.
|
||||
pub fn codegen_backend_stamp(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue