Skip to content

Commit 4916801

Browse files
committed
Auto merge of #57871 - Mark-Simulacrum:fix-compiletest-stamp, r=oli-obk
Correctly set filetime for copied LLVM This also makes compiletest no longer always retest everything. Fixes #57864
2 parents 20c2cba + 82fae2b commit 4916801

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

Diff for: src/bootstrap/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ use std::cell::{RefCell, Cell};
135135
use std::collections::{HashSet, HashMap};
136136
use std::env;
137137
use std::fs::{self, OpenOptions, File};
138-
use std::io::{self, Seek, SeekFrom, Write, Read};
138+
use std::io::{Seek, SeekFrom, Write, Read};
139139
use std::path::{PathBuf, Path};
140140
use std::process::{self, Command};
141141
use std::slice;
@@ -1263,9 +1263,15 @@ impl Build {
12631263
if !src.exists() {
12641264
panic!("Error: File \"{}\" not found!", src.display());
12651265
}
1266-
let mut s = t!(fs::File::open(&src));
1267-
let mut d = t!(fs::File::create(&dst));
1268-
io::copy(&mut s, &mut d).expect("failed to copy");
1266+
let metadata = t!(src.symlink_metadata());
1267+
if let Err(e) = fs::copy(&src, &dst) {
1268+
panic!("failed to copy `{}` to `{}`: {}", src.display(),
1269+
dst.display(), e)
1270+
}
1271+
t!(fs::set_permissions(&dst, metadata.permissions()));
1272+
let atime = FileTime::from_last_access_time(&metadata);
1273+
let mtime = FileTime::from_last_modification_time(&metadata);
1274+
t!(filetime::set_file_times(&dst, atime, mtime));
12691275
}
12701276
chmod(&dst, perms);
12711277
}

Diff for: src/tools/compiletest/src/main.rs

+35-19
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,6 @@ fn stamp(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> Path
669669
output_base_dir(config, testpaths, revision).join("stamp")
670670
}
671671

672-
/// Return an iterator over timestamps of files in the directory at `path`.
673-
fn collect_timestamps(path: &PathBuf) -> impl Iterator<Item=FileTime> {
674-
WalkDir::new(path)
675-
.into_iter()
676-
.map(|entry| entry.unwrap())
677-
.filter(|entry| entry.file_type().is_file())
678-
.map(|entry| mtime(entry.path()))
679-
}
680-
681672
fn up_to_date(
682673
config: &Config,
683674
testpaths: &TestPaths,
@@ -700,13 +691,15 @@ fn up_to_date(
700691
let rust_src_dir = config
701692
.find_rust_src_root()
702693
.expect("Could not find Rust source root");
703-
let stamp = mtime(&stamp_name);
704-
let mut inputs = vec![mtime(&testpaths.file), mtime(&config.rustc_path)];
694+
let stamp = Stamp::from_path(&stamp_name);
695+
let mut inputs = vec![Stamp::from_path(&testpaths.file), Stamp::from_path(&config.rustc_path)];
705696
inputs.extend(
706697
props
707698
.aux
708699
.iter()
709-
.map(|aux| mtime(&testpaths.file.parent().unwrap().join("auxiliary").join(aux))),
700+
.map(|aux| {
701+
Stamp::from_path(&testpaths.file.parent().unwrap().join("auxiliary").join(aux))
702+
}),
710703
);
711704
// Relevant pretty printer files
712705
let pretty_printer_files = [
@@ -717,24 +710,47 @@ fn up_to_date(
717710
"src/etc/lldb_rust_formatters.py",
718711
];
719712
inputs.extend(pretty_printer_files.iter().map(|pretty_printer_file| {
720-
mtime(&rust_src_dir.join(pretty_printer_file))
713+
Stamp::from_path(&rust_src_dir.join(pretty_printer_file))
721714
}));
722-
inputs.extend(collect_timestamps(&config.run_lib_path));
715+
inputs.extend(Stamp::from_dir(&config.run_lib_path));
723716
if let Some(ref rustdoc_path) = config.rustdoc_path {
724-
inputs.push(mtime(&rustdoc_path));
725-
inputs.push(mtime(&rust_src_dir.join("src/etc/htmldocck.py")));
717+
inputs.push(Stamp::from_path(&rustdoc_path));
718+
inputs.push(Stamp::from_path(&rust_src_dir.join("src/etc/htmldocck.py")));
726719
}
727720

728721
// UI test files.
729722
inputs.extend(UI_EXTENSIONS.iter().map(|extension| {
730723
let path = &expected_output_path(testpaths, revision, &config.compare_mode, extension);
731-
mtime(path)
724+
Stamp::from_path(path)
732725
}));
733726

734727
// Compiletest itself.
735-
inputs.extend(collect_timestamps(&rust_src_dir.join("src/tools/compiletest/")));
728+
inputs.extend(Stamp::from_dir(&rust_src_dir.join("src/tools/compiletest/")));
736729

737-
inputs.iter().any(|input| *input > stamp)
730+
inputs.iter().any(|input| input > &stamp)
731+
}
732+
733+
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)]
734+
struct Stamp {
735+
time: FileTime,
736+
file: PathBuf,
737+
}
738+
739+
impl Stamp {
740+
fn from_path(p: &Path) -> Self {
741+
Stamp {
742+
time: mtime(&p),
743+
file: p.into(),
744+
}
745+
}
746+
747+
fn from_dir(path: &Path) -> impl Iterator<Item=Stamp> {
748+
WalkDir::new(path)
749+
.into_iter()
750+
.map(|entry| entry.unwrap())
751+
.filter(|entry| entry.file_type().is_file())
752+
.map(|entry| Stamp::from_path(entry.path()))
753+
}
738754
}
739755

740756
fn mtime(path: &Path) -> FileTime {

Diff for: src/tools/compiletest/src/runtest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,8 @@ impl<'test> TestCx<'test> {
20332033

20342034
fn fatal(&self, err: &str) -> ! {
20352035
self.error(err);
2036-
panic!();
2036+
error!("fatal error, panic: {:?}", err);
2037+
panic!("fatal error");
20372038
}
20382039

20392040
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {

0 commit comments

Comments
 (0)