Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(add): Improve error when adding registry packages while vendored #13281

Merged
merged 3 commits into from
Feb 22, 2024

Conversation

LuuuXXX
Copy link
Contributor

@LuuuXXX LuuuXXX commented Jan 11, 2024

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

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" }
  1. run the same cargo add command.
cargo add another-crate --registry alter-registry

@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2024

r? @epage

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver A-directory-source Area: directory sources (vendoring) A-registries Area: registries Command-add S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2024
@epage
Copy link
Contributor

epage commented Jan 12, 2024

I recommend re-arranging the commits so the first commit shows the current behavior via a test and then the commit with the fix updates the test. This helps make clear to the reviewers what the behavior change was and ensures we "test the test" (assuming you ran the tests).

I tried to do that with your branch and when i cherry-picked the test onto master, it passed.

@LuuuXXX
Copy link
Contributor Author

LuuuXXX commented Jan 14, 2024

I recommend re-arranging the commits so the first commit shows the current behavior via a test
Okay, revised the commit order

@epage
Copy link
Contributor

epage commented Jan 15, 2024

Its not just about the commit order but that every commit should pass cargo test. In doing so, the commit that fixes the bug will need to be updating the test to reflect the new behavior.

@rustbot rustbot added the A-manifest Area: Cargo.toml issues label Jan 16, 2024
@LuuuXXX LuuuXXX force-pushed the issue-10729 branch 2 times, most recently from cdb15d6 to b049570 Compare January 16, 2024 06:41
@LuuuXXX
Copy link
Contributor Author

LuuuXXX commented Jan 17, 2024

Its not just about the commit order but that every commit should pass cargo test.

No problem, I've resubmitted the commits.

@epage
Copy link
Contributor

epage commented Jan 17, 2024

The test is still the last commit.

The test should be the first commit and it should pass as-is. The follow up changes should change the tests as the behavior changes which will show that the behavior did change in the intended way and that the test tests the right thing. Last I looked, it appeared that the current tests do not test the right thing.

@LuuuXXX LuuuXXX changed the title Fix: `cargo add refuses to add new non-vendored packages due to source replacement [wip] Fix: `cargo add refuses to add new non-vendored packages due to source replacement Jan 22, 2024
@LuuuXXX LuuuXXX force-pushed the issue-10729 branch 6 times, most recently from 787a975 to 7b9d3f5 Compare January 31, 2024 09:10
@LuuuXXX LuuuXXX changed the title [wip] Fix: `cargo add refuses to add new non-vendored packages due to source replacement Fix: `cargo add refuses to add new non-vendored packages due to source replacement Feb 1, 2024
@LuuuXXX
Copy link
Contributor Author

LuuuXXX commented Feb 1, 2024

The test should be the first commit and it should pass as-is.

I reordered commits.

Last I looked, it appeared that the current tests do not test the right thing.

I've added two new tests,
One is to ensure that no package can be obtained from the vendor directory when a non-vendor package is added. (Throwing error in my opinion is the right thing to do.)
The other is to ensure that non-vendor packages can be obtained through alter registry.

@epage
Copy link
Contributor

epage commented Feb 1, 2024

I reordered commits.

They were re-ordered but not updated so that every commit passes. I've pushed an update to your branch that does this.

@epage epage changed the title Fix: `cargo add refuses to add new non-vendored packages due to source replacement fix(add): Improve error when adding registry packages while vendored Feb 1, 2024
@LuuuXXX LuuuXXX force-pushed the issue-10729 branch 2 times, most recently from 03705aa to e550de4 Compare February 20, 2024 03:32
@LuuuXXX
Copy link
Contributor Author

LuuuXXX commented Feb 20, 2024

Thanks, it's been squashed

@epage
Copy link
Contributor

epage commented Feb 20, 2024

Thanks, it's been squashed

I was asking for the last commit to be squashed, not all of them.

@LuuuXXX LuuuXXX force-pushed the issue-10729 branch 5 times, most recently from 6f5cbe2 to 4e22e35 Compare February 21, 2024 06:09
@LuuuXXX
Copy link
Contributor Author

LuuuXXX commented Feb 21, 2024

my bad, I recreated the commit history with latest modifies

@epage
Copy link
Contributor

epage commented Feb 21, 2024

As a reminder, each commit should pass tests.

@LuuuXXX
Copy link
Contributor Author

LuuuXXX commented Feb 22, 2024

yes yes, recreated again

@epage
Copy link
Contributor

epage commented Feb 22, 2024

Thanks for all of the work you put into this and patience through the back and forth!

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 22, 2024

📌 Commit 640c077 has been approved by epage

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 22, 2024
@bors
Copy link
Collaborator

bors commented Feb 22, 2024

⌛ Testing commit 640c077 with merge e08a813...

@bors
Copy link
Collaborator

bors commented Feb 22, 2024

☀️ Test successful - checks-actions
Approved by: epage
Pushing e08a813 to master...

@bors bors merged commit e08a813 into rust-lang:master Feb 22, 2024
23 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 28, 2024
Update cargo

16 commits in 194a60b2952bd5d12ba15dd2577a97eed7d3c587..8964c8ccff6e420e2a38b8696d178d69fab84d9d
2024-02-21 01:53:45 +0000 to 2024-02-27 19:22:46 +0000
- feat: Add "-Zpublic-dependency" for public-dependency feature. (rust-lang/cargo#13340)
- Stabilize global cache data tracking. (rust-lang/cargo#13492)
- chore: bump baseline version requirement of sub crates (rust-lang/cargo#13494)
- fix(doctest): search native libs in build script outputs (rust-lang/cargo#13490)
- chore: fixed a typo(two->too) (rust-lang/cargo#13489)
- test: relax help text assertion (rust-lang/cargo#13488)
- refactor: clean up for `GlobalContext` rename (rust-lang/cargo#13486)
- test(cli): Verify terminal styling (rust-lang/cargo#13461)
- fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' (rust-lang/cargo#13479)
- Error messages when collecting workspace members now mention the workspace root location (rust-lang/cargo#13480)
- fix(add): Improve error when adding registry packages while vendored (rust-lang/cargo#13281)
- [docs]:Add missing jump links (rust-lang/cargo#13478)
- Add global_cache_tracker stability tests. (rust-lang/cargo#13467)
- fix(cli): Control clap colors through config (rust-lang/cargo#13463)
- chore: remove the unused function (rust-lang/cargo#13472)
- Fix missing brackets (rust-lang/cargo#13470)
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 28, 2024
Update cargo

16 commits in 194a60b2952bd5d12ba15dd2577a97eed7d3c587..8964c8ccff6e420e2a38b8696d178d69fab84d9d
2024-02-21 01:53:45 +0000 to 2024-02-27 19:22:46 +0000
- feat: Add "-Zpublic-dependency" for public-dependency feature. (rust-lang/cargo#13340)
- Stabilize global cache data tracking. (rust-lang/cargo#13492)
- chore: bump baseline version requirement of sub crates (rust-lang/cargo#13494)
- fix(doctest): search native libs in build script outputs (rust-lang/cargo#13490)
- chore: fixed a typo(two->too) (rust-lang/cargo#13489)
- test: relax help text assertion (rust-lang/cargo#13488)
- refactor: clean up for `GlobalContext` rename (rust-lang/cargo#13486)
- test(cli): Verify terminal styling (rust-lang/cargo#13461)
- fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' (rust-lang/cargo#13479)
- Error messages when collecting workspace members now mention the workspace root location (rust-lang/cargo#13480)
- fix(add): Improve error when adding registry packages while vendored (rust-lang/cargo#13281)
- [docs]:Add missing jump links (rust-lang/cargo#13478)
- Add global_cache_tracker stability tests. (rust-lang/cargo#13467)
- fix(cli): Control clap colors through config (rust-lang/cargo#13463)
- chore: remove the unused function (rust-lang/cargo#13472)
- Fix missing brackets (rust-lang/cargo#13470)
@ehuss ehuss added this to the 1.78.0 milestone Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-directory-source Area: directory sources (vendoring) A-manifest Area: Cargo.toml issues A-registries Area: registries Command-add S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants