Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use std for file mtime and atime modifications #127697

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies = [
"clap_complete",
"cmake",
"fd-lock",
"filetime",
"home",
"ignore",
"junction",
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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_complete = "4.4"
fd-lock = "4.0"
filetime = "0.2"
home = "0.5"
ignore = "0.4"
libc = "0.2"
Expand Down
7 changes: 4 additions & 3 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::utils::helpers::{
};
use crate::LLVM_TOOLS;
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
use filetime::FileTime;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Std {
Expand Down Expand Up @@ -2160,9 +2159,11 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
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);

let file = t!(fs::File::open(path));

// 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
// bootstrap is invoked.
Expand All @@ -2175,5 +2176,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
// 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.
t!(filetime::set_file_mtime(path, previous_mtime));
t!(file.set_modified(previous_mtime));
}
8 changes: 6 additions & 2 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,13 @@ download-rustc = false
// 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
// 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));
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() {
let llvm_lib = llvm_root.join("lib");
Expand Down
11 changes: 7 additions & 4 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use std::time::SystemTime;

use build_helper::ci::{gha, CiEnv};
use build_helper::exit;
use filetime::FileTime;
use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo;
Expand Down Expand Up @@ -1693,9 +1692,13 @@ impl Build {
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
}
t!(fs::set_permissions(dst, metadata.permissions()));
let atime = FileTime::from_last_access_time(&metadata);
let mtime = FileTime::from_last_modification_time(&metadata);
t!(filetime::set_file_times(dst, atime, mtime));

let file_times = fs::FileTimes::new()
.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));
}
}

Expand Down
Loading