Skip to content

Commit bef29c0

Browse files
authored
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.
2 parents 60e10e6 + e2c15fe commit bef29c0

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

src/bootstrap/Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ dependencies = [
4848
"clap_complete",
4949
"cmake",
5050
"fd-lock",
51-
"filetime",
5251
"home",
5352
"ignore",
5453
"junction",

src/bootstrap/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ build_helper = { path = "../tools/build_helper" }
4444
clap = { version = "4.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
4545
clap_complete = "4.4"
4646
fd-lock = "4.0"
47-
filetime = "0.2"
4847
home = "0.5"
4948
ignore = "0.4"
5049
libc = "0.2"

src/bootstrap/src/core/build_steps/compile.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::utils::helpers::{
3333
};
3434
use crate::LLVM_TOOLS;
3535
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
36-
use filetime::FileTime;
3736

3837
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3938
pub struct Std {
@@ -2161,9 +2160,11 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
21612160
return;
21622161
}
21632162

2164-
let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
2163+
let previous_mtime = t!(t!(path.metadata()).modified());
21652164
command("strip").capture().arg("--strip-debug").arg(path).run(builder);
21662165

2166+
let file = t!(fs::File::open(path));
2167+
21672168
// After running `strip`, we have to set the file modification time to what it was before,
21682169
// otherwise we risk Cargo invalidating its fingerprint and rebuilding the world next time
21692170
// bootstrap is invoked.
@@ -2176,5 +2177,5 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
21762177
// In the second invocation of bootstrap, Cargo will see that the mtime of librustc_driver.so
21772178
// is greater than the mtime of rustc-main, and will rebuild rustc-main. That will then cause
21782179
// everything else (standard library, future stages...) to be rebuilt.
2179-
t!(filetime::set_file_mtime(path, previous_mtime));
2180+
t!(file.set_modified(previous_mtime));
21802181
}

src/bootstrap/src/core/download.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,13 @@ download-rustc = false
702702
// time `rustc_llvm` build script ran. However, the timestamps of the
703703
// files in the tarball are in the past, so it doesn't trigger a
704704
// rebuild.
705-
let now = filetime::FileTime::from_system_time(std::time::SystemTime::now());
705+
let now = std::time::SystemTime::now();
706+
let file_times = fs::FileTimes::new().set_accessed(now).set_modified(now);
707+
706708
let llvm_config = llvm_root.join("bin").join(exe("llvm-config", self.build));
707-
t!(filetime::set_file_times(llvm_config, now, now));
709+
let llvm_config_file = t!(File::open(llvm_config));
710+
711+
t!(llvm_config_file.set_times(file_times));
708712

709713
if self.should_fix_bins_and_dylibs() {
710714
let llvm_lib = llvm_root.join("lib");

src/bootstrap/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use std::time::SystemTime;
3030

3131
use build_helper::ci::{gha, CiEnv};
3232
use build_helper::exit;
33-
use filetime::FileTime;
3433
use sha2::digest::Digest;
3534
use termcolor::{ColorChoice, StandardStream, WriteColor};
3635
use utils::channel::GitInfo;
@@ -1708,9 +1707,13 @@ Executed at: {executed_at}"#,
17081707
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
17091708
}
17101709
t!(fs::set_permissions(dst, metadata.permissions()));
1711-
let atime = FileTime::from_last_access_time(&metadata);
1712-
let mtime = FileTime::from_last_modification_time(&metadata);
1713-
t!(filetime::set_file_times(dst, atime, mtime));
1710+
1711+
let file_times = fs::FileTimes::new()
1712+
.set_accessed(t!(metadata.accessed()))
1713+
.set_modified(t!(metadata.modified()));
1714+
1715+
let dst_file = t!(fs::File::open(dst));
1716+
t!(dst_file.set_times(file_times));
17141717
}
17151718
}
17161719

0 commit comments

Comments
 (0)