Skip to content

Commit

Permalink
fix: change to update -w per feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chaaz committed Nov 6, 2020
1 parent 5b92843 commit 9589d2c
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 58 deletions.
3 changes: 0 additions & 3 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 0 additions & 24 deletions src/bin/cargo/commands/sync_lockfile.rs

This file was deleted.

2 changes: 2 additions & 0 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)?;
Expand Down
14 changes: 14 additions & 0 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -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")
}
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/doc/man/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/doc/src/commands/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
10 changes: 10 additions & 0 deletions src/etc/man/cargo-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ mod rustflags;
mod search;
mod shell_quoting;
mod standard_lib;
mod sync_lockfile;
mod test;
mod timings;
mod tool_paths;
Expand Down
28 changes: 0 additions & 28 deletions tests/testsuite/sync_lockfile.rs

This file was deleted.

25 changes: 25 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

0 comments on commit 9589d2c

Please sign in to comment.