-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #13281 - LuuuXXX:issue-10729, r=epage
fix(add): Improve error when adding registry packages while vendored ### **What does this PR try to resolve?** When a vendored directory is established, cargo add no longer adds new packages. Instead, it tries to translate a package name into a package that already exists in the vendored directory. [More details](#10729 (comment)) Since `@epage` has done most of the work, here I do the rest of the finishing work. Improves the error from #10729 ### **How should we test and review this PR?** The implementation procedure is as follows: #10729 (comment) Test steps: 1. Try to get an arbitrary crate and execute `cargo vendor` command. 2. Configure the vendor directory in .cargo/config.toml. 3. Add `alter-registry` to the config.toml file. ``` [registries] alter-registry= { index = "XXX" } ``` 4. run the same `cargo add` command. ``` cargo add another-crate --registry alter-registry ```
- Loading branch information
Showing
28 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/.cargo/config.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[source.crates-io] | ||
replace-with = "vendored-sources" | ||
|
||
[source.vendored-sources] | ||
directory = "./vendor" |
5 changes: 5 additions & 0 deletions
5
tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "cargo-list-test-fixture" | ||
version = "0.0.0" |
Empty file.
1 change: 1 addition & 0 deletions
1
...e/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/.cargo-checksum.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"files":{}} |
5 changes: 5 additions & 0 deletions
5
...s/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "aa" | ||
version = "0.0.0" |
Empty file.
35 changes: 35 additions & 0 deletions
35
tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use cargo_test_support::compare::assert_ui; | ||
use cargo_test_support::prelude::*; | ||
use cargo_test_support::Project; | ||
|
||
use cargo_test_support::curr_dir; | ||
|
||
#[cargo_test] | ||
fn case() { | ||
cargo_test_support::registry::alt_init(); | ||
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4") | ||
.feature("clippy", &[]) | ||
.feature("heapsize", &[]) | ||
.feature("heapsize_impl", &[]) | ||
.feature("nightly", &[]) | ||
.feature("serde", &[]) | ||
.feature("serde_impl", &[]) | ||
.feature("serde_test", &[]) | ||
.alternative(true) | ||
.publish(); | ||
|
||
let project = Project::from_template(curr_dir!().join("in")); | ||
let project_root = project.root(); | ||
let cwd = &project_root; | ||
|
||
snapbox::cmd::Command::cargo_ui() | ||
.arg("add") | ||
.arg_line("linked_hash_map --registry alternative") | ||
.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); | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/out/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "cargo-list-test-fixture" | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
linked-hash-map = { version = "0.5.4", registry = "alternative" } |
11 changes: 11 additions & 0 deletions
11
tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/stderr.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Updating `alternative` index | ||
warning: translating `linked_hash_map` to `linked-hash-map` | ||
Adding linked-hash-map v0.5.4 to dependencies. | ||
Features: | ||
- clippy | ||
- heapsize | ||
- heapsize_impl | ||
- nightly | ||
- serde | ||
- serde_impl | ||
- serde_test |
Empty file.
5 changes: 5 additions & 0 deletions
5
tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/.cargo/config.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[source.crates-io] | ||
replace-with = "vendored-sources" | ||
|
||
[source.vendored-sources] | ||
directory = "./vendor" |
5 changes: 5 additions & 0 deletions
5
tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "cargo-list-test-fixture" | ||
version = "0.0.0" |
Empty file.
1 change: 1 addition & 0 deletions
1
...testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/.cargo-checksum.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"files":{}} |
5 changes: 5 additions & 0 deletions
5
tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "aa" | ||
version = "0.0.0" |
Empty file.
23 changes: 23 additions & 0 deletions
23
tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use cargo_test_support::compare::assert_ui; | ||
use cargo_test_support::prelude::*; | ||
use cargo_test_support::Project; | ||
|
||
use cargo_test_support::curr_dir; | ||
|
||
#[cargo_test] | ||
fn case() { | ||
let project = Project::from_template(curr_dir!().join("in")); | ||
let project_root = project.root(); | ||
let cwd = &project_root; | ||
|
||
snapbox::cmd::Command::cargo_ui() | ||
.arg("add") | ||
.arg_line("cbindgen") | ||
.current_dir(cwd) | ||
.assert() | ||
.failure() | ||
.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); | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/out/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "cargo-list-test-fixture" | ||
version = "0.0.0" |
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/stderr.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
error: the crate `cbindgen` could not be found in registry index. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters