]> git.proxmox.com Git - cargo.git/commitdiff
fix: change to `update -w` per feedback
authorCharlie Ozinga <ozchaz@gmail.com>
Fri, 6 Nov 2020 21:44:06 +0000 (14:44 -0700)
committerCharlie Ozinga <ozchaz@gmail.com>
Fri, 6 Nov 2020 21:44:06 +0000 (14:44 -0700)
12 files changed:
src/bin/cargo/commands/mod.rs
src/bin/cargo/commands/sync_lockfile.rs [deleted file]
src/bin/cargo/commands/update.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/mod.rs
src/doc/man/cargo-update.md
src/doc/man/generated_txt/cargo-update.txt
src/doc/src/commands/cargo-update.md
src/etc/man/cargo-update.1
tests/testsuite/main.rs
tests/testsuite/sync_lockfile.rs [deleted file]
tests/testsuite/update.rs

index 4581150f7a1038de91e4aa9c75d352e35ae356cd..d668809f060e8967f09bbeb73aa0175c375961da 100644 (file)
@@ -8,7 +8,6 @@ pub fn builtin() -> Vec<App> {
         clean::cli(),
         doc::cli(),
         fetch::cli(),
-        sync_lockfile::cli(),
         fix::cli(),
         generate_lockfile::cli(),
         git_checkout::cli(),
@@ -46,7 +45,6 @@ pub fn builtin_exec(cmd: &str) -> Option<fn(&mut Config, &ArgMatches<'_>) -> Cli
         "clean" => clean::exec,
         "doc" => doc::exec,
         "fetch" => fetch::exec,
-        "sync-lockfile" => sync_lockfile::exec,
         "fix" => fix::exec,
         "generate-lockfile" => generate_lockfile::exec,
         "git-checkout" => git_checkout::exec,
@@ -103,7 +101,6 @@ pub mod run;
 pub mod rustc;
 pub mod rustdoc;
 pub mod search;
-pub mod sync_lockfile;
 pub mod test;
 pub mod tree;
 pub mod uninstall;
diff --git a/src/bin/cargo/commands/sync_lockfile.rs b/src/bin/cargo/commands/sync_lockfile.rs
deleted file mode 100644 (file)
index 16c8b71..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-use crate::command_prelude::*;
-
-use cargo::ops;
-use cargo::ops::SyncLockfileOptions;
-
-pub fn cli() -> App {
-    subcommand("sync-lockfile")
-        .about("Synchronize the lockfile to the package")
-        .arg(opt("quiet", "No output printed to stdout").short("q"))
-        .arg_manifest_path()
-        .arg_target_triple("Sync the lockfile for the target triple")
-        .after_help("Run `cargo help sync-lockfile` for more detailed information.\n")
-}
-
-pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
-    let ws = args.workspace(config)?;
-
-    let opts = SyncLockfileOptions {
-        config,
-        targets: args.targets(),
-    };
-    let _ = ops::sync_lockfile(&ws, &opts)?;
-    Ok(())
-}
index 34bab9f757ee7dfb03dd9d2f0227542718640f32..9a0b99b9181dd53c6c579700be232f52fedf45b3 100644 (file)
@@ -7,6 +7,7 @@ pub fn cli() -> App {
     subcommand("update")
         .about("Update dependencies as recorded in the local lock file")
         .arg(opt("quiet", "No output printed to stdout").short("q"))
+        .arg(opt("workspace", "Only update the workspace pakcages").short("w"))
         .arg_package_spec_simple("Package to update")
         .arg(opt(
             "aggressive",
@@ -30,6 +31,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
         precise: args.value_of("precise"),
         to_update: values(args, "package"),
         dry_run: args.is_present("dry-run"),
+        workspace: args.is_present("workspace"),
         config,
     };
     ops::update_lockfile(&ws, &update_opts)?;
index a86b34e3ae06a98688a8866cb92f737501f9f1ff..3c84edfe92990e28ec686b3a0e4bb9beebe262bf 100644 (file)
@@ -17,6 +17,7 @@ pub struct UpdateOptions<'a> {
     pub precise: Option<&'a str>,
     pub aggressive: bool,
     pub dry_run: bool,
+    pub workspace: bool,
 }
 
 pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> {
@@ -35,6 +36,19 @@ pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> {
 }
 
 pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> {
+    if opts.workspace {
+      if opts.aggressive {
+        anyhow::bail!("cannot specify aggressive for workspace updates");
+      }
+      if opts.precise.is_some() {
+        anyhow::bail!("cannot specify precise for workspace updates");
+      }
+
+      ws.emit_warnings()?;
+      let (_packages, _resolve) = ops::resolve_ws(ws)?;
+      return Ok(())
+    }
+
     if opts.aggressive && opts.precise.is_some() {
         anyhow::bail!("cannot specify both aggressive and precise simultaneously")
     }
index 0d7656516ad49cb399dbf3b51096236f3abf3ee5..dc45fc41dcb6584179352cd03462c956ef513113 100644 (file)
@@ -15,7 +15,6 @@ pub use self::cargo_package::{package, PackageOpts};
 pub use self::cargo_pkgid::pkgid;
 pub use self::cargo_read_manifest::{read_package, read_packages};
 pub use self::cargo_run::run;
-pub use self::cargo_sync_lockfile::{sync_lockfile, SyncLockfileOptions};
 pub use self::cargo_test::{run_benches, run_tests, TestOptions};
 pub use self::cargo_uninstall::uninstall;
 pub use self::fix::{fix, fix_maybe_exec_rustc, FixOptions};
@@ -42,7 +41,6 @@ mod cargo_package;
 mod cargo_pkgid;
 mod cargo_read_manifest;
 mod cargo_run;
-mod cargo_sync_lockfile;
 mod cargo_test;
 mod cargo_uninstall;
 mod common_for_install_and_uninstall;
index 3bca1982c662487dc2ad6388cebda1d2687c7056..4be609d83e405ddd306842271ead68e4b0dfc200 100644 (file)
@@ -44,6 +44,14 @@ the package to. If the package comes from a git repository, this can be a git
 revision (such as a SHA hash or tag).
 {{/option}}
 
+{{#option "`-w`" "`--workspace`" }}
+Attempt to update only packages defined in the workspace. Other packages
+are updated only if they don't already exist in the lockfile. This
+option is useful for updating `Cargo.lock` after you've changed version
+numbers in `Cargo.toml`.
+Cannot be used with `--precise` or `--aggressive`.
+{{/option}}
+
 {{#option "`--dry-run`" }}
 Displays what would be updated, but doesn't actually write the lockfile.
 {{/option}}
index be3e8067962de208ea8b361fc750b9ec86de1121..c8225b39955537ce893adb94f098ca2707ce4939 100644 (file)
@@ -35,6 +35,13 @@ OPTIONS
            to set the package to. If the package comes from a git repository,
            this can be a git revision (such as a SHA hash or tag).
 
+       -w, --workspace
+           Attempt to update only packages defined in the workspace. Other
+           packages are updated only if they don't already exist in the
+           lockfile. This option is useful for updating Cargo.lock after you've
+           changed version numbers in Cargo.toml. Cannot be used with --precise
+           or --aggressive.
+
        --dry-run
            Displays what would be updated, but doesn't actually write the
            lockfile.
index ac2f7a368534198ea6354c44282bf3733dc8b2b2..5199e210ea542f1c92cdfa9ce96f32f34b785f56 100644 (file)
@@ -43,6 +43,15 @@ the package to. If the package comes from a git repository, this can be a git
 revision (such as a SHA hash or tag).</dd>
 
 
+<dt class="option-term" id="option-cargo-update--w"><a class="option-anchor" href="#option-cargo-update--w"></a><code>-w</code></dt>
+<dt class="option-term" id="option-cargo-update---workspace"><a class="option-anchor" href="#option-cargo-update---workspace"></a><code>--workspace</code></dt>
+<dd class="option-desc">Attempt to update only packages defined in the workspace. Other packages
+are updated only if they don't already exist in the lockfile. This
+option is useful for updating <code>Cargo.lock</code> after you've changed version
+numbers in <code>Cargo.toml</code>.
+Cannot be used with <code>--precise</code> or <code>--aggressive</code>.</dd>
+
+
 <dt class="option-term" id="option-cargo-update---dry-run"><a class="option-anchor" href="#option-cargo-update---dry-run"></a><code>--dry-run</code></dt>
 <dd class="option-desc">Displays what would be updated, but doesn't actually write the lockfile.</dd>
 
index 1d531394e2c94340ba506c11bca5cd8871569164..94ef3e13a73c02837d2d682bb8b7282cf028a1e4 100644 (file)
@@ -42,6 +42,16 @@ the package to. If the package comes from a git repository, this can be a git
 revision (such as a SHA hash or tag).
 .RE
 .sp
+\fB\-w\fR, 
+\fB\-\-workspace\fR
+.RS 4
+Attempt to update only packages defined in the workspace. Other packages
+are updated only if they don't already exist in the lockfile. This
+option is useful for updating \fBCargo.lock\fR after you've changed version
+numbers in \fBCargo.toml\fR\&.
+Cannot be used with \fB\-\-precise\fR or \fB\-\-aggressive\fR\&.
+.RE
+.sp
 \fB\-\-dry\-run\fR
 .RS 4
 Displays what would be updated, but doesn't actually write the lockfile.
index c750184613e3959a86274bc5aaa33ae3f9a58fdb..3fc5e492b3c680d87fc9c9cc5cdc52cba652b66a 100644 (file)
@@ -109,7 +109,6 @@ mod rustflags;
 mod search;
 mod shell_quoting;
 mod standard_lib;
-mod sync_lockfile;
 mod test;
 mod timings;
 mod tool_paths;
diff --git a/tests/testsuite/sync_lockfile.rs b/tests/testsuite/sync_lockfile.rs
deleted file mode 100644 (file)
index 6b938a4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//! Tests for the `cargo sync-lockfile` command.
-
-use cargo_test_support::project;
-
-#[cargo_test]
-fn sync_after_generate() {
-    let p = project().file("src/main.rs", "fn main() {}").build();
-    p.cargo("generate-lockfile").run();
-    let lock1 = p.read_lockfile();
-
-    // add a dep
-    p.change_file(
-        "Cargo.toml",
-        r#"
-            [package]
-            name = "foo"
-            authors = []
-            version = "0.0.2"
-        "#,
-    );
-    p.cargo("sync-lockfile").run();
-    let lock2 = p.read_lockfile();
-    assert_ne!(lock1, lock2);
-    assert!(lock1.contains("0.0.1"));
-    assert!(lock2.contains("0.0.2"));
-    assert!(!lock1.contains("0.0.2"));
-    assert!(!lock2.contains("0.0.1"));
-}
index dd5b3ff5afb3530f465235aaf7709223984ca7c5..6148bd3d6f25307458d267e1d6e4074a52909c45 100644 (file)
@@ -649,3 +649,28 @@ fn dry_run_update() {
     let new_lockfile = p.read_lockfile();
     assert_eq!(old_lockfile, new_lockfile)
 }
+
+#[cargo_test]
+fn workspace_only() {
+    let p = project().file("src/main.rs", "fn main() {}").build();
+    p.cargo("generate-lockfile").run();
+    let lock1 = p.read_lockfile();
+
+    p.change_file(
+        "Cargo.toml",
+        r#"
+            [package]
+            name = "foo"
+            authors = []
+            version = "0.0.2"
+        "#,
+    );
+    p.cargo("update --workspace").run();
+    let lock2 = p.read_lockfile();
+
+    assert_ne!(lock1, lock2);
+    assert!(lock1.contains("0.0.1"));
+    assert!(lock2.contains("0.0.2"));
+    assert!(!lock1.contains("0.0.2"));
+    assert!(!lock2.contains("0.0.1"));
+}