Rollup merge of #127697 - onur-ozkan:use-std-filetimes, r=Kobzol

use std for file mtime and atime modifications

Since 1.75 std provides an interface to set access and modified times on files. This change replaces the external dependency previously used for these operations with the corresponding std functions.
This commit is contained in:
Matthias Krüger 2024-07-14 10:05:21 +02:00 committed by GitHub
commit bef29c0a8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 11 deletions

View File

@ -48,7 +48,6 @@ dependencies = [
"clap_complete", "clap_complete",
"cmake", "cmake",
"fd-lock", "fd-lock",
"filetime",
"home", "home",
"ignore", "ignore",
"junction", "junction",

View File

@ -44,7 +44,6 @@ build_helper = { path = "../tools/build_helper" }
clap = { version = "4.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] } clap = { version = "4.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
clap_complete = "4.4" clap_complete = "4.4"
fd-lock = "4.0" fd-lock = "4.0"
filetime = "0.2"
home = "0.5" home = "0.5"
ignore = "0.4" ignore = "0.4"
libc = "0.2" libc = "0.2"

View File

@ -33,7 +33,6 @@ use crate::utils::helpers::{
}; };
use crate::LLVM_TOOLS; use crate::LLVM_TOOLS;
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode}; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
use filetime::FileTime;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Std { pub struct Std {
@ -2161,9 +2160,11 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
return; return;
} }
let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap()); let previous_mtime = t!(t!(path.metadata()).modified());
command("strip").capture().arg("--strip-debug").arg(path).run(builder); command("strip").capture().arg("--strip-debug").arg(path).run(builder);
let file = t!(fs::File::open(path));
// After running `strip`, we have to set the file modification time to what it was before, // After running `strip`, we have to set the file modification time to what it was before,
// otherwise we risk Cargo invalidating its fingerprint and rebuilding the world next time // otherwise we risk Cargo invalidating its fingerprint and rebuilding the world next time
// bootstrap is invoked. // bootstrap is invoked.
@ -2176,5 +2177,5 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
// In the second invocation of bootstrap, Cargo will see that the mtime of librustc_driver.so // In the second invocation of bootstrap, Cargo will see that the mtime of librustc_driver.so
// is greater than the mtime of rustc-main, and will rebuild rustc-main. That will then cause // is greater than the mtime of rustc-main, and will rebuild rustc-main. That will then cause
// everything else (standard library, future stages...) to be rebuilt. // everything else (standard library, future stages...) to be rebuilt.
t!(filetime::set_file_mtime(path, previous_mtime)); t!(file.set_modified(previous_mtime));
} }

View File

@ -702,9 +702,13 @@ download-rustc = false
// time `rustc_llvm` build script ran. However, the timestamps of the // time `rustc_llvm` build script ran. However, the timestamps of the
// files in the tarball are in the past, so it doesn't trigger a // files in the tarball are in the past, so it doesn't trigger a
// rebuild. // rebuild.
let now = filetime::FileTime::from_system_time(std::time::SystemTime::now()); let now = std::time::SystemTime::now();
let file_times = fs::FileTimes::new().set_accessed(now).set_modified(now);
let llvm_config = llvm_root.join("bin").join(exe("llvm-config", self.build)); let llvm_config = llvm_root.join("bin").join(exe("llvm-config", self.build));
t!(filetime::set_file_times(llvm_config, now, now)); let llvm_config_file = t!(File::open(llvm_config));
t!(llvm_config_file.set_times(file_times));
if self.should_fix_bins_and_dylibs() { if self.should_fix_bins_and_dylibs() {
let llvm_lib = llvm_root.join("lib"); let llvm_lib = llvm_root.join("lib");

View File

@ -30,7 +30,6 @@ use std::time::SystemTime;
use build_helper::ci::{gha, CiEnv}; use build_helper::ci::{gha, CiEnv};
use build_helper::exit; use build_helper::exit;
use filetime::FileTime;
use sha2::digest::Digest; use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor}; use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo; use utils::channel::GitInfo;
@ -1708,9 +1707,13 @@ Executed at: {executed_at}"#,
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e) panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
} }
t!(fs::set_permissions(dst, metadata.permissions())); t!(fs::set_permissions(dst, metadata.permissions()));
let atime = FileTime::from_last_access_time(&metadata);
let mtime = FileTime::from_last_modification_time(&metadata); let file_times = fs::FileTimes::new()
t!(filetime::set_file_times(dst, atime, mtime)); .set_accessed(t!(metadata.accessed()))
.set_modified(t!(metadata.modified()));
let dst_file = t!(fs::File::open(dst));
t!(dst_file.set_times(file_times));
} }
} }