cargo icon indicating copy to clipboard operation
cargo copied to clipboard

fix(metadata): Stabilize id format as PackageIDSpec

Open epage opened this issue 8 months ago • 5 comments

What does this PR try to resolve?

For tools integrating with cargo, cargo metadata is the primary interface. Limitations include:

  • There isn't an unambiguous way to map a package entry from cargo metadata to a parameter to pass to other cargo commands. An id field exists but it is documented as an opaque string, useful only for comparisons with other ids within the document.
  • There isn't an unambiguous way of taking user parameters (--package) and mapping them to cargo metadata entries. cargo pkgid could help but it returns a PackageIdSpec which doesn't exist within the cargo metadata output.

This attempts to solve these problems by switching the id field from PackageId to PackageIdSpec which is a publicly documented format, can be generated by cargo pkgid, and is accepted by most commands via the --package flag.

As the "id" field is documented as opaque, this technically isn't a breaking change though people could be parsing it.

For cargo_metadata they do use a new type that documents it as opaque but publicly expose the inner String. The String wasn't publicly exposed due to a request by users but instead their PackageId type replaced using Strings in the API in oli-obk/cargo_metadata#59 with no indication given as to why the String was still exposed. However, you'll note that before that PR, they had WorkspaceMember that parsed PackageId. This was introduced in oli-obk/cargo_metadata#26 without a motivation given.

Note that PackageIdSpec has multiple representation that might uniquely identify a package and we can return any one of them.

Fixes #7267

How should we test and review this PR?

Additional information

cc @oli-obk

epage avatar Nov 03 '23 18:11 epage

r? @ehuss

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

rustbot avatar Nov 03 '23 18:11 rustbot

@rfcbot fcp merge

epage avatar Dec 06 '23 20:12 epage

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

  • [x] @Eh2406
  • [x] @Muscraft
  • [x] @arlosi
  • [ ] @ehuss
  • [x] @epage
  • [ ] @joshtriplett
  • [x] @weihanglo

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 avatar Dec 06 '23 20:12 rfcbot

@rfcbot reviewed

BTW, do we have a plan for SourceId?

weihanglo avatar Dec 11 '23 15:12 weihanglo

BTW, do we have a plan for SourceId?

I do not as I don't see as much reason to stabilize it. The end-user benefit here is that you can run a cargo command against a package you came across in cargo metadata. I don't see similar use cases at this time for SourceId.

epage avatar Dec 11 '23 15:12 epage

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

rfcbot avatar Jan 03 '24 16:01 rfcbot

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

rfcbot avatar Jan 13 '24 16:01 rfcbot

@bors r+

Thanks!

weihanglo avatar Jan 15 '24 15:01 weihanglo

:pushpin: Commit 63bb70df004e0097d1a084d88180d638c842b4c7 has been approved by weihanglo

It is now in the queue for this repository.

bors avatar Jan 15 '24 15:01 bors

:hourglass: Testing commit 63bb70df004e0097d1a084d88180d638c842b4c7 with merge 77f2da7b926008b7edcca2fcf6bf1ed4eee56872...

bors avatar Jan 15 '24 15:01 bors

:sunny: Test successful - checks-actions Approved by: weihanglo Pushing 77f2da7b926008b7edcca2fcf6bf1ed4eee56872 to master...

bors avatar Jan 15 '24 16:01 bors