Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --quiet flag that suppresses "waiting for file lock" message #43

Merged
merged 1 commit into from Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cli.rs
Expand Up @@ -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()
Expand Down
28 changes: 16 additions & 12 deletions src/flock.rs
Expand Up @@ -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<T>(&self, other: T) -> Filesystem
where
T: AsRef<Path>,
{
Filesystem::new(self.path.join(other))
Filesystem::new(self.path.join(other), self.quiet)
}

pub fn open_ro<P>(&self, path: P, msg: &str) -> io::Result<FileLock>
Expand Down Expand Up @@ -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())?;
}
}

Expand All @@ -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<()> {
Expand Down Expand Up @@ -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()
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Expand Up @@ -145,6 +145,7 @@ fn run(command_name: &str) -> Result<Option<ExitStatus>> {

fn build(args: cli::Args, command_name: &str) -> Result<ExitStatus> {
let verbose = args.verbose();
let quiet = args.quiet();
let meta = rustc::version();
let cd = CurrentDirectory::get()?;
let config = cargo::config()?;
Expand Down Expand Up @@ -207,7 +208,7 @@ fn build(args: cli::Args, command_name: &str) -> Result<ExitStatus> {
}

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(
Expand Down
4 changes: 2 additions & 2 deletions src/xargo.rs
Expand Up @@ -74,7 +74,7 @@ impl Home {
}
}

pub fn home(root: &Path, config: &Config) -> Result<Home> {
pub fn home(root: &Path, config: &Config, quiet: bool) -> Result<Home> {
let path = if let Ok(path) = env::var("XBUILD_SYSROOT_PATH") {
PathBuf::from(path)
} else {
Expand All @@ -84,6 +84,6 @@ pub fn home(root: &Path, config: &Config) -> Result<Home> {
};

Ok(Home {
path: Filesystem::new(path),
path: Filesystem::new(path, quiet),
})
}