Skip to content

Commit eba4323

Browse files
committed
Back touch the output instead of having a new important file.
This still round trips through the file system just in case it is on a different clock.
1 parent 03a6b6e commit eba4323

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,14 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
332332
state.build_plan(invocation_name, cmd.clone(), Arc::new(Vec::new()));
333333
} else {
334334
state.running(&cmd);
335+
// `invoked.timestamp` is used to get `FileTime::from_system_time(SystemTime::now());`
336+
// using the exact clock that this file system is using.
337+
let timestamp = output_file.with_file_name("invoked.timestamp");
335338
paths::write(
336-
&output_file.with_file_name("invoked.timestamp"),
339+
&timestamp,
337340
b"This file has an mtime of when this build-script was started.",
338341
)?;
342+
let timestamp = paths::mtime(&timestamp)?;
339343
let output = if extra_verbose {
340344
let prefix = format!("[{} {}] ", id.name(), id.version());
341345
state.capture_output(&cmd, Some(prefix), true)
@@ -358,6 +362,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
358362
// state informing what variables were discovered via our script as
359363
// well.
360364
paths::write(&output_file, &output.stdout)?;
365+
filetime::set_file_times(output_file, timestamp, timestamp)?;
361366
paths::write(&err_file, &output.stderr)?;
362367
paths::write(&root_output_file, util::path2bytes(&script_out_dir)?)?;
363368
let parsed_output =

src/cargo/core/compiler/fingerprint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Fingerprint {
239239
for local in self.local.iter() {
240240
match *local {
241241
LocalFingerprint::MtimeBased(ref slot, ref path) => {
242-
let path = root.join(&path.with_file_name("invoked.timestamp"));
242+
let path = root.join(path);
243243
let mtime = paths::mtime(&path)?;
244244
*slot.0.lock().unwrap() = Some(mtime);
245245
}
@@ -746,7 +746,7 @@ where
746746
I: IntoIterator,
747747
I::Item: AsRef<Path>,
748748
{
749-
let mtime = match paths::mtime(&output.with_file_name("invoked.timestamp")) {
749+
let mtime = match paths::mtime(output) {
750750
Ok(mtime) => mtime,
751751
Err(..) => return None,
752752
};

src/cargo/core/compiler/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ fn rustc<'a, 'cfg>(
292292
}
293293

294294
state.running(&rustc);
295+
// `invoked.timestamp` is used to get `FileTime::from_system_time(SystemTime::now());`
296+
// using the exact clock that this file system is using.
297+
let timestamp = dep_info_loc.with_file_name("invoked.timestamp");
295298
paths::write(
296-
&dep_info_loc.with_file_name("invoked.timestamp"),
299+
&timestamp,
297300
b"This file has an mtime of when rustc was started.",
298301
)?;
302+
let timestamp = paths::mtime(&timestamp)?;
299303
if json_messages {
300304
exec.exec_json(
301305
rustc,
@@ -338,6 +342,7 @@ fn rustc<'a, 'cfg>(
338342
rustc_dep_info_loc.display()
339343
))
340344
})?;
345+
filetime::set_file_times(dep_info_loc, timestamp, timestamp)?;
341346
}
342347

343348
Ok(())

0 commit comments

Comments
 (0)