diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 391a2b7cf4b..dec3c57b169 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -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"), + ×tamp, b"This file has an mtime of when this build-script was started.", )?; + let timestamp = paths::mtime(×tamp)?; let output = if extra_verbose { let prefix = format!("[{} {}] ", id.name(), id.version()); 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 // 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 = diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 5fd44dd1e7f..484ca6c5e01 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -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); } @@ -746,7 +746,7 @@ where I: IntoIterator, I::Item: AsRef, { - let mtime = match paths::mtime(&output.with_file_name("invoked.timestamp")) { + let mtime = match paths::mtime(output) { Ok(mtime) => mtime, Err(..) => return None, }; diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index bbb1f686b25..db86a60b9e2 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -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"), + ×tamp, b"This file has an mtime of when rustc was started.", )?; + let timestamp = paths::mtime(×tamp)?; if json_messages { exec.exec_json( rustc, @@ -338,6 +342,7 @@ fn rustc<'a, 'cfg>( rustc_dep_info_loc.display() )) })?; + filetime::set_file_times(dep_info_loc, timestamp, timestamp)?; } Ok(())