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

propose bazel type for Bazel modules #317

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

fmeum
Copy link

@fmeum fmeum commented Aug 1, 2024

Bazel 6 introduced a new system for managing external dependencies centered around the concept of Bazel modules, which are hosted in a registry. The default registry is the Bazel Central Registry. This system will become the default this year and its predecessor will be turned off next year.

As discussed in bazelbuild/bazel#23166, we would thus like to register the bazel purl type for Bazel modules, as specified in this PR.

(Approved by the Rules Authors SIG: https://docs.google.com/document/d/1YGCYAGLzTfqSOgRFVsB8hDz-kEoTgTEKKp9Jd07TJ5c/edit#heading=h.9h67icc19g8f)

@fmeum
Copy link
Author

fmeum commented Aug 6, 2024

CC @mzeren-vmw

@oej
Copy link

oej commented Aug 7, 2024

Any status on the feedback you waited for?

@fmeum
Copy link
Author

fmeum commented Aug 7, 2024

@oej Yes, this has been approved and is ready for review!

@fmeum fmeum marked this pull request as ready for review August 7, 2024 09:05
@fmeum
Copy link
Author

fmeum commented Aug 21, 2024

@stevespringett Could you review this?

@fmeum
Copy link
Author

fmeum commented Oct 9, 2024

@pombredanne Not sure who to ask for a review, could you take a look?

@johnmhoran johnmhoran added the type: bazel Proposed new type label Oct 19, 2024
@jkowalleck jkowalleck changed the title Add bazel type for Bazel modules propose bazel type for Bazel modules Oct 19, 2024
fviernau added a commit to oss-review-toolkit/ort that referenced this pull request Nov 21, 2024
fviernau added a commit to oss-review-toolkit/ort that referenced this pull request Nov 22, 2024
@sschuberth
Copy link
Member

@fmeum please rebase to resolve conflicts.

@fmeum
Copy link
Author

fmeum commented Nov 22, 2024

@sschuberth Done

PURL-TYPES.rst Outdated Show resolved Hide resolved
PURL-TYPES.rst Outdated Show resolved Hide resolved
PURL-TYPES.rst Outdated Show resolved Hide resolved
fviernau added a commit to oss-review-toolkit/ort that referenced this pull request Nov 22, 2024
@fmeum fmeum requested a review from sschuberth November 22, 2024 10:04
sschuberth pushed a commit to oss-review-toolkit/ort that referenced this pull request Nov 22, 2024
PURL-TYPES.rst Outdated
- The ``version`` is the module version in `Bazel's relaxed semver format
<https://bazel.build/external/module#version_format>`_.
- The optional ``repository_url`` can be used to specify the URL of an
alternative registry, with any trailing forward slashes removed.
Copy link
Member

Choose a reason for hiding this comment

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

with any trailing forward slashes removed.

I'm not sure about that bit. This is not one of the "type-specific normalizations" that are allowed for the namespace segments and name. And semantically, having a trailing slash or not does not make a difference for the URL.

Copy link
Author

Choose a reason for hiding this comment

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

I just dropped this in a new commit.

PURL-TYPES.rst Outdated
Comment on lines 73 to 75
- The optional ``subpath`` can name a particular Bazel target in the module via
a label with the leading double slash (``//``) removed and canonicalized by
omitting the target name if it is equal to the name of the containing package.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. The spec describes the subpath as

extra subpath within a package, relative to the package root.

How is what you describe "relative to the package root"? Would a custom qualifier maybe make more sense to store the Bazel target?

Copy link
Author

Choose a reason for hiding this comment

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

I simplified this part of the spec in a new commit so that it's always a regular file path, corresponding to a package (not target or file) in the Bazel module. This is analogous to the usage of subpath for golang.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good to me now, but I'd like others to share their opinion as well.

@fmeum fmeum requested a review from sschuberth November 22, 2024 12:10
sschuberth added a commit to oss-review-toolkit/ort that referenced this pull request Nov 22, 2024
sschuberth added a commit to oss-review-toolkit/ort that referenced this pull request Nov 22, 2024
The algorithm description at [1] demands to "apply type-specific
normalization" to namespace segments and the name before applying
percent-encoding. In general, type-specific requirements are documented
at [2]. For Bazel the PR still pending, but in the current state
lowercasing of the name should be performed [3].

[1]: https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst#how-to-build-purl-string-from-its-components
[2]: https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst
[3]: package-url/purl-spec#317

Signed-off-by: Sebastian Schuberth <[email protected]>
sschuberth added a commit to oss-review-toolkit/ort that referenced this pull request Nov 22, 2024
The algorithm description at [1] demands to "apply type-specific
normalization" to namespace segments and the name before applying
percent-encoding. In general, type-specific requirements are documented
at [2]. For Bazel the PR still pending, but in the current state
lowercasing of the name should be performed [3].

[1]: https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst#how-to-build-purl-string-from-its-components
[2]: https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst
[3]: package-url/purl-spec#317

Signed-off-by: Sebastian Schuberth <[email protected]>
@fmeum
Copy link
Author

fmeum commented Jan 16, 2025

@stevespringett @shibumi @johnmhoran @pombredanne Apologies for the multi-ping, but it's hard to tell who would be able to move this forward. Could you add a second review?

@shibumi
Copy link
Contributor

shibumi commented Jan 19, 2025

@fmeum Hi, I am "only" the packageurl-go maintainer and have not much to say when it comes to purl specification issues. I am afraid you will have to wait for @pombredanne or anyone else of the "steering committee".

Copy link
Member

@pombredanne pombredanne left a comment

Choose a reason for hiding this comment

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

Thanks. Looking good overall! ❤️ It would be great to add at a link to the spec for modules at https://bazel.build/external/module and I have posted a few small nits, suggestions and questions for you consideration.

PURL-TYPES.rst Outdated Show resolved Hide resolved
PURL-TYPES.rst Outdated Show resolved Hide resolved
PURL-TYPES.rst Outdated Show resolved Hide resolved
test-suite-data.json Show resolved Hide resolved
test-suite-data.json Outdated Show resolved Hide resolved
PURL-TYPES.rst Outdated

- The default repository ("registry") is ``https://bcr.bazel.build``, the
Bazel Central Registry (BCR).
- The ``name`` is the module name. It must be lowercased.
Copy link
Member

Choose a reason for hiding this comment

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

Could it make sense to integrate the whole name spec at https://bazel.build/rules/lib/globals/module#module.name ?

A valid module name must: 1) only contain lowercase letters (a-z), digits (0-9), dots (.), hyphens (-), and underscores (_); 2) begin with a lowercase letter; 3) end with a lowercase letter or digit.

Also, about names, I guess that when there is name as possible in the spec, there is no purl possible, right?

The name of the module. Can be omitted only if this module is the root module (as in, if it's not going to be depended on by another module).

Copy link
Contributor

Choose a reason for hiding this comment

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

Validating package names via the PURL spec makes PURL and its implementations more complicated and leads to a PURL spec crisis if the real validation rules are relaxed in the future (eg @a/b was invalid before NPM 2.0) where people will argue that it's a breaking change to allow something that was previously forbidden in PURL. I understand the value of canonicalizing the package name so multiple distinct PURLs don't refer to the same package, and that should be safe because changing canonicalization rules would break builds, but I don't think there's a need for PURL implementations in general to validate the name of the package to prevent PURLs that cannot refer to a package.

Are Bazel module names case insensitive, or are uppercase characters currently invalid? There's a difference, and some existing PURL types get this wrong (eg NPM).

Copy link
Author

Choose a reason for hiding this comment

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

Bazel module names are enforced to be of the form @pombredanne linked. I agree that keeping validation out of the spec makes sense. We could just allow PURLs to reference module names that aren't valid as per the current rules enforced by Bazel, they just won't be useful.

Copy link

Choose a reason for hiding this comment

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

Having recently worked on implementing PURL in Starlark (Bazel's python dialect), my vote would be to keep "type"-specific validation and normalization to a minimum. That was the most complex part to implement. It also allows Bazel to change the allowed chars for module names without having to change the PURL spec, which I think would be a plus. We would allow PURLs that are not Bazel modules, but we can't really prevent that anyway because pkg:bazel/foo@1234 is definitely a valid PURL, but is not going to ever exist in BCR. Sure, pkg:bazel/[email protected] would point to a non-existing module, but PURL by itself can't prevent that given my example above. So why adding the additional complexity of doing the validation/normalization?

Copy link
Author

Choose a reason for hiding this comment

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

I dropped validation from the type spec and the test suite, PTAL.

jkowalleck
jkowalleck previously approved these changes Jan 28, 2025
Copy link

@Yannic Yannic left a comment

Choose a reason for hiding this comment

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

Thanks!

Can we add a test case for valid purls that Bazel will reject (e.g., pkg:bazel/Curl@1234) to have coverage for the non-validation case?

@fmeum
Copy link
Author

fmeum commented Jan 28, 2025

Can we add a test case for valid purls that Bazel will reject (e.g., pkg:bazel/Curl@1234) to have coverage for the non-validation case?

Added via b29e1ea

@fmeum fmeum requested review from jkowalleck and Yannic January 28, 2025 13:14
test-suite-data.json Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants