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

Respect Cargo.toml [package.exclude] even not in a git repo. #9186

Merged
merged 2 commits into from
May 1, 2021

Conversation

weihanglo
Copy link
Member

@weihanglo weihanglo commented Feb 18, 2021

May resolves #9054

This bug (or feature?) has been lingering for a while. #7680 fixed the cargo package part but cargo vendor is still affected by the heuristic rule of ignoring dotfiles. I propose to drop the rule and include dotfiles by default even if the package is not under git-controlled. See below.

Updated: Changes Summary

cargo vendor vendors dependencies without git-controlled but cargo package often runs under a VCS like git. These lines are where they diverges: fn list_files_walk_except_dot_files_and_dirs builds its own ignore instance, which cannot merge with other filter rules from [package.exclude]. This causes some patterns to not work as expected, such as re-including file after ignoring dotfiles [.*, !negated_file].

To make re-include (negate) rule works, this patch adds the excluding dotfiles rule directly into the package.exclude ignore instance if no include option nor git repo exists. Other old behaviors should not change in this patch.

@rust-highfive
Copy link

r? @alexcrichton

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2021
@alexcrichton
Copy link
Member

Thanks for the PR! Unfortunately it's been basically forever since I last looked at any of this and at this point I don't really remember much about what's going on here. I tried to read this for awhile and piece together what's going on, but I wasn't really able to get very far unfortunately.

You say that this may solve #9054, but does it?

The body of this looks like it's basically just reverting #7680, which I'm not sure why that works or the interactions it has with other parts of the systems. I'm surprised that at a high-level vendor/package are different since in theory they should both be using the same code paths now that they're both bundled in Cargo.

@weihanglo
Copy link
Member Author

If I got it correctly, cargo::sources::path::list_files has these scenarios (similar to #7680 (comment)):

  • In a git repo + without [package.include] field: respecting git status, .gitignore and exclude field from manifest.
  • Not in a git repo + without [package.include] field: respecting .gitignore, but skipping dotfiles, which builds its own gitignorer and may accidentally overrides exclude field from manifest.
  • With [package.include] field: respecting .gitignore and exclude field from manifest.

We can see that #9054 is under the second scenario (unpacked sources in registry/src without git controlled). Since an unpacked source is downloaded from a registry, and that means files in the source are all necessary for building the crate (author must exclude unnecessary files explicitly while uploading it to a registry). So, in my opinion all files in an unpacked source are safe to be vendored.

As far as I can think of, the only exception that would be affected by this change is a cargo project using version control tools other than git. Considering this is somewhat a breaking change, maybe we can disable skipping dotfiles functionality for cargo vendor instead. Though personally I prefer to remove the strong rule of skipping all dotfiles.

@alexcrichton
Copy link
Member

I wonder if this could apply a similar change but basically try to fix just the use case mentioned? For example the default "exclude" builder could, even if not mentioned in the manifest, have a rule that says .* and then that can be overridden by subsequent rules?

@weihanglo
Copy link
Member Author

@alexcrichton Updated. Please help review at your pace 😁

Note that it is still impossible to negate (include) a file inside a dot directory. This is the limitation of gitignore rule.

It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

@alexcrichton
Copy link
Member

Ok sorry for the delay in getting to this, but I'm looking at this again. Would you be up for writing a summary of the change that this is now updated to doing? I think I have it in my head but I want to make sure I'm right. After that I'll get a sign-off from the rest of the team that this behavior is ok to change.

@weihanglo
Copy link
Member Author

@alexcrichton Thank for you review!
A changes summary is added to PR description. 😄

@alexcrichton alexcrichton added the T-cargo Team: Cargo label Apr 23, 2021
@alexcrichton
Copy link
Member

Ok thanks!

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 23, 2021

Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Apr 23, 2021
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 30, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Apr 30, 2021
@ehuss
Copy link
Contributor

ehuss commented May 1, 2021

Thanks!

@bors r=alexcrichton

@bors
Copy link
Contributor

bors commented May 1, 2021

📌 Commit 153146e has been approved by alexcrichton

@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 May 1, 2021
@bors
Copy link
Contributor

bors commented May 1, 2021

⌛ Testing commit 153146e with merge db741ac...

@bors
Copy link
Contributor

bors commented May 1, 2021

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing db741ac to master...

@bors bors merged commit db741ac into rust-lang:master May 1, 2021
@weihanglo weihanglo deleted the issue-9054 branch May 1, 2021 23:39
bors added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2021
Update cargo

7 commits in f3e13226d6d17a2bc5f325303494b43a45f53b7f..e51522ab3db23b0d8f1de54eb1f0113924896331
2021-04-30 21:50:27 +0000 to 2021-05-07 21:29:52 +0000
- Add CARGO_TARGET_TMPDIR env var for integration tests & benches (rust-lang/cargo#9375)
- Bump to 0.55.0, update changelog (rust-lang/cargo#9464)
- Some updates to the unstable documentation (rust-lang/cargo#9457)
- Add CARGO_PROFILE_<name>_SPLIT_DEBUGINFO to env docs. (rust-lang/cargo#9456)
- Add `report` subcommand. (rust-lang/cargo#9438)
- Respect Cargo.toml `[package.exclude]` even not in a git repo. (rust-lang/cargo#9186)
- Document the other crates in the codebase in the contrib guide. (rust-lang/cargo#9439)
@rfcbot rfcbot added finished-final-comment-period FCP complete to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels May 10, 2021
@ehuss ehuss added this to the 1.54.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge FCP with intent to merge finished-final-comment-period FCP complete S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-cargo Team: Cargo to-announce
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo vendor vs cargo package inconsistency
6 participants