From 28ee3f7a284adb6950a177bebf27aa67ab491404 Mon Sep 17 00:00:00 2001 From: Artur Sinila Date: Thu, 11 Nov 2021 16:37:42 +0200 Subject: [PATCH] Imply `--workspace` when running in workspace root Aims for saner defaults & to match `cargo update` behavior --- README.md | 1 + src/bin/set-version/main.rs | 3 ++- src/bin/upgrade/main.rs | 4 +++- src/manifest.rs | 7 ++++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8355abe51..3f90923a53 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,7 @@ supported. Git/path dependencies will be ignored. All packages in the workspace will be upgraded if the `--workspace` flag is supplied. The `--workspace` flag may be supplied in the presence of a virtual manifest. +Running in workspace root automatically implies `--workspace` If the '--to-lockfile' flag is supplied, all dependencies will be upgraded to the currently locked version as recorded in the Cargo.lock file. This flag requires that the Cargo.lock file is diff --git a/src/bin/set-version/main.rs b/src/bin/set-version/main.rs index 8d9d6e66f4..fb32ce074e 100644 --- a/src/bin/set-version/main.rs +++ b/src/bin/set-version/main.rs @@ -75,7 +75,8 @@ fn process(args: Args) -> Result<()> { if all { deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?; } - let all = workspace || all; + let all = workspace || all || LocalManifest::find(&None)?.is_virtual(); + let manifests = if all { Manifests::get_all(&manifest_path) } else if let Some(ref pkgid) = pkgid { diff --git a/src/bin/upgrade/main.rs b/src/bin/upgrade/main.rs index 2f82e8e2b0..ee8464f951 100644 --- a/src/bin/upgrade/main.rs +++ b/src/bin/upgrade/main.rs @@ -94,6 +94,7 @@ struct Args { all: bool, /// Upgrade all packages in the workspace. + /// Implied by default when running in a directory with virtual manifest. #[structopt(long = "workspace", conflicts_with = "all", conflicts_with = "pkgid")] workspace: bool, @@ -468,7 +469,8 @@ fn process(args: Args) -> Result<()> { deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?; } - let all = workspace || all; + // Running in workspace root automatically implies `--workspace` + let all = workspace || all || LocalManifest::find(&None)?.is_virtual(); if !args.offline && !to_lockfile && std::env::var("CARGO_IS_TEST").is_err() { let url = registry_url(&find(&manifest_path)?, None)?; diff --git a/src/manifest.rs b/src/manifest.rs index 85ff1c94e9..67273370a4 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -293,10 +293,15 @@ impl LocalManifest { Ok(LocalManifest { manifest, path }) } + /// Check if local manifest is virtual, i. e. corresponds to workspace root + pub fn is_virtual(&self) -> bool { + !self.data["workspace"].is_none() + } + /// Write changes back to the file pub fn write(&self) -> Result<()> { if self.manifest.data["package"].is_none() && self.manifest.data["project"].is_none() { - if !self.manifest.data["workspace"].is_none() { + if self.is_virtual() { return Err(ErrorKind::UnexpectedRootManifest.into()); } else { return Err(ErrorKind::InvalidManifest.into());