Skip to content

Commit

Permalink
Improve crate_universe debug logging for cargo tree parsing (#2854)
Browse files Browse the repository at this point in the history
It's much easier to understand what's going on if I can see a standard
`cargo tree` output.
  • Loading branch information
UebelAndre committed Sep 10, 2024
1 parent 8ae5dc8 commit 98e847b
Show file tree
Hide file tree
Showing 8 changed files with 2,417 additions and 121 deletions.
8 changes: 2 additions & 6 deletions crate_universe/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl LoggingFormatEvent {
}

/// Initialize logging for one of the cli options.
pub fn init_logging(name: &str) {
pub fn init_logging(name: &str, verbose: bool) {
if !EXPECTED_LOGGER_NAMES.contains(&name) {
panic!(
"Unexpected logger name {}, use of one of {:?}",
Expand All @@ -98,11 +98,7 @@ pub fn init_logging(name: &str) {
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
// will be written to stdout.
.with_max_level(
std::env::var("CARGO_BAZEL_DEBUG")
.map(|_| Level::DEBUG)
.unwrap_or(Level::INFO),
)
.with_max_level(if verbose { Level::DEBUG } else { Level::INFO })
.event_format(LoggingFormatEvent::new(name))
// completes the builder.
.finish();
Expand Down
10 changes: 6 additions & 4 deletions crate_universe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ fn main() -> cli::Result<()> {
// Parse arguments
let opt = cli::parse_args();

let verbose_logging = std::env::var("CARGO_BAZEL_DEBUG").is_ok();

match opt {
cli::Options::Generate(opt) => {
cli::init_logging("Generate");
cli::init_logging("Generate", verbose_logging);
cli::generate(opt)
}
cli::Options::Splice(opt) => {
cli::init_logging("Splice");
cli::init_logging("Splice", verbose_logging);
cli::splice(opt)
}
cli::Options::Query(opt) => {
cli::init_logging("Query");
cli::init_logging("Query", verbose_logging);
cli::query(opt)
}
cli::Options::Vendor(opt) => {
cli::init_logging("Vendor");
cli::init_logging("Vendor", verbose_logging);
cli::vendor(opt)
}
}
Expand Down
389 changes: 289 additions & 100 deletions crate_universe/src/metadata/cargo_tree_resolver.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crate_universe/src/metadata/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ mod test {
let pkg = &metadata[&node.id];
pkg.name == name
})
.unwrap()
.unwrap_or_else(|| panic!("Unable to find node '{}'", name))
}

#[test]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "nested_build_dependencies"
version = "0.0.0"
edition = "2021"

# Required to satisfy cargo but no `lib.rs` is expected to
# exist within test data.
[lib]
path = "lib.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
num-traits = "0.2.19"
syn = "2.0.77"

[dev-dependencies]
proc-macro-error-attr = "=1.0.4"
Loading

0 comments on commit 98e847b

Please sign in to comment.