From 383d1b245488490626674d6ef71a435888349ee7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 22 Sep 2022 10:13:45 -0500 Subject: [PATCH 1/5] test: Show current workspace inheritance behavior --- tests/cargo-upgrade/main.rs | 1 + .../workspace_inheritance/in/Cargo.lock | 137 ++++++++++++++++++ .../workspace_inheritance/in/Cargo.toml | 9 ++ .../workspace_inheritance/in/dummy.rs | 0 .../in/explicit/four/Cargo.toml | 9 ++ .../in/implicit/three/Cargo.toml | 9 ++ .../workspace_inheritance/in/one/Cargo.toml | 10 ++ .../workspace_inheritance/in/two/Cargo.toml | 10 ++ .../workspace_inheritance/mod.rs | 25 ++++ .../workspace_inheritance/out/Cargo.lock | 38 +++++ .../workspace_inheritance/out/Cargo.toml | 9 ++ .../workspace_inheritance/out/dummy.rs | 0 .../out/explicit/four/Cargo.toml | 9 ++ .../out/implicit/three/Cargo.toml | 9 ++ .../workspace_inheritance/out/one/Cargo.toml | 10 ++ .../workspace_inheritance/out/two/Cargo.toml | 10 ++ .../workspace_inheritance/stderr.log | 7 + .../workspace_inheritance/stdout.log | 0 18 files changed, 302 insertions(+) create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/Cargo.lock create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/dummy.rs create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/explicit/four/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/implicit/three/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/one/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/in/two/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/mod.rs create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/dummy.rs create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/explicit/four/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/implicit/three/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/one/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/out/two/Cargo.toml create mode 100644 tests/cargo-upgrade/workspace_inheritance/stderr.log create mode 100644 tests/cargo-upgrade/workspace_inheritance/stdout.log diff --git a/tests/cargo-upgrade/main.rs b/tests/cargo-upgrade/main.rs index 0fe0413639..ff7c831605 100644 --- a/tests/cargo-upgrade/main.rs +++ b/tests/cargo-upgrade/main.rs @@ -34,6 +34,7 @@ mod upgrade_renamed; mod upgrade_verbose; mod upgrade_workspace; mod virtual_manifest; +mod workspace_inheritance; mod workspace_member_cwd; mod workspace_member_manifest_path; diff --git a/tests/cargo-upgrade/workspace_inheritance/in/Cargo.lock b/tests/cargo-upgrade/workspace_inheritance/in/Cargo.lock new file mode 100644 index 0000000000..59bda66005 --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/in/Cargo.lock @@ -0,0 +1,137 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "four" +version = "0.1.0" +dependencies = [ + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "log" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "one" +version = "0.1.0" +dependencies = [ + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", + "three 0.1.0", +] + +[[package]] +name = "rand" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "three" +version = "0.1.0" +dependencies = [ + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "two" +version = "0.1.0" +dependencies = [ + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e32a70cf75e5846d53a673923498228bbec6a8624708a9ea5645f075d6276122" +"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" +"checksum log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f91d813fb009895c01b1b5c095fc88aea17138355bc0e4d53a277c466f62161f" +"checksum rand 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28cb601e872bcf1e2667d0433d2b5f2c53d37a6ca05e948fd1a977fa087e42e3" +"checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/tests/cargo-upgrade/workspace_inheritance/in/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/in/Cargo.toml new file mode 100644 index 0000000000..2ac75c86ca --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/in/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +members = [ + "one", + "two", + "explicit/*" +] + +[workspace.dependencies] +my-package = "0.1.1" diff --git a/tests/cargo-upgrade/workspace_inheritance/in/dummy.rs b/tests/cargo-upgrade/workspace_inheritance/in/dummy.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/cargo-upgrade/workspace_inheritance/in/explicit/four/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/in/explicit/four/Cargo.toml new file mode 100644 index 0000000000..9037dfa185 --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/in/explicit/four/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "four" +version = "0.1.0" + +[lib] +path = "../../dummy.rs" + +[dependencies] +my-package.workspace = true diff --git a/tests/cargo-upgrade/workspace_inheritance/in/implicit/three/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/in/implicit/three/Cargo.toml new file mode 100644 index 0000000000..149a1cf48e --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/in/implicit/three/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "three" +version = "0.1.0" + +[lib] +path = "../../dummy.rs" + +[dependencies] +my-package.workspace = true diff --git a/tests/cargo-upgrade/workspace_inheritance/in/one/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/in/one/Cargo.toml new file mode 100644 index 0000000000..0554254e4e --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/in/one/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "one" +version = "0.1.0" + +[lib] +path = "../dummy.rs" + +[dependencies] +my-package.workspace = true +three = { path = "../implicit/three"} diff --git a/tests/cargo-upgrade/workspace_inheritance/in/two/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/in/two/Cargo.toml new file mode 100644 index 0000000000..3fb23c2211 --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/in/two/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "two" +version = "0.1.0" + +[[bin]] +name = "two" +path = "../dummy.rs" + +[dependencies] +my-package.workspace = true diff --git a/tests/cargo-upgrade/workspace_inheritance/mod.rs b/tests/cargo-upgrade/workspace_inheritance/mod.rs new file mode 100644 index 0000000000..60cc78b4bc --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/mod.rs @@ -0,0 +1,25 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::Project; + +use crate::init_registry; +use crate::CargoCommand; +use cargo_test_support::curr_dir; + +#[cargo_test] +fn case() { + init_registry(); + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("upgrade") + .args(["--incompatible"]) + .current_dir(&cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock new file mode 100644 index 0000000000..e1b18d68f8 --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock @@ -0,0 +1,38 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "four" +version = "0.1.0" +dependencies = [ + "my-package", +] + +[[package]] +name = "my-package" +version = "0.1.1+my-package" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61758fedb08b81e9c6967f0661a54feb83fb38eb4bde3614119fbc1d03c1cedf" + +[[package]] +name = "one" +version = "0.1.0" +dependencies = [ + "my-package", + "three", +] + +[[package]] +name = "three" +version = "0.1.0" +dependencies = [ + "my-package", +] + +[[package]] +name = "two" +version = "0.1.0" +dependencies = [ + "my-package", +] diff --git a/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml new file mode 100644 index 0000000000..2ac75c86ca --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +members = [ + "one", + "two", + "explicit/*" +] + +[workspace.dependencies] +my-package = "0.1.1" diff --git a/tests/cargo-upgrade/workspace_inheritance/out/dummy.rs b/tests/cargo-upgrade/workspace_inheritance/out/dummy.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/cargo-upgrade/workspace_inheritance/out/explicit/four/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/out/explicit/four/Cargo.toml new file mode 100644 index 0000000000..9037dfa185 --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/out/explicit/four/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "four" +version = "0.1.0" + +[lib] +path = "../../dummy.rs" + +[dependencies] +my-package.workspace = true diff --git a/tests/cargo-upgrade/workspace_inheritance/out/implicit/three/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/out/implicit/three/Cargo.toml new file mode 100644 index 0000000000..149a1cf48e --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/out/implicit/three/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "three" +version = "0.1.0" + +[lib] +path = "../../dummy.rs" + +[dependencies] +my-package.workspace = true diff --git a/tests/cargo-upgrade/workspace_inheritance/out/one/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/out/one/Cargo.toml new file mode 100644 index 0000000000..0554254e4e --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/out/one/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "one" +version = "0.1.0" + +[lib] +path = "../dummy.rs" + +[dependencies] +my-package.workspace = true +three = { path = "../implicit/three"} diff --git a/tests/cargo-upgrade/workspace_inheritance/out/two/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/out/two/Cargo.toml new file mode 100644 index 0000000000..3fb23c2211 --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/out/two/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "two" +version = "0.1.0" + +[[bin]] +name = "two" +path = "../dummy.rs" + +[dependencies] +my-package.workspace = true diff --git a/tests/cargo-upgrade/workspace_inheritance/stderr.log b/tests/cargo-upgrade/workspace_inheritance/stderr.log new file mode 100644 index 0000000000..a04fc3df9c --- /dev/null +++ b/tests/cargo-upgrade/workspace_inheritance/stderr.log @@ -0,0 +1,7 @@ + Updating '[ROOTURL]/registry' index + Checking four's dependencies + Checking one's dependencies + Checking three's dependencies + Checking two's dependencies +note: Re-run with `--verbose` to show all dependencies + local: three diff --git a/tests/cargo-upgrade/workspace_inheritance/stdout.log b/tests/cargo-upgrade/workspace_inheritance/stdout.log new file mode 100644 index 0000000000..e69de29bb2 From 6209284d16e3a50f78966b64fc94095c55150eb9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 22 Sep 2022 10:28:38 -0500 Subject: [PATCH 2/5] refactor(upgrade): Clarify which manifest we are talking about --- src/bin/upgrade/upgrade.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/upgrade/upgrade.rs b/src/bin/upgrade/upgrade.rs index 34a4430a1a..0d7341d1ab 100644 --- a/src/bin/upgrade/upgrade.rs +++ b/src/bin/upgrade/upgrade.rs @@ -163,7 +163,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { } let metadata = resolve_ws(args.manifest_path.as_deref(), args.locked, args.offline)?; - let manifest_path = metadata.workspace_root.as_std_path().join("Cargo.toml"); + let root_manifest_path = metadata.workspace_root.as_std_path().join("Cargo.toml"); let manifests = find_ws_members(&metadata); let selected_dependencies = args @@ -442,7 +442,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { } else { // Ensure lock file is updated and collect data for `recursive` let offline = true; // index should already be updated - let metadata = resolve_ws(Some(&manifest_path), args.locked, offline)?; + let metadata = resolve_ws(Some(&root_manifest_path), args.locked, offline)?; let mut locked = metadata.packages; let precise_deps = selected_dependencies @@ -469,7 +469,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { { let mut cmd = std::process::Command::new("cargo"); cmd.arg("update"); - cmd.arg("--manifest-path").arg(&manifest_path); + cmd.arg("--manifest-path").arg(&root_manifest_path); if args.locked { cmd.arg("--locked"); } @@ -496,7 +496,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { // Update data for `recursive` with precise_deps let offline = true; // index should already be updated - let metadata = resolve_ws(Some(&manifest_path), args.locked, offline)?; + let metadata = resolve_ws(Some(&root_manifest_path), args.locked, offline)?; locked = metadata.packages; } @@ -504,7 +504,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { shell_status("Upgrading", "git dependencies")?; let mut cmd = std::process::Command::new("cargo"); cmd.arg("update"); - cmd.arg("--manifest-path").arg(&manifest_path); + cmd.arg("--manifest-path").arg(&root_manifest_path); if args.locked { cmd.arg("--locked"); } @@ -533,7 +533,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { // Update data for `recursive` with precise_deps let offline = true; // index should already be updated - let metadata = resolve_ws(Some(&manifest_path), args.locked, offline)?; + let metadata = resolve_ws(Some(&root_manifest_path), args.locked, offline)?; locked = metadata.packages; } @@ -541,7 +541,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { shell_status("Upgrading", "recursive dependencies")?; let mut cmd = std::process::Command::new("cargo"); cmd.arg("update"); - cmd.arg("--manifest-path").arg(&manifest_path); + cmd.arg("--manifest-path").arg(&root_manifest_path); if args.locked { cmd.arg("--locked"); } From 12ee3a8f11b5c0d4610020471988310c1624f4e6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 22 Sep 2022 10:30:34 -0500 Subject: [PATCH 3/5] refactor(upgrade): Don't restrict processing to packages --- src/bin/upgrade/upgrade.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bin/upgrade/upgrade.rs b/src/bin/upgrade/upgrade.rs index 0d7341d1ab..2c9aff428e 100644 --- a/src/bin/upgrade/upgrade.rs +++ b/src/bin/upgrade/upgrade.rs @@ -165,6 +165,10 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { let metadata = resolve_ws(args.manifest_path.as_deref(), args.locked, args.offline)?; let root_manifest_path = metadata.workspace_root.as_std_path().join("Cargo.toml"); let manifests = find_ws_members(&metadata); + let manifests = manifests + .into_iter() + .map(|p| (p.name, p.manifest_path.as_std_path().to_owned())) + .collect::>(); let selected_dependencies = args .package @@ -182,12 +186,11 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { let mut pinned_present = false; let mut incompatible_present = false; let mut uninteresting_crates = BTreeSet::new(); - for package in &manifests { - let mut manifest = LocalManifest::try_new(package.manifest_path.as_std_path())?; + for (pkg_name, manifest_path) in &manifests { + let mut manifest = LocalManifest::try_new(manifest_path)?; let mut crate_modified = false; let mut table = Vec::new(); - let manifest_path = manifest.path.clone(); - shell_status("Checking", &format!("{}'s dependencies", package.name))?; + shell_status("Checking", &format!("{}'s dependencies", pkg_name))?; for dep_table in manifest.get_dependency_tables_mut() { for (dep_key, dep_item) in dep_table.iter_mut() { let mut reason = None; From 0c24866d65a68e2b901ecdfea8fbf88a10d985b0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 22 Sep 2022 10:49:39 -0500 Subject: [PATCH 4/5] feat(upgrade): Process workspace.dependencies --- src/bin/upgrade/upgrade.rs | 8 ++++- src/manifest.rs | 29 ++++++++----------- tests/cargo-upgrade/lockfile/stderr.log | 1 + tests/cargo-upgrade/upgrade_all/stderr.log | 1 + .../upgrade_workspace/stderr.log | 1 + .../cargo-upgrade/virtual_manifest/stderr.log | 1 + .../workspace_inheritance/out/Cargo.lock | 4 +-- .../workspace_inheritance/out/Cargo.toml | 2 +- .../workspace_inheritance/stderr.log | 5 ++++ .../workspace_member_cwd/stderr.log | 1 + .../workspace_member_manifest_path/stderr.log | 1 + 11 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/bin/upgrade/upgrade.rs b/src/bin/upgrade/upgrade.rs index 2c9aff428e..dd724ba2ba 100644 --- a/src/bin/upgrade/upgrade.rs +++ b/src/bin/upgrade/upgrade.rs @@ -165,10 +165,16 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { let metadata = resolve_ws(args.manifest_path.as_deref(), args.locked, args.offline)?; let root_manifest_path = metadata.workspace_root.as_std_path().join("Cargo.toml"); let manifests = find_ws_members(&metadata); - let manifests = manifests + let mut manifests = manifests .into_iter() .map(|p| (p.name, p.manifest_path.as_std_path().to_owned())) .collect::>(); + if !manifests.iter().any(|(_, p)| *p == root_manifest_path) { + manifests.insert( + 0, + ("virtual workspace".to_owned(), root_manifest_path.clone()), + ); + } let selected_dependencies = args .package diff --git a/src/manifest.rs b/src/manifest.rs index be9ce6b584..9be84bb9ca 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -229,23 +229,6 @@ impl LocalManifest { /// Write changes back to the file pub fn write(&self) -> CargoResult<()> { - if !self.manifest.data.contains_key("package") - && !self.manifest.data.contains_key("project") - { - if self.manifest.data.contains_key("workspace") { - anyhow::bail!( - "Found virtual manifest at {}, but this command requires running against an \ - actual package in this workspace.", - self.path.display() - ); - } else { - anyhow::bail!( - "Missing expected `package` or `project` fields in {}", - self.path.display() - ); - } - } - let s = self.manifest.data.to_string(); let new_contents_bytes = s.as_bytes(); @@ -302,6 +285,18 @@ impl LocalManifest { .any(|kind| kind.kind_table() == k.get()) { v.as_table_like_mut().into_iter().collect::>() + } else if k == "workspace" { + v.as_table_like_mut() + .unwrap() + .iter_mut() + .filter_map(|(k, v)| { + if k.get() == "dependencies" { + v.as_table_like_mut() + } else { + None + } + }) + .collect::>() } else if k == "target" { v.as_table_like_mut() .unwrap() diff --git a/tests/cargo-upgrade/lockfile/stderr.log b/tests/cargo-upgrade/lockfile/stderr.log index 8bb26b767c..430e288a7f 100644 --- a/tests/cargo-upgrade/lockfile/stderr.log +++ b/tests/cargo-upgrade/lockfile/stderr.log @@ -1,4 +1,5 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies Checking four's dependencies name old req compatible latest new req ==== ======= ========== ====== ======= diff --git a/tests/cargo-upgrade/upgrade_all/stderr.log b/tests/cargo-upgrade/upgrade_all/stderr.log index 8bb26b767c..430e288a7f 100644 --- a/tests/cargo-upgrade/upgrade_all/stderr.log +++ b/tests/cargo-upgrade/upgrade_all/stderr.log @@ -1,4 +1,5 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies Checking four's dependencies name old req compatible latest new req ==== ======= ========== ====== ======= diff --git a/tests/cargo-upgrade/upgrade_workspace/stderr.log b/tests/cargo-upgrade/upgrade_workspace/stderr.log index 8bb26b767c..430e288a7f 100644 --- a/tests/cargo-upgrade/upgrade_workspace/stderr.log +++ b/tests/cargo-upgrade/upgrade_workspace/stderr.log @@ -1,4 +1,5 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies Checking four's dependencies name old req compatible latest new req ==== ======= ========== ====== ======= diff --git a/tests/cargo-upgrade/virtual_manifest/stderr.log b/tests/cargo-upgrade/virtual_manifest/stderr.log index 8bb26b767c..430e288a7f 100644 --- a/tests/cargo-upgrade/virtual_manifest/stderr.log +++ b/tests/cargo-upgrade/virtual_manifest/stderr.log @@ -1,4 +1,5 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies Checking four's dependencies name old req compatible latest new req ==== ======= ========== ====== ======= diff --git a/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock index e1b18d68f8..cd11e50ad0 100644 --- a/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock +++ b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.lock @@ -11,9 +11,9 @@ dependencies = [ [[package]] name = "my-package" -version = "0.1.1+my-package" +version = "99999.0.0+my-package" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61758fedb08b81e9c6967f0661a54feb83fb38eb4bde3614119fbc1d03c1cedf" +checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915" [[package]] name = "one" diff --git a/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml index 2ac75c86ca..14b6524480 100644 --- a/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml +++ b/tests/cargo-upgrade/workspace_inheritance/out/Cargo.toml @@ -6,4 +6,4 @@ members = [ ] [workspace.dependencies] -my-package = "0.1.1" +my-package = "99999.0.0" diff --git a/tests/cargo-upgrade/workspace_inheritance/stderr.log b/tests/cargo-upgrade/workspace_inheritance/stderr.log index a04fc3df9c..fb3e55e0f0 100644 --- a/tests/cargo-upgrade/workspace_inheritance/stderr.log +++ b/tests/cargo-upgrade/workspace_inheritance/stderr.log @@ -1,7 +1,12 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies +name old req compatible latest new req +==== ======= ========== ====== ======= +my-package 0.1.1 0.1.1 99999.0.0 99999.0.0 Checking four's dependencies Checking one's dependencies Checking three's dependencies Checking two's dependencies + Upgrading recursive dependencies note: Re-run with `--verbose` to show all dependencies local: three diff --git a/tests/cargo-upgrade/workspace_member_cwd/stderr.log b/tests/cargo-upgrade/workspace_member_cwd/stderr.log index bdc3a67393..27be3fa056 100644 --- a/tests/cargo-upgrade/workspace_member_cwd/stderr.log +++ b/tests/cargo-upgrade/workspace_member_cwd/stderr.log @@ -1,4 +1,5 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies Checking four's dependencies name old req compatible latest new req ==== ======= ========== ====== ======= diff --git a/tests/cargo-upgrade/workspace_member_manifest_path/stderr.log b/tests/cargo-upgrade/workspace_member_manifest_path/stderr.log index 7d67af84c8..68e818e425 100644 --- a/tests/cargo-upgrade/workspace_member_manifest_path/stderr.log +++ b/tests/cargo-upgrade/workspace_member_manifest_path/stderr.log @@ -1,4 +1,5 @@ Updating '[ROOTURL]/registry' index + Checking virtual workspace's dependencies Checking four's dependencies name old req compatible latest new req ==== ======= ========== ====== ======= From f78d3893ec3a026f7a12a36d29d00bc12c44d3d4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 22 Sep 2022 10:55:22 -0500 Subject: [PATCH 5/5] style: Make clippy happy --- src/bin/upgrade/upgrade.rs | 9 +++++---- src/manifest.rs | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bin/upgrade/upgrade.rs b/src/bin/upgrade/upgrade.rs index dd724ba2ba..964f68fd04 100644 --- a/src/bin/upgrade/upgrade.rs +++ b/src/bin/upgrade/upgrade.rs @@ -202,7 +202,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { let mut reason = None; let dep_key = dep_key.get(); - let dependency = match Dependency::from_toml(&manifest_path, dep_key, dep_item) { + let dependency = match Dependency::from_toml(manifest_path, dep_key, dep_item) { Ok(dependency) => dependency, Err(err) => { shell_warn(&format!("ignoring {}, unsupported entry: {}", dep_key, err))?; @@ -271,7 +271,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { // we're offline. let registry_url = dependency .registry() - .map(|registry| registry_url(&manifest_path, Some(registry))) + .map(|registry| registry_url(manifest_path, Some(registry))) .transpose()?; if !args.offline { if let Some(registry_url) = ®istry_url { @@ -286,7 +286,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { get_compatible_dependency( &dependency.name, &old_version_req, - &manifest_path, + manifest_path, registry_url.as_ref(), ) .ok() @@ -300,7 +300,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { let latest_version = get_latest_dependency( &dependency.name, is_prerelease, - &manifest_path, + manifest_path, registry_url.as_ref(), ) .map(|d| { @@ -470,6 +470,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { // // Reusing updates (resolve_ws) so we know what lock_version to reference for (name, (req, precise)) in &precise_deps { + #[allow(clippy::unnecessary_lazy_evaluations)] // requires 1.62 for lock_version in locked .iter() .filter(|p| p.name == **name) diff --git a/src/manifest.rs b/src/manifest.rs index 9be84bb9ca..f45ad66825 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -275,9 +275,9 @@ impl LocalManifest { } /// Allow mutating depedencies, wherever they live - pub fn get_dependency_tables_mut<'r>( - &'r mut self, - ) -> impl Iterator + 'r { + pub fn get_dependency_tables_mut( + &mut self, + ) -> impl Iterator + '_ { let root = self.data.as_table_mut(); root.iter_mut().flat_map(|(k, v)| { if DepTable::KINDS @@ -385,6 +385,7 @@ fn remove_feature_activation( .filter_map(|(idx, feature_activation)| { if let toml_edit::Value::String(feature_activation) = feature_activation { let activation = feature_activation.value(); + #[allow(clippy::unnecessary_lazy_evaluations)] // requires 1.62 match status { FeatureStatus::None => activation == dep || activation.starts_with(dep_feature), FeatureStatus::DepFeature => activation == dep,