Skip to content

Commit a87f50f

Browse files
committed
make a helper function
1 parent eba4323 commit a87f50f

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,7 @@ 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");
338-
paths::write(
339-
&timestamp,
340-
b"This file has an mtime of when this build-script was started.",
341-
)?;
342-
let timestamp = paths::mtime(&timestamp)?;
335+
let timestamp = paths::get_current_filesystem_time(&output_file)?;
343336
let output = if extra_verbose {
344337
let prefix = format!("[{} {}] ", id.name(), id.version());
345338
state.capture_output(&cmd, Some(prefix), true)

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,7 @@ 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");
298-
paths::write(
299-
&timestamp,
300-
b"This file has an mtime of when rustc was started.",
301-
)?;
302-
let timestamp = paths::mtime(&timestamp)?;
295+
let timestamp = paths::get_current_filesystem_time(&dep_info_loc)?;
303296
if json_messages {
304297
exec.exec_json(
305298
rustc,

src/cargo/util/paths.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ pub fn mtime(path: &Path) -> CargoResult<FileTime> {
197197
Ok(FileTime::from_last_modification_time(&meta))
198198
}
199199

200+
/// get `FileTime::from_system_time(SystemTime::now());` using the exact clock that this file system is using.
201+
pub fn get_current_filesystem_time(path: &Path) -> CargoResult<FileTime> {
202+
// note that if `FileTime::from_system_time(SystemTime::now());` is determined to be sufficient,
203+
// then this can be removed.
204+
let timestamp = path.with_file_name("invoked.timestamp");
205+
write(
206+
&timestamp,
207+
b"This file has an mtime of when this was started.",
208+
)?;
209+
Ok(mtime(&timestamp)?)
210+
}
211+
200212
#[cfg(unix)]
201213
pub fn path2bytes(path: &Path) -> CargoResult<&[u8]> {
202214
use std::os::unix::prelude::*;

0 commit comments

Comments
 (0)