1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Turn the output of a real Cargo build into a [`critpath_core::BuildGraph`].
//!
//! Two inputs are needed, and one `cargo build --timings -v --offline` produces both:
//!
//! - the **verbose build log**, which contains one `rustc` invocation per dirty unit and therefore
//! states the unit set, the edge set and each edge's kind exactly;
//! - the **timing report**, `target/cargo-timings/cargo-timing.html`, which contains each unit's
//! wall duration and the moment it emitted its metadata.
//!
//! Neither input is sufficient alone. The timing report cannot tell a library from a procedural
//! macro, and its `unblocked_units` fields record only the last blocker of each unit rather than the
//! dependency graph. The verbose log carries no timings. The details, and the measurements behind
//! them, are in `docs/cargo-data-sources.md`.
//!
//! ```no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let outputs = cargo_critpath::collect::from_directory(std::path::Path::new("captured"))?;
//! let input = cargo_critpath::parse_with_metadata(
//! &outputs.verbose_log,
//! &outputs.timing_html,
//! outputs.cargo_metadata.as_deref(),
//! )?;
//! println!("{} units, {} edges", input.graph.len(), input.graph.edge_count());
//! # Ok(())
//! # }
//! ```
//!
//! Everything except [`collect`] takes text rather than paths, so it is testable without a
//! filesystem.
pub use ;
pub use ;
pub use ;
pub use ;
pub use MatchMethod;
pub use ;
/// Parses one build's verbose log and timing report into an analysable [`BuildInput`].
///
/// This is the entry point most callers want. See [`parse_with_metadata`] for the workspaces where
/// it is not enough.
///
/// # Errors
///
/// Returns [`ParseError`] if either input cannot be parsed, if the build was not a clean full build,
/// or if the two inputs describe different sets of units. No graph is ever built from a partial unit
/// set: an unmatched unit is a refusal, not a warning.
/// Parses one build's inputs, resolving workspace-local packages through `cargo metadata`.
///
/// A `rustc` invocation identifies its unit by a source path. For a registry crate that path
/// contains `name-version/` and the package is known exactly. For a workspace-local crate it does
/// not. `cargo metadata --format-version 1` gives every package's `manifest_path`, so a source path
/// can be attributed to a package by longest-prefix match on the manifest directories — exactly,
/// with no heuristic.
///
/// Passing `None` falls back to the crate name and then to the crate's own directory name, which is
/// right for most workspaces and wrong for some: `bevy` keeps several distinct procedural-macro
/// packages in directories all named `macros`. Where the fallback cannot separate two units, the
/// parse fails and the error says that `cargo metadata` output would resolve it.
///
/// # Errors
///
/// As [`parse`], plus [`ParseError::Metadata`] if `cargo_metadata` is not the expected JSON.