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(package): detect dirty workspace manifest #15089

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

weihanglo
Copy link
Member

What does this PR try to resolve?

This addresses one of the corner cases of VCS dirtiness in #14967.

Workspace inheritance — like changing workspace.package.edition
to 2021 would actually make member Cargo.toml dirty,
but the current dirty status check doesn't capture that.

The solution here is

  • Retrieve workspace manifest from Git index.
  • Use the ws manifest from index to normalize package manifest.
  • Compare the difference between normalized tomls from Git index and
    from Git working directory.

The implementation here is a bit ugly, as it exposes some internals
functions to pub(crate).

The current implementation also has performance issues. When the
workspace contains lots of members and has a dirty workspace manifest:

  • It adds one extra manifest parsing and normalization for
    checking each member.
    • Parsing part can be cached for the entire workspace.
      However normalization cannot be skipped.
  • It adds two TOML serializations for checking each member.
    • If we derive Eq for manifest types, we might be able to skip
      serializations and instead just compare them.

How should we test and review this PR?

Three tests are added to demonstrate that dirtiness check does not
work for Cargo.toml involved with workspace inheritance.

  • One for basic check. If any change in workspace manifest could affect
    the inherited value, this should be caught as dirty.
  • One for broken workspace manifest in Git index.
  • The other is also for broken workspace manifest in Git index, but has
    no inherited field.

Additional information

Workspace manifest dirtiness is more complicated than the other cases.
We will construct dedicated tests for it in following commits.
This commits adds three tests to demonstrate that dirtiness check does not
work for Cargo.toml involved with workspace inheritance.

* One for basic check. If any change in workspace manifest could affect
  the inherited value, this should be caught as dirty.
* One for broken workspace manifest in Git index.
* The other is also for broken workspace manifest in Git index, but has
  no inherited field.
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-git Area: anything dealing with git A-manifest Area: Cargo.toml issues Command-package S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2025
This addresses one of the corner cases of VCS dirtiness in rust-lang#14967.

> Workspace inheritance — like changing `workspace.package.edition`
> to `2021` would actually make member Cargo.toml dirty,
> but the current dirty status check doesn't capture that.

The solution here is

* Retrieve workspace manifest from Git index.
* Use the ws manifest from index to normalize package manifest.
* Compare the difference between normalized tomls from Git index and
  from Git working directory.

The implementation here is a bit ugly, as it exposes some internals
functions to `pub(crate)`.

The current implementation also has performance issues. When the
workspace contains lots of members and has a dirty workspace manifest:

* It adds one extra manifest parsing and normalization for
  checking each member.
  * Parsing part can be cached for the entire workspace.
    However normalization cannot be skipped.
* It adds two TOML serializations for checking each member.
  * If we derive `Eq` for manifest types, we might be able to skip
    serializations and instead just compare them.
@weihanglo weihanglo force-pushed the package-dirty-workspace branch from e7c2904 to 1a91bd3 Compare January 22, 2025 02:43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution here is

  • Retrieve workspace manifest from Git index.
  • Use the ws manifest from index to normalize package manifest.
  • Compare the difference between normalized tomls from Git index and
    from Git working directory.

This is a complex operation we are doing which I seriously question whether it is worth it vs something else like "its dirty if the workspace manifest is dirty" (without even bothering to check if the workspace manifest is different than the package manifest).

Similarly, we now include Cargo.lock and that could be dirty. Would we extend the same kind of "only if it affects this one package" style check for that case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I do think this fix is a bit too convoluted to merge.

"its dirty if the workspace manifest is dirty"

This is actually a good compromise as users always have --allow-dirty to bypass it. Guess we could start an FCP or discussion during the meeting.

Similarly, we now include Cargo.lock and that could be dirty. Would we extend the same kind of "only if it affects this one package" style check for that case?

Ooops. I would rather not. Also we have --lockfile-path, which makes the entire story worse 😞.

@weihanglo weihanglo marked this pull request as draft January 22, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git A-manifest Area: Cargo.toml issues Command-package S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants