Skip to content

Commit c7b2df1

Browse files
committed
Add a way to force a unit of work to always be rebuilt
1 parent 9e664bd commit c7b2df1

File tree

1 file changed

+12
-1
lines changed
  • src/cargo/ops/cargo_rustc

1 file changed

+12
-1
lines changed

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ pub trait Executor: Send + Sync + 'static {
8383
cmd.exec_with_streaming(handle_stdout, handle_stderr, false)?;
8484
Ok(())
8585
}
86+
87+
/// Queried when queuing each unit of work. If it returns true, then the
88+
/// unit will always be rebuilt, independent of whether it needs to be.
89+
fn force_rebuild(&self, _unit: &Unit) -> bool {
90+
false
91+
}
8692
}
8793

8894
/// A DefaultExecutor calls rustc without doing anything else. It is Cargo's
@@ -230,7 +236,7 @@ fn compile<'a, 'cfg: 'a>(cx: &mut Context<'a, 'cfg>,
230236
// we run these targets later, so this is just a noop for now
231237
(Work::new(|_| Ok(())), Work::new(|_| Ok(())), Freshness::Fresh)
232238
} else {
233-
let (freshness, dirty, fresh) = fingerprint::prepare_target(cx, unit)?;
239+
let (mut freshness, dirty, fresh) = fingerprint::prepare_target(cx, unit)?;
234240
let work = if unit.profile.doc {
235241
rustdoc(cx, unit)?
236242
} else {
@@ -239,6 +245,11 @@ fn compile<'a, 'cfg: 'a>(cx: &mut Context<'a, 'cfg>,
239245
// Need to link targets on both the dirty and fresh
240246
let dirty = work.then(link_targets(cx, unit, false)?).then(dirty);
241247
let fresh = link_targets(cx, unit, true)?.then(fresh);
248+
249+
if exec.force_rebuild(unit) {
250+
freshness = Freshness::Dirty;
251+
}
252+
242253
(dirty, fresh, freshness)
243254
};
244255
jobs.enqueue(cx, unit, Job::new(dirty, fresh), freshness)?;

0 commit comments

Comments
 (0)