Skip to content

Genericize package manifest system and interface#660

Merged
nacl merged 6 commits intobazelbuild:mainfrom
nacl:topic/i385-generic-manifest-2
Feb 8, 2023
Merged

Genericize package manifest system and interface#660
nacl merged 6 commits intobazelbuild:mainfrom
nacl:topic/i385-generic-manifest-2

Conversation

@nacl
Copy link
Collaborator

@nacl nacl commented Jan 13, 2023

The current way that rules_pkg communicates with must packagers is using a manifest file, which is currently a JSON data structure based on a an array of arrays. While generally readable, it looks strange, as it was to reduce Bazel resource usage (JSON strings in memory). Further, our Python code is directly bound to this data structure format.

However, if we want to add more or change this, it becomes cumbersome on both the Starlark and Python sides. This change alleviates concerns generally by:

  • Converting all manifests to a JSON "object" style, improving readability. Numerous "golden" tests were updated to support this.
  • Replace the collections.namedtuple-based ManifestEntry object with one that is a little more flexible and type-safe.
  • Providing a function (read_entries_from) that converts a file-like object into a list of ManifestEntrys, and replacing all JSON reading in packagers (tar, zip, install) and their tests with this function. While this is theoretically usable by consumers of rules_pkg, it is not intended to be supported as such.

Other convenience factors or things addressed:

  • ManifestEntry.entry_type is now just ManifestEntry.type
  • Bazel 6 now stringifies repository-local labels with a preceding @, unlike prior versions. Adapt to this in the manifest writer.

Future changes will extend this interface to allow for custom attributes to be passed from pkg_files and friends, which, among other things, will be necessary to more generically support pkg_rpm.

Provides some groundwork for (but doesn't resolve) #385.

The current way that rules_pkg communicates with must packagers is using a
manifest file, which is currently a JSON data structure based on a an array of
arrays.  While generally readable, it looks strange, as it was to reduce Bazel
resource usage (JSON strings in memory).  Further, our Python code is directly
bound to this data structure format.

However, if we want to add more or change this, it becomes cumbersome on both
the Starlark and Python sides. This change alleviates concerns generally by:

- Converting all manifests to a JSON "object" style, improving readability.
  Numerous "golden" tests were updated to support this.
- Replace the `collections.namedtuple`-based `ManifestEntry` object with one
  that is a little more flexible and type-safe.
- Providing a function (`read_entries_from`) that converts a file-like object
  into a list of `ManifestEntry`s, and replacing all JSON reading in packagers
  (`tar`, `zip`, `install`) and their tests with this function.

Other convenience factors or things addressed:

- `ManifestEntry.entry_type` is now just `ManifestEntry.type`
- Bazel 6 now stringifies repository-local labels with a preceding `@`, unlike
  prior versions.  Adapt to this in the manifest writer.

Future changes will extend this interface to allow for custom attributes to be
passed from `pkg_files` and friends, which, among other things, will be
necessary to more generically support `pkg_rpm`.

Provides groundwork for (but doesn't resolve) bazelbuild#385.
@nacl nacl requested a review from aiuto as a code owner January 13, 2023 23:08
Copy link
Collaborator

@aiuto aiuto left a comment

Choose a reason for hiding this comment

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

Sorry this took so long. It landed just before a crunch time.
I love PRs like this. All sorts of plumbling is different, but the tests remain the same.

@nacl nacl merged commit f98a821 into bazelbuild:main Feb 8, 2023
@nacl
Copy link
Collaborator Author

nacl commented Feb 8, 2023

Sorry this took so long. It landed just before a crunch time. I love PRs like this. All sorts of plumbling is different, but the tests remain the same.

No worries, thanks for taking a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants