Skip to content

Commit 6237eb5

Browse files
committed
refactor: Replace debugln! macro with log crate
Migrate all `debugln!` calls to `log::debug!` and remove the old debug infrastructure (`ENABLE_DEBUG`, `--debug` flag, and `debugln!` macro definitions). Debug output is now controlled via the `-v/-vv/-vvv` verbosity levels introduced in the previous commit.
1 parent 6db10d1 commit 6237eb5

10 files changed

Lines changed: 77 additions & 128 deletions

File tree

src/cli.rs

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::diagnostic::{Diagnostics, Warnings};
2929
use crate::error::*;
3030
use crate::lockfile::*;
3131
use crate::sess::{Session, SessionArenas, SessionIo};
32-
use crate::{debugln, fmt_path, fmt_pkg, stageln};
32+
use crate::{fmt_path, fmt_pkg, stageln};
3333

3434
#[derive(Parser, Debug)]
3535
#[command(name = "bender")]
@@ -84,16 +84,6 @@ struct Cli {
8484
)]
8585
verbose: u8,
8686

87-
/// Print additional debug information
88-
#[cfg(debug_assertions)]
89-
#[arg(
90-
long,
91-
global = true,
92-
help_heading = "Global Options",
93-
env = "BENDER_DEBUG"
94-
)]
95-
debug: bool,
96-
9787
#[command(subcommand)]
9888
command: Commands,
9989
}
@@ -170,11 +160,6 @@ pub fn main() -> Result<()> {
170160
// Initialize warning and error handling with the suppression arguments.
171161
Diagnostics::init(suppressed_warnings);
172162

173-
#[cfg(debug_assertions)]
174-
if cli.debug {
175-
ENABLE_DEBUG.store(true, std::sync::atomic::Ordering::Relaxed);
176-
}
177-
178163
// Handle commands that do not require a session.
179164
match &cli.command {
180165
Commands::Completion(args) => {
@@ -202,16 +187,16 @@ pub fn main() -> Result<()> {
202187
None => find_package_root(Path::new("."))
203188
.map_err(|cause| Error::chain("Cannot find root directory of package.", cause))?,
204189
};
205-
debugln!("main: root dir {:?}", root_dir);
190+
log::debug!("root dir {:?}", root_dir);
206191

207192
// Parse the manifest file of the package.
208193
let manifest_path = root_dir.join("Bender.yml");
209194
let manifest = read_manifest(&manifest_path)?;
210-
debugln!("main: {:#?}", manifest);
195+
log::debug!("{:#?}", manifest);
211196

212197
// Gather and parse the tool configuration.
213198
let config = load_config(&root_dir, matches!(cli.command, Commands::Update(_)))?;
214-
debugln!("main: {:#?}", config);
199+
log::debug!("{:#?}", config);
215200

216201
// Determine git throttle. The precedence is: CLI argument, env variable, config file, default (4).
217202
let git_throttle = cli.git_throttle.or(config.git_throttle).unwrap_or(4);
@@ -251,7 +236,7 @@ pub fn main() -> Result<()> {
251236
cmd::update::run_plain(false, &sess, locked_existing.as_ref(), IndexSet::new())?
252237
}
253238
_ => {
254-
debugln!("main: lockfile {:?} up-to-date", lock_path);
239+
log::debug!("lockfile {:?} up-to-date", lock_path);
255240
(locked_existing.unwrap(), Vec::new())
256241
}
257242
};
@@ -262,7 +247,7 @@ pub fn main() -> Result<()> {
262247
{
263248
let io = SessionIo::new(&sess);
264249
for (path, pkg_name) in &sess.manifest.workspace.package_links {
265-
debugln!("main: maintaining link to {} at {:?}", pkg_name, path);
250+
log::debug!("maintaining link to {} at {:?}", pkg_name, path);
266251

267252
// Determine the checkout path for this package.
268253
let pkg_path = io.get_package_path(sess.dependency_with_name(pkg_name)?);
@@ -293,7 +278,7 @@ pub fn main() -> Result<()> {
293278
continue;
294279
}
295280
if path.read_link().map(|d| d != pkg_path).unwrap_or(true) {
296-
debugln!("main: removing existing link {:?}", path);
281+
log::debug!("removing existing link {:?}", path);
297282
remove_symlink_dir(path).map_err(|cause| {
298283
Error::chain(
299284
format!("Failed to remove symlink at path {:?}.", path),
@@ -400,18 +385,18 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
400385
// Canonicalize the path. This will resolve any intermediate links.
401386
let mut path = canonicalize(from)
402387
.map_err(|cause| Error::chain(format!("Failed to canonicalize path {:?}.", from), cause))?;
403-
debugln!("find_package_root: canonicalized to {:?}", path);
388+
log::debug!("canonicalized to {:?}", path);
404389

405390
// Look up the device at the current path. This information will then be
406391
// used to stop at filesystem boundaries.
407392
#[cfg(unix)]
408393
let limit_rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
409394
#[cfg(unix)]
410-
debugln!("find_package_root: limit rdev = {:?}", limit_rdev);
395+
log::debug!("limit rdev = {:?}", limit_rdev);
411396

412397
// Step upwards through the path hierarchy.
413398
for _ in 0..100 {
414-
debugln!("find_package_root: looking in {:?}", path);
399+
log::debug!("looking in {:?}", path);
415400

416401
// Check if we can find a package manifest here.
417402
if path.join("Bender.yml").exists() {
@@ -430,7 +415,7 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
430415
#[cfg(unix)]
431416
{
432417
let rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
433-
debugln!("find_package_root: rdev = {:?}", rdev);
418+
log::debug!("rdev = {:?}", rdev);
434419
if rdev != limit_rdev {
435420
return Err(Error::new(format!(
436421
"No manifest (`Bender.yml` file) found. Stopped searching at filesystem boundary {:?}.",
@@ -449,7 +434,7 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
449434
pub fn read_manifest(path: &Path) -> Result<Manifest> {
450435
use crate::config::PartialManifest;
451436
use std::fs::File;
452-
debugln!("read_manifest: {:?}", path);
437+
log::debug!("reading manifest {:?}", path);
453438
let file = File::open(path)
454439
.map_err(|cause| Error::chain(format!("Cannot open manifest {:?}.", path), cause))?;
455440
let partial: PartialManifest = serde_yaml_ng::from_reader(file)
@@ -471,14 +456,14 @@ fn load_config(from: &Path, warn_config_loaded: bool) -> Result<Config> {
471456
// Canonicalize the path. This will resolve any intermediate links.
472457
let mut path = canonicalize(from)
473458
.map_err(|cause| Error::chain(format!("Failed to canonicalize path {:?}.", from), cause))?;
474-
debugln!("load_config: canonicalized to {:?}", path);
459+
log::debug!("canonicalized to {:?}", path);
475460

476461
// Look up the device at the current path. This information will then be
477462
// used to stop at filesystem boundaries.
478463
#[cfg(unix)]
479464
let limit_rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
480465
#[cfg(unix)]
481-
debugln!("load_config: limit rdev = {:?}", limit_rdev);
466+
log::debug!("limit rdev = {:?}", limit_rdev);
482467

483468
// Step upwards through the path hierarchy.
484469
for _ in 0..100 {
@@ -487,7 +472,7 @@ fn load_config(from: &Path, warn_config_loaded: bool) -> Result<Config> {
487472
out = out.merge(cfg);
488473
}
489474

490-
debugln!("load_config: looking in {:?}", path);
475+
log::debug!("looking in {:?}", path);
491476

492477
if let Some(cfg) = maybe_load_config(&path.join(".bender.yml"), warn_config_loaded)? {
493478
out = out.merge(cfg);
@@ -502,7 +487,7 @@ fn load_config(from: &Path, warn_config_loaded: bool) -> Result<Config> {
502487
#[cfg(unix)]
503488
{
504489
let rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
505-
debugln!("load_config: rdev = {:?}", rdev);
490+
log::debug!("rdev = {:?}", rdev);
506491
if rdev != limit_rdev {
507492
break;
508493
}
@@ -551,7 +536,7 @@ fn load_config(from: &Path, warn_config_loaded: bool) -> Result<Config> {
551536
/// Load a configuration file if it exists.
552537
fn maybe_load_config(path: &Path, warn_config_loaded: bool) -> Result<Option<PartialConfig>> {
553538
use std::fs::File;
554-
debugln!("maybe_load_config: {:?}", path);
539+
log::debug!("maybe loading config {:?}", path);
555540
if !path.exists() {
556541
return Ok(None);
557542
}
@@ -570,7 +555,7 @@ fn maybe_load_config(path: &Path, warn_config_loaded: bool) -> Result<Option<Par
570555

571556
/// Execute a plugin.
572557
fn execute_plugin(sess: &Session, plugin: &str, args: &[String]) -> Result<()> {
573-
debugln!("main: execute plugin `{}`", plugin);
558+
log::debug!("execute plugin `{}`", plugin);
574559

575560
// Obtain a list of declared plugins.
576561
let runtime = Runtime::new()?;
@@ -582,7 +567,7 @@ fn execute_plugin(sess: &Session, plugin: &str, args: &[String]) -> Result<()> {
582567
Some(p) => p,
583568
None => return Err(Error::new(format!("Unknown command `{}`.", plugin))),
584569
};
585-
debugln!("main: found plugin {:#?}", plugin);
570+
log::debug!("found plugin {:#?}", plugin);
586571

587572
// Assemble a command that executes the plugin with the appropriate
588573
// environment and forwards command line arguments.
@@ -601,7 +586,7 @@ fn execute_plugin(sess: &Session, plugin: &str, args: &[String]) -> Result<()> {
601586
cmd.current_dir(sess.root);
602587
cmd.args(args);
603588

604-
debugln!("main: executing plugin {:#?}", cmd);
589+
log::debug!("executing plugin {:#?}", cmd);
605590
let stat = cmd.status().map_err(|cause| {
606591
Error::chain(
607592
format!(

src/cmd/clone.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::config::{Locked, LockedSource};
1616
use crate::diagnostic::Warnings;
1717
use crate::error::*;
1818
use crate::sess::{DependencyRef, DependencySource, Session, SessionIo};
19-
use crate::{debugln, fmt_path, fmt_pkg, stageln};
19+
use crate::{fmt_path, fmt_pkg, stageln};
2020

2121
/// Clone dependency to a working directory
2222
#[derive(Args, Debug)]
@@ -82,9 +82,9 @@ pub fn run(sess: &Session, path: &Path, args: &CloneArgs) -> Result<()> {
8282
eprintln!("Please manually ensure the correct checkout.");
8383
} else {
8484
let id = sess.dependency_with_name(&args.name.to_lowercase())?;
85-
debugln!("main: obtain checkout {:?}", id);
85+
log::debug!("obtain checkout {:?}", id);
8686
let checkout = rt.block_on(io.checkout(id, false, &[]))?;
87-
debugln!("main: checkout {:#?}", checkout);
87+
log::debug!("checkout {:#?}", checkout);
8888
if let Some(s) = checkout.to_str() {
8989
if !Path::new(s).exists() {
9090
Err(Error::new(format!("`{dep}` path `{s}` does not exist")))?;
@@ -247,7 +247,7 @@ pub fn run(sess: &Session, path: &Path, args: &CloneArgs) -> Result<()> {
247247
// Update any possible workspace symlinks
248248
for (link_path, pkg_name) in &sess.manifest.workspace.package_links {
249249
if pkg_name == dep {
250-
debugln!("main: maintaining link to {} at {:?}", pkg_name, link_path);
250+
log::debug!("maintaining link to {} at {:?}", pkg_name, link_path);
251251

252252
// Determine the checkout path for this package.
253253
let pkg_path = &path.join(path_mod).join(dep);
@@ -270,7 +270,7 @@ pub fn run(sess: &Session, path: &Path, args: &CloneArgs) -> Result<()> {
270270
continue;
271271
}
272272
if link_path.read_link().map(|d| d != pkg_path).unwrap_or(true) {
273-
debugln!("main: removing existing link {:?}", link_path);
273+
log::debug!("removing existing link {:?}", link_path);
274274
remove_symlink_dir(link_path).map_err(|cause| {
275275
Error::chain(
276276
format!("Failed to remove symlink at path {:?}.", link_path),

src/cmd/path.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use clap::Args;
99
use futures::future::join_all;
1010
use tokio::runtime::Runtime;
1111

12-
use crate::debugln;
1312
use crate::error::*;
1413
use crate::sess::{Session, SessionIo};
1514

@@ -43,7 +42,7 @@ pub fn run(sess: &Session, args: &PathArgs) -> Result<()> {
4342

4443
// Check out if requested or not done yet
4544
if args.checkout || !paths.iter().all(|p| p.exists()) {
46-
debugln!("main: obtain checkouts {:?}", ids);
45+
log::debug!("obtain checkouts {:?}", ids);
4746
let rt = Runtime::new()?;
4847
let _checkouts = rt
4948
.block_on(join_all(
@@ -53,7 +52,7 @@ pub fn run(sess: &Session, args: &PathArgs) -> Result<()> {
5352
))
5453
.into_iter()
5554
.collect::<Result<Vec<_>>>()?;
56-
debugln!("main: checkouts {:#?}", _checkouts);
55+
log::debug!("checkouts {:#?}", _checkouts);
5756
}
5857

5958
// Print paths

src/cmd/snapshot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::config::{Dependency, Locked, LockedSource};
1616
use crate::diagnostic::Warnings;
1717
use crate::error::*;
1818
use crate::sess::{DependencySource, Session, SessionIo};
19-
use crate::{debugln, fmt_path, fmt_pkg, stageln};
19+
use crate::{fmt_path, fmt_pkg, stageln};
2020

2121
/// Snapshot the cloned IPs from the working directory into the Bender.lock file
2222
#[derive(Args, Debug)]
@@ -224,7 +224,7 @@ pub fn run(sess: &Session, args: &SnapshotArgs) -> Result<()> {
224224
// Update any possible workspace symlinks
225225
for (link_path, pkg_name) in &sess.manifest.workspace.package_links {
226226
if updated_deps.contains(&pkg_name.as_str()) {
227-
debugln!("main: maintaining link to {} at {:?}", pkg_name, link_path);
227+
log::debug!("maintaining link to {} at {:?}", pkg_name, link_path);
228228

229229
// Determine the checkout path for this package.
230230
let pkg_path = if snapshotted_deps.contains(&pkg_name.as_str()) {
@@ -262,7 +262,7 @@ pub fn run(sess: &Session, args: &SnapshotArgs) -> Result<()> {
262262
continue;
263263
}
264264
if link_path.read_link().map(|d| d != pkg_path).unwrap_or(true) {
265-
debugln!("main: removing existing link {:?}", link_path);
265+
log::debug!("removing existing link {:?}", link_path);
266266
remove_symlink_dir(link_path).map_err(|cause| {
267267
Error::chain(
268268
format!("Failed to remove symlink at path {:?}.", link_path),

src/cmd/update.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use tabwriter::TabWriter;
1212

1313
use crate::cmd;
1414
use crate::config::{Locked, LockedPackage};
15-
use crate::debugln;
1615
use crate::diagnostic::Warnings;
1716
use crate::error::*;
1817
use crate::lockfile::*;
@@ -121,8 +120,8 @@ pub fn run_plain<'ctx>(
121120
sess.root.join("Bender.yml")
122121
)));
123122
}
124-
debugln!(
125-
"main: lockfile {:?} outdated",
123+
log::debug!(
124+
"lockfile {:?} outdated",
126125
sess.root.join("Bender.lock")
127126
);
128127

src/error.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
use std;
77
use std::fmt;
88
use std::sync::Arc;
9-
use std::sync::atomic::AtomicBool;
109

1110
use owo_colors::Style;
1211

13-
pub static ENABLE_DEBUG: AtomicBool = AtomicBool::new(false);
14-
1512
/// Print an error.
1613
#[macro_export]
1714
macro_rules! errorln {
@@ -24,30 +21,12 @@ macro_rules! infoln {
2421
($($arg:tt)*) => { $crate::diagnostic!($crate::error::Severity::Info; $($arg)*); }
2522
}
2623

27-
/// Print debug information. Omitted in release builds.
28-
#[macro_export]
29-
#[cfg(debug_assertions)]
30-
macro_rules! debugln {
31-
($($arg:tt)*) => {
32-
if $crate::error::ENABLE_DEBUG.load(std::sync::atomic::Ordering::Relaxed) {
33-
$crate::diagnostic!($crate::error::Severity::Debug; $($arg)*);
34-
}
35-
}
36-
}
37-
3824
/// Format and print stage progress.
3925
#[macro_export]
4026
macro_rules! stageln {
4127
($stage_name:expr, $($arg:tt)*) => { $crate::diagnostic!($crate::error::Severity::Stage($stage_name); $($arg)*); }
4228
}
4329

44-
/// Print debug information. Omitted in release builds.
45-
#[macro_export]
46-
#[cfg(not(debug_assertions))]
47-
macro_rules! debugln {
48-
($($arg:tt)*) => {};
49-
}
50-
5130
/// Emit a diagnostic message.
5231
#[macro_export]
5332
macro_rules! diagnostic {
@@ -59,7 +38,6 @@ macro_rules! diagnostic {
5938
/// The severity of a diagnostic message.
6039
#[derive(PartialEq, Eq)]
6140
pub enum Severity {
62-
Debug,
6341
Info,
6442
Error,
6543
Stage(&'static str),
@@ -70,7 +48,6 @@ impl fmt::Display for Severity {
7048
let (severity, style) = match *self {
7149
Severity::Error => ("Error:", Style::new().red().bold()),
7250
Severity::Info => ("Info:", Style::new().white().bold()),
73-
Severity::Debug => ("Debug:", Style::new().blue().bold()),
7451
Severity::Stage(name) => (name, Style::new().green().bold()),
7552
};
7653
write!(f, "{:>14}", crate::fmt_with_style!(severity, style))

src/git.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use walkdir::WalkDir;
1818

1919
use crate::progress::{ProgressHandler, monitor_stderr};
2020

21-
use crate::debugln;
2221
use crate::error::*;
2322

2423
/// A git repository.
@@ -101,8 +100,6 @@ impl<'ctx> Git<'ctx> {
101100
}
102101
})?;
103102

104-
debugln!("git: {:?} in {:?}", cmd, self.path);
105-
106103
// Setup Streaming for Stderr (Progress + Error Collection)
107104
// We need to capture stderr in case the command fails, so we collect it while parsing.
108105
let stderr = child.stderr.take().unwrap();

0 commit comments

Comments
 (0)