From edfc1437e3dbcff4d35163e33614d8fd59dab49e Mon Sep 17 00:00:00 2001 From: Nils Asmussen Date: Wed, 4 Sep 2019 20:54:05 +0200 Subject: [PATCH] Don't print "waiting for file lock" message in quiet mode --- src/cli.rs | 4 ++++ src/flock.rs | 28 ++++++++++++++++------------ src/lib.rs | 3 ++- src/xargo.rs | 4 ++-- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 48b601c..a5a3cbf 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -20,6 +20,10 @@ impl Args { self.manifest_path.as_ref().map(|s| &**s) } + pub fn quiet(&self) -> bool { + self.all.iter().any(|a| a == "--quiet" || a == "-q") + } + pub fn verbose(&self) -> bool { self.all .iter() diff --git a/src/flock.rs b/src/flock.rs index 147ba03..966c228 100644 --- a/src/flock.rs +++ b/src/flock.rs @@ -49,18 +49,19 @@ impl FileLock { pub struct Filesystem { path: PathBuf, + quiet: bool, } impl Filesystem { - pub fn new(path: PathBuf) -> Filesystem { - Filesystem { path: path } + pub fn new(path: PathBuf, quiet: bool) -> Filesystem { + Filesystem { path: path, quiet: quiet } } pub fn join(&self, other: T) -> Filesystem where T: AsRef, { - Filesystem::new(self.path.join(other)) + Filesystem::new(self.path.join(other), self.quiet) } pub fn open_ro

(&self, path: P, msg: &str) -> io::Result @@ -107,12 +108,12 @@ impl Filesystem { match state { State::Exclusive => { - acquire(msg, &path, &|| f.try_lock_exclusive(), &|| { + acquire(msg, &path, self.quiet, &|| f.try_lock_exclusive(), &|| { f.lock_exclusive() })?; } State::Shared => { - acquire(msg, &path, &|| f.try_lock_shared(), &|| f.lock_shared())?; + acquire(msg, &path, self.quiet, &|| f.try_lock_shared(), &|| f.lock_shared())?; } } @@ -136,6 +137,7 @@ impl Drop for FileLock { fn acquire( msg: &str, path: &Path, + quiet: bool, try: &dyn Fn() -> io::Result<()>, block: &dyn Fn() -> io::Result<()>, ) -> io::Result<()> { @@ -178,13 +180,15 @@ fn acquire( } } - writeln!( - io::stderr(), - "{:>12} waiting for file lock on {}", - "Blocking", - msg - ) - .ok(); + if !quiet { + writeln!( + io::stderr(), + "{:>12} waiting for file lock on {}", + "Blocking", + msg + ) + .ok(); + } block() } diff --git a/src/lib.rs b/src/lib.rs index 396749c..562b4bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,6 +145,7 @@ fn run(command_name: &str) -> Result> { fn build(args: cli::Args, command_name: &str) -> Result { let verbose = args.verbose(); + let quiet = args.quiet(); let meta = rustc::version(); let cd = CurrentDirectory::get()?; let config = cargo::config()?; @@ -207,7 +208,7 @@ fn build(args: cli::Args, command_name: &str) -> Result { } if let Some(cmode) = cmode { - let home = xargo::home(root, &crate_config)?; + let home = xargo::home(root, &crate_config, quiet)?; let rustflags = cargo::rustflags(config.as_ref(), cmode.triple())?; sysroot::update( diff --git a/src/xargo.rs b/src/xargo.rs index 0033847..4dd72dd 100644 --- a/src/xargo.rs +++ b/src/xargo.rs @@ -74,7 +74,7 @@ impl Home { } } -pub fn home(root: &Path, config: &Config) -> Result { +pub fn home(root: &Path, config: &Config, quiet: bool) -> Result { let path = if let Ok(path) = env::var("XBUILD_SYSROOT_PATH") { PathBuf::from(path) } else { @@ -84,6 +84,6 @@ pub fn home(root: &Path, config: &Config) -> Result { }; Ok(Home { - path: Filesystem::new(path), + path: Filesystem::new(path, quiet), }) }