about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authoronur-ozkan <work@onurozkan.dev>2025-01-09 12:34:03 +0300
committeronur-ozkan <work@onurozkan.dev>2025-01-12 08:43:32 +0300
commita72068adeed913068350327d0a5f6fdbb04e0b4a (patch)
tree49eb626e6de07b150ccc354874675c0acd005786 /src
parent9878d63acbd95c63b4cc2ec4034e4eddbb9cd6bb (diff)
downloadrust-a72068adeed913068350327d0a5f6fdbb04e0b4a.tar.gz
rust-a72068adeed913068350327d0a5f6fdbb04e0b4a.zip
migrate `program_out_of_date` to `BuildStamp::is_up_to_date`
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/src/core/build_steps/format.rs4
-rw-r--r--src/bootstrap/src/core/download.rs29
-rw-r--r--src/bootstrap/src/utils/helpers.rs9
-rw-r--r--src/bootstrap/src/utils/helpers/tests.rs24
4 files changed, 20 insertions, 46 deletions
diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs
index cfabfcf7f22..253a33183bf 100644
--- a/src/bootstrap/src/core/build_steps/format.rs
+++ b/src/bootstrap/src/core/build_steps/format.rs
@@ -13,7 +13,7 @@ use ignore::WalkBuilder;
 use crate::core::builder::Builder;
 use crate::utils::build_stamp::BuildStamp;
 use crate::utils::exec::command;
-use crate::utils::helpers::{self, program_out_of_date, t};
+use crate::utils::helpers::{self, t};
 
 #[must_use]
 enum RustfmtStatus {
@@ -74,7 +74,7 @@ fn verify_rustfmt_version(build: &Builder<'_>) -> bool {
     let Some((version, stamp_file)) = get_rustfmt_version(build) else {
         return false;
     };
-    !program_out_of_date(&stamp_file, &version)
+    stamp_file.with_stamp(version).is_up_to_date()
 }
 
 /// Updates the last rustfmt version used.
diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs
index c18f7c2aae4..78bb5747ffd 100644
--- a/src/bootstrap/src/core/download.rs
+++ b/src/bootstrap/src/core/download.rs
@@ -12,7 +12,7 @@ use xz2::bufread::XzDecoder;
 use crate::core::config::BUILDER_CONFIG_FILENAME;
 use crate::utils::build_stamp::BuildStamp;
 use crate::utils::exec::{BootstrapCommand, command};
-use crate::utils::helpers::{check_run, exe, hex_encode, move_file, program_out_of_date};
+use crate::utils::helpers::{check_run, exe, hex_encode, move_file};
 use crate::{Config, t};
 
 static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
@@ -427,9 +427,10 @@ impl Config {
         let version = &self.stage0_metadata.compiler.version;
         let host = self.build;
 
-        let clippy_stamp = BuildStamp::new(&self.initial_sysroot).with_prefix("clippy");
+        let clippy_stamp =
+            BuildStamp::new(&self.initial_sysroot).with_prefix("clippy").with_stamp(date);
         let cargo_clippy = self.initial_sysroot.join("bin").join(exe("cargo-clippy", host));
-        if cargo_clippy.exists() && !program_out_of_date(&clippy_stamp, date) {
+        if cargo_clippy.exists() && clippy_stamp.is_up_to_date() {
             return cargo_clippy;
         }
 
@@ -440,7 +441,7 @@ impl Config {
             self.fix_bin_or_dylib(&cargo_clippy.with_file_name(exe("clippy-driver", host)));
         }
 
-        self.create(&clippy_stamp, date);
+        t!(clippy_stamp.write());
         cargo_clippy
     }
 
@@ -461,8 +462,8 @@ impl Config {
         let host = self.build;
         let bin_root = self.out.join(host).join("rustfmt");
         let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
-        let rustfmt_stamp = BuildStamp::new(&bin_root).with_prefix("rustfmt");
-        if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {
+        let rustfmt_stamp = BuildStamp::new(&bin_root).with_prefix("rustfmt").with_stamp(channel);
+        if rustfmt_path.exists() && rustfmt_stamp.is_up_to_date() {
             return Some(rustfmt_path);
         }
 
@@ -493,7 +494,7 @@ impl Config {
             }
         }
 
-        self.create(&rustfmt_stamp, &channel);
+        t!(rustfmt_stamp.write());
         Some(rustfmt_path)
     }
 
@@ -568,10 +569,10 @@ impl Config {
     ) {
         let host = self.build.triple;
         let bin_root = self.out.join(host).join(sysroot);
-        let rustc_stamp = BuildStamp::new(&bin_root).with_prefix("rustc");
+        let rustc_stamp = BuildStamp::new(&bin_root).with_prefix("rustc").with_stamp(stamp_key);
 
         if !bin_root.join("bin").join(exe("rustc", self.build)).exists()
-            || program_out_of_date(&rustc_stamp, stamp_key)
+            || !rustc_stamp.is_up_to_date()
         {
             if bin_root.exists() {
                 t!(fs::remove_dir_all(&bin_root));
@@ -602,7 +603,7 @@ impl Config {
                 }
             }
 
-            t!(fs::write(rustc_stamp, stamp_key));
+            t!(rustc_stamp.write());
         }
     }
 
@@ -729,10 +730,10 @@ download-rustc = false
         }
 
         let llvm_root = self.ci_llvm_root();
-        let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm");
         let llvm_sha = detect_llvm_sha(self, self.rust_info.is_managed_git_subrepository());
-        let key = format!("{}{}", llvm_sha, self.llvm_assertions);
-        if program_out_of_date(&llvm_stamp, &key) && !self.dry_run() {
+        let stamp_key = format!("{}{}", llvm_sha, self.llvm_assertions);
+        let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm").with_stamp(stamp_key);
+        if !llvm_stamp.is_up_to_date() && !self.dry_run() {
             self.download_ci_llvm(&llvm_sha);
 
             if self.should_fix_bins_and_dylibs() {
@@ -765,7 +766,7 @@ download-rustc = false
                 }
             }
 
-            t!(fs::write(llvm_stamp, key));
+            t!(llvm_stamp.write());
         }
 
         if let Some(config_path) = &self.config {
diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs
index 55797af4c61..516c314024b 100644
--- a/src/bootstrap/src/utils/helpers.rs
+++ b/src/bootstrap/src/utils/helpers.rs
@@ -13,7 +13,6 @@ use std::{env, fs, io, str};
 use build_helper::util::fail;
 use object::read::archive::ArchiveFile;
 
-use super::build_stamp::BuildStamp;
 use crate::LldMode;
 use crate::core::builder::Builder;
 use crate::core::config::{Config, TargetSelection};
@@ -148,14 +147,6 @@ impl Drop for TimeIt {
     }
 }
 
-/// Used for download caching
-pub(crate) fn program_out_of_date(stamp: &BuildStamp, key: &str) -> bool {
-    if !stamp.as_ref().exists() {
-        return true;
-    }
-    t!(fs::read_to_string(stamp)) != key
-}
-
 /// Symlinks two directories, using junctions on Windows and normal symlinks on
 /// Unix.
 pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<()> {
diff --git a/src/bootstrap/src/utils/helpers/tests.rs b/src/bootstrap/src/utils/helpers/tests.rs
index 611d9f299b7..9030ca2820a 100644
--- a/src/bootstrap/src/utils/helpers/tests.rs
+++ b/src/bootstrap/src/utils/helpers/tests.rs
@@ -1,11 +1,10 @@
-use std::fs::{self, File, remove_file};
+use std::fs::{self, File};
 use std::io::Write;
 use std::path::PathBuf;
 
-use crate::utils::build_stamp::BuildStamp;
 use crate::utils::helpers::{
-    check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, set_file_times,
-    submodule_path_of, symlink_dir,
+    check_cfg_arg, extract_beta_rev, hex_encode, make, set_file_times, submodule_path_of,
+    symlink_dir,
 };
 use crate::{Config, Flags};
 
@@ -59,23 +58,6 @@ fn test_check_cfg_arg() {
 }
 
 #[test]
-fn test_program_out_of_date() {
-    let config =
-        Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
-    let temp_stampfile = BuildStamp::new(&config.tempdir()).with_prefix("tmp");
-
-    File::create(temp_stampfile.as_ref()).unwrap().write_all(b"dummy value").unwrap();
-    assert!(temp_stampfile.as_ref().exists());
-
-    // up-to-date
-    assert!(!program_out_of_date(&temp_stampfile, "dummy value"));
-    // out-of-date
-    assert!(program_out_of_date(&temp_stampfile, ""));
-
-    remove_file(temp_stampfile).unwrap();
-}
-
-#[test]
 fn test_symlink_dir() {
     let config =
         Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));