Skip to content

Commit 7d61462

Browse files
committed
feat(build-analysis): emit rebuild reason log entry
1 parent fed7d0a commit 7d61462

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/cargo/core/compiler/fingerprint/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ use crate::core::compiler::unit_graph::UnitDep;
397397
use crate::util;
398398
use crate::util::errors::CargoResult;
399399
use crate::util::interning::InternedString;
400+
use crate::util::log_message::LogMessage;
400401
use crate::util::{StableHasher, internal, path_args};
401402
use crate::{CARGO_ENV, GlobalContext};
402403

@@ -448,6 +449,18 @@ pub fn prepare_target(
448449
return Ok(Job::new_fresh());
449450
};
450451

452+
if let Some(logger) = bcx.logger {
453+
// Dont log FreshBuild as it is noisy.
454+
if !dirty_reason.is_fresh_build() {
455+
logger.log(LogMessage::Rebuild {
456+
package_id: unit.pkg.package_id().to_spec(),
457+
target: unit.target.clone(),
458+
mode: unit.mode,
459+
cause: dirty_reason.clone(),
460+
});
461+
}
462+
}
463+
451464
// We're going to rebuild, so ensure the source of the crate passes all
452465
// verification checks before we build it.
453466
//

src/cargo/util/log_message.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use serde::Serialize;
1010
use crate::core::Target;
1111
use crate::core::compiler::CompilationSection;
1212
use crate::core::compiler::CompileMode;
13+
use crate::core::compiler::fingerprint::DirtyReason;
1314

1415
/// A log message.
1516
///
@@ -39,6 +40,13 @@ pub enum LogMessage {
3940
#[serde(skip_serializing_if = "Vec::is_empty")]
4041
sections: Vec<(String, CompilationSection)>,
4142
},
43+
/// Emitted when a unit needs to be rebuilt.
44+
Rebuild {
45+
package_id: PackageIdSpec,
46+
target: Target,
47+
mode: CompileMode,
48+
cause: DirtyReason,
49+
},
4250
}
4351

4452
impl LogMessage {

tests/testsuite/build_analysis.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ fn log_rebuild_reason_file_changed() {
227227
"...": "{...}",
228228
"reason": "build-started"
229229
},
230+
{
231+
"cause": {
232+
"dirty_reason": "fs-status-outdated",
233+
"fs_status": "stale-item",
234+
"reference": "[ROOT]/foo/target/debug/.fingerprint/foo-[HASH]/dep-lib-foo",
235+
"reference_mtime": "{...}",
236+
"stale": "[ROOT]/foo/src/lib.rs",
237+
"stale_item": "changed-file",
238+
"stale_mtime": "{...}"
239+
},
240+
"mode": "check",
241+
"package_id": "path+[ROOTURL]/foo#0.0.0",
242+
"reason": "rebuild",
243+
"run_id": "[..]T[..]Z-[..]",
244+
"target": "{...}",
245+
"timestamp": "[..]T[..]Z"
246+
},
230247
{
231248
"...": "{...}",
232249
"reason": "timing-info"

0 commit comments

Comments
 (0)