Skip to content

Commit b496622

Browse files
committed
Prevent build-plan touch files
1 parent dba478b commit b496622

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,17 @@ fn rustc<'a, 'cfg>(
251251
add_custom_env(&mut rustc, &script_outputs, current_id, kind)?;
252252
}
253253

254-
for output in outputs.iter() {
255-
// If there is both an rmeta and rlib, rustc will prefer to use the
256-
// rlib, even if it is older. Therefore, we must delete the rlib to
257-
// force using the new rmeta.
258-
if output.path.extension() == Some(OsStr::new("rmeta")) {
259-
let dst = root.join(&output.path).with_extension("rlib");
260-
if dst.exists() {
261-
paths::remove_file(&dst)?;
254+
// Don't touch any file when we are generating build-plan
255+
if !build_plan {
256+
for output in outputs.iter() {
257+
// If there is both an rmeta and rlib, rustc will prefer to use the
258+
// rlib, even if it is older. Therefore, we must delete the rlib to
259+
// force using the new rmeta.
260+
if output.path.extension() == Some(OsStr::new("rmeta")) {
261+
let dst = root.join(&output.path).with_extension("rlib");
262+
if dst.exists() {
263+
paths::remove_file(&dst)?;
264+
}
262265
}
263266
}
264267
}
@@ -277,9 +280,10 @@ fn rustc<'a, 'cfg>(
277280
}
278281

279282
state.running(&rustc);
280-
let timestamp = paths::set_invocation_time(&fingerprint_dir)?;
281-
if build_plan {
283+
let timestamp = if build_plan {
282284
state.build_plan(buildkey, rustc.clone(), outputs.clone());
285+
// Build plan should not touch the timestamp
286+
None
283287
} else {
284288
exec.exec(
285289
rustc,
@@ -291,7 +295,8 @@ fn rustc<'a, 'cfg>(
291295
)
292296
.map_err(internal_if_simple_exit_code)
293297
.chain_err(|| format!("could not compile `{}`.", name))?;
294-
}
298+
Some(paths::set_invocation_time(&fingerprint_dir)?)
299+
};
295300

296301
if do_rename && real_name != crate_name {
297302
let dst = &outputs[0].path;
@@ -324,7 +329,10 @@ fn rustc<'a, 'cfg>(
324329
rustc_dep_info_loc.display()
325330
))
326331
})?;
327-
filetime::set_file_times(dep_info_loc, timestamp, timestamp)?;
332+
333+
if let Some(timestamp) = timestamp {
334+
filetime::set_file_times(dep_info_loc, timestamp, timestamp)?;
335+
}
328336
}
329337

330338
Ok(())

0 commit comments

Comments
 (0)