Skip to content

Commit f6d3c02

Browse files
committed
migrate program_out_of_date to BuildStamp::is_up_to_date
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent e9d3ff7 commit f6d3c02

File tree

4 files changed

+22
-48
lines changed

4 files changed

+22
-48
lines changed

Diff for: src/bootstrap/src/core/build_steps/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ignore::WalkBuilder;
1313
use crate::core::builder::Builder;
1414
use crate::utils::build_stamp::BuildStamp;
1515
use crate::utils::exec::command;
16-
use crate::utils::helpers::{self, program_out_of_date, t};
16+
use crate::utils::helpers::{self, t};
1717

1818
#[must_use]
1919
enum RustfmtStatus {
@@ -74,7 +74,7 @@ fn verify_rustfmt_version(build: &Builder<'_>) -> bool {
7474
let Some((version, stamp_file)) = get_rustfmt_version(build) else {
7575
return false;
7676
};
77-
!program_out_of_date(&stamp_file, &version)
77+
stamp_file.with_stamp(version).is_up_to_date()
7878
}
7979

8080
/// Updates the last rustfmt version used.

Diff for: src/bootstrap/src/core/download.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use xz2::bufread::XzDecoder;
1111

1212
use crate::core::config::BUILDER_CONFIG_FILENAME;
1313
use crate::utils::build_stamp::BuildStamp;
14-
use crate::utils::exec::{BootstrapCommand, command};
15-
use crate::utils::helpers::{check_run, exe, hex_encode, move_file, program_out_of_date};
16-
use crate::{Config, t};
14+
use crate::utils::exec::{command, BootstrapCommand};
15+
use crate::utils::helpers::{check_run, exe, hex_encode, move_file};
16+
use crate::{t, Config};
1717

1818
static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
1919

@@ -427,9 +427,10 @@ impl Config {
427427
let version = &self.stage0_metadata.compiler.version;
428428
let host = self.build;
429429

430-
let clippy_stamp = BuildStamp::new(&self.initial_sysroot).with_prefix("clippy");
430+
let clippy_stamp =
431+
BuildStamp::new(&self.initial_sysroot).with_prefix("clippy").with_stamp(date);
431432
let cargo_clippy = self.initial_sysroot.join("bin").join(exe("cargo-clippy", host));
432-
if cargo_clippy.exists() && !program_out_of_date(&clippy_stamp, date) {
433+
if cargo_clippy.exists() && clippy_stamp.is_up_to_date() {
433434
return cargo_clippy;
434435
}
435436

@@ -440,7 +441,7 @@ impl Config {
440441
self.fix_bin_or_dylib(&cargo_clippy.with_file_name(exe("clippy-driver", host)));
441442
}
442443

443-
self.create(&clippy_stamp, date);
444+
t!(clippy_stamp.write());
444445
cargo_clippy
445446
}
446447

@@ -461,8 +462,8 @@ impl Config {
461462
let host = self.build;
462463
let bin_root = self.out.join(host).join("rustfmt");
463464
let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
464-
let rustfmt_stamp = BuildStamp::new(&bin_root).with_prefix("rustfmt");
465-
if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {
465+
let rustfmt_stamp = BuildStamp::new(&bin_root).with_prefix("rustfmt").with_stamp(channel);
466+
if rustfmt_path.exists() && rustfmt_stamp.is_up_to_date() {
466467
return Some(rustfmt_path);
467468
}
468469

@@ -493,7 +494,7 @@ impl Config {
493494
}
494495
}
495496

496-
self.create(&rustfmt_stamp, &channel);
497+
t!(rustfmt_stamp.write());
497498
Some(rustfmt_path)
498499
}
499500

@@ -568,10 +569,10 @@ impl Config {
568569
) {
569570
let host = self.build.triple;
570571
let bin_root = self.out.join(host).join(sysroot);
571-
let rustc_stamp = BuildStamp::new(&bin_root).with_prefix("rustc");
572+
let rustc_stamp = BuildStamp::new(&bin_root).with_prefix("rustc").with_stamp(stamp_key);
572573

573574
if !bin_root.join("bin").join(exe("rustc", self.build)).exists()
574-
|| program_out_of_date(&rustc_stamp, stamp_key)
575+
|| !rustc_stamp.is_up_to_date()
575576
{
576577
if bin_root.exists() {
577578
t!(fs::remove_dir_all(&bin_root));
@@ -602,7 +603,7 @@ impl Config {
602603
}
603604
}
604605

605-
t!(fs::write(rustc_stamp, stamp_key));
606+
t!(rustc_stamp.write());
606607
}
607608
}
608609

@@ -729,10 +730,10 @@ download-rustc = false
729730
}
730731

731732
let llvm_root = self.ci_llvm_root();
732-
let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm");
733733
let llvm_sha = detect_llvm_sha(self, self.rust_info.is_managed_git_subrepository());
734-
let key = format!("{}{}", llvm_sha, self.llvm_assertions);
735-
if program_out_of_date(&llvm_stamp, &key) && !self.dry_run() {
734+
let stamp_key = format!("{}{}", llvm_sha, self.llvm_assertions);
735+
let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm").with_stamp(stamp_key);
736+
if !llvm_stamp.is_up_to_date() && !self.dry_run() {
736737
self.download_ci_llvm(&llvm_sha);
737738

738739
if self.should_fix_bins_and_dylibs() {
@@ -765,7 +766,7 @@ download-rustc = false
765766
}
766767
}
767768

768-
t!(fs::write(llvm_stamp, key));
769+
t!(llvm_stamp.write());
769770
}
770771

771772
if let Some(config_path) = &self.config {

Diff for: src/bootstrap/src/utils/helpers.rs

-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::{env, fs, io, str};
1313
use build_helper::util::fail;
1414
use object::read::archive::ArchiveFile;
1515

16-
use super::build_stamp::BuildStamp;
1716
use crate::LldMode;
1817
use crate::core::builder::Builder;
1918
use crate::core::config::{Config, TargetSelection};
@@ -148,14 +147,6 @@ impl Drop for TimeIt {
148147
}
149148
}
150149

151-
/// Used for download caching
152-
pub(crate) fn program_out_of_date(stamp: &BuildStamp, key: &str) -> bool {
153-
if !stamp.as_ref().exists() {
154-
return true;
155-
}
156-
t!(fs::read_to_string(stamp)) != key
157-
}
158-
159150
/// Symlinks two directories, using junctions on Windows and normal symlinks on
160151
/// Unix.
161152
pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<()> {

Diff for: src/bootstrap/src/utils/helpers/tests.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use std::fs::{self, File, remove_file};
1+
use std::fs::{self, File};
22
use std::io::Write;
33
use std::path::PathBuf;
44

5-
use crate::utils::build_stamp::BuildStamp;
65
use crate::utils::helpers::{
7-
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, set_file_times,
8-
submodule_path_of, symlink_dir,
6+
check_cfg_arg, extract_beta_rev, hex_encode, make, set_file_times, submodule_path_of,
7+
symlink_dir,
98
};
109
use crate::{Config, Flags};
1110

@@ -58,23 +57,6 @@ fn test_check_cfg_arg() {
5857
);
5958
}
6059

61-
#[test]
62-
fn test_program_out_of_date() {
63-
let config =
64-
Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
65-
let temp_stampfile = BuildStamp::new(&config.tempdir()).with_prefix("tmp");
66-
67-
File::create(temp_stampfile.as_ref()).unwrap().write_all(b"dummy value").unwrap();
68-
assert!(temp_stampfile.as_ref().exists());
69-
70-
// up-to-date
71-
assert!(!program_out_of_date(&temp_stampfile, "dummy value"));
72-
// out-of-date
73-
assert!(program_out_of_date(&temp_stampfile, ""));
74-
75-
remove_file(temp_stampfile).unwrap();
76-
}
77-
7860
#[test]
7961
fn test_symlink_dir() {
8062
let config =

0 commit comments

Comments
 (0)