Skip to content

Commit

Permalink
refactor: remove unnecessary Option in Freshness::Dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jan 28, 2024
1 parent 1a277ab commit 84584e6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use super::{fingerprint, Context, Job, Unit, Work};
use crate::core::compiler::artifact;
use crate::core::compiler::context::Metadata;
use crate::core::compiler::fingerprint::DirtyReason;
use crate::core::compiler::job_queue::JobState;
use crate::core::{profiles::ProfileRoot, PackageId, Target};
use crate::util::errors::CargoResult;
Expand Down Expand Up @@ -608,7 +609,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
});

let mut job = if cx.bcx.build_config.build_plan {
Job::new_dirty(Work::noop(), None)
Job::new_dirty(Work::noop(), DirtyReason::FreshBuild)
} else {
fingerprint::prepare_target(cx, unit, false)?
};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
Work::new(move |_| write_fingerprint(&loc, &fingerprint))
};

Ok(Job::new_dirty(write_fingerprint, Some(dirty_reason)))
Ok(Job::new_dirty(write_fingerprint, dirty_reason))
}

/// Dependency edge information for fingerprints. This is generated for each
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/job_queue/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Job {
}

/// Creates a new job representing a unit of work.
pub fn new_dirty(work: Work, dirty_reason: Option<DirtyReason>) -> Job {
pub fn new_dirty(work: Work, dirty_reason: DirtyReason) -> Job {
Job {
work,
fresh: Freshness::Dirty(dirty_reason),
Expand Down Expand Up @@ -100,7 +100,7 @@ impl fmt::Debug for Job {
#[derive(Debug, Clone)]
pub enum Freshness {
Fresh,
Dirty(Option<DirtyReason>),
Dirty(DirtyReason),
}

impl Freshness {
Expand Down
10 changes: 4 additions & 6 deletions src/cargo/core/compiler/job_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,12 +1110,10 @@ impl<'cfg> DrainState<'cfg> {
// Any dirty stage which runs at least one command gets printed as
// being a compiled package.
Dirty(dirty_reason) => {
if let Some(reason) = dirty_reason {
if !reason.is_fresh_build() {
config
.shell()
.verbose(|shell| reason.present_to(shell, unit, ws_root))?;
}
if !dirty_reason.is_fresh_build() {
config
.shell()
.verbose(|shell| dirty_reason.present_to(shell, unit, ws_root))?;
}

if unit.mode.is_doc() {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn compile<'cfg>(
// We run these targets later, so this is just a no-op for now.
Job::new_fresh()
} else if build_plan {
Job::new_dirty(rustc(cx, unit, &exec.clone())?, None)
Job::new_dirty(rustc(cx, unit, &exec.clone())?, DirtyReason::FreshBuild)
} else {
let force = exec.force_rebuild(unit) || force_rebuild;
let mut job = fingerprint::prepare_target(cx, unit, force)?;
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl InstallTracker {
// Check if any tracked exe's are already installed.
let duplicates = self.find_duplicates(dst, &exes);
if force || duplicates.is_empty() {
return Ok((Freshness::Dirty(Some(DirtyReason::Forced)), duplicates));
return Ok((Freshness::Dirty(DirtyReason::Forced), duplicates));
}
// Check if all duplicates come from packages of the same name. If
// there are duplicates from other packages, then --force will be
Expand Down Expand Up @@ -205,7 +205,7 @@ impl InstallTracker {
let source_id = pkg.package_id().source_id();
if source_id.is_path() {
// `cargo install --path ...` is always rebuilt.
return Ok((Freshness::Dirty(Some(DirtyReason::Forced)), duplicates));
return Ok((Freshness::Dirty(DirtyReason::Forced), duplicates));
}
let is_up_to_date = |dupe_pkg_id| {
let info = self
Expand All @@ -229,7 +229,7 @@ impl InstallTracker {
if matching_duplicates.iter().all(is_up_to_date) {
Ok((Freshness::Fresh, duplicates))
} else {
Ok((Freshness::Dirty(Some(DirtyReason::Forced)), duplicates))
Ok((Freshness::Dirty(DirtyReason::Forced), duplicates))
}
} else {
// Format the error message.
Expand Down

0 comments on commit 84584e6

Please sign in to comment.