Skip to content

Commit

Permalink
Back touch the output instead of having a new important file.
Browse files Browse the repository at this point in the history
This still round trips through the file system just in case it is on a different clock.
  • Loading branch information
Eh2406 committed Jan 2, 2019
1 parent 03a6b6e commit eba4323
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,14 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
state.build_plan(invocation_name, cmd.clone(), Arc::new(Vec::new()));
} else {
state.running(&cmd);
// `invoked.timestamp` is used to get `FileTime::from_system_time(SystemTime::now());`
// using the exact clock that this file system is using.
let timestamp = output_file.with_file_name("invoked.timestamp");
paths::write(
&output_file.with_file_name("invoked.timestamp"),
&timestamp,
b"This file has an mtime of when this build-script was started.",
)?;
let timestamp = paths::mtime(&timestamp)?;
let output = if extra_verbose {
let prefix = format!("[{} {}] ", id.name(), id.version());
state.capture_output(&cmd, Some(prefix), true)
Expand All @@ -358,6 +362,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
// state informing what variables were discovered via our script as
// well.
paths::write(&output_file, &output.stdout)?;
filetime::set_file_times(output_file, timestamp, timestamp)?;
paths::write(&err_file, &output.stderr)?;
paths::write(&root_output_file, util::path2bytes(&script_out_dir)?)?;
let parsed_output =
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl Fingerprint {
for local in self.local.iter() {
match *local {
LocalFingerprint::MtimeBased(ref slot, ref path) => {
let path = root.join(&path.with_file_name("invoked.timestamp"));
let path = root.join(path);
let mtime = paths::mtime(&path)?;
*slot.0.lock().unwrap() = Some(mtime);
}
Expand Down Expand Up @@ -746,7 +746,7 @@ where
I: IntoIterator,
I::Item: AsRef<Path>,
{
let mtime = match paths::mtime(&output.with_file_name("invoked.timestamp")) {
let mtime = match paths::mtime(output) {
Ok(mtime) => mtime,
Err(..) => return None,
};
Expand Down
7 changes: 6 additions & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,14 @@ fn rustc<'a, 'cfg>(
}

state.running(&rustc);
// `invoked.timestamp` is used to get `FileTime::from_system_time(SystemTime::now());`
// using the exact clock that this file system is using.
let timestamp = dep_info_loc.with_file_name("invoked.timestamp");
paths::write(
&dep_info_loc.with_file_name("invoked.timestamp"),
&timestamp,
b"This file has an mtime of when rustc was started.",
)?;
let timestamp = paths::mtime(&timestamp)?;
if json_messages {
exec.exec_json(
rustc,
Expand Down Expand Up @@ -338,6 +342,7 @@ fn rustc<'a, 'cfg>(
rustc_dep_info_loc.display()
))
})?;
filetime::set_file_times(dep_info_loc, timestamp, timestamp)?;
}

Ok(())
Expand Down

0 comments on commit eba4323

Please sign in to comment.