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

Allow native.package_relative_label in initializers #21740

Closed
wants to merge 1 commit into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Mar 20, 2024

Work towards #21622

RELNOTES: native.package_relative_label can now be used in rule initializers.

@fmeum fmeum marked this pull request as ready for review March 20, 2024 11:07
@fmeum fmeum requested a review from a team as a code owner March 20, 2024 11:07
@fmeum fmeum requested review from gregestren and removed request for a team March 20, 2024 11:07
@github-actions github-actions bot added team-Configurability Issues for Configurability team awaiting-review PR is awaiting review from an assigned reviewer labels Mar 20, 2024
@fmeum fmeum requested review from comius and removed request for gregestren March 20, 2024 11:07
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 20, 2024

FYI @Wyverald

@comius
Copy link
Contributor

comius commented Mar 21, 2024

I’d feel more comfortable accepting just package_relative_label, because it seems this function doesn’t lead into parsing and concatenating the labels and is covered by a clear usecase. Other functions seem more risky.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 21, 2024

I’d feel more comfortable accepting just package_relative_label, because it seems this function doesn’t lead into parsing and concatenating the labels and is covered by a clear usecase. Other functions seem more risky.

I have made the change to only allow this function, but I don't quite follow your reasoning: With native.package_relative_label, I can implement native.repo_name as native.package_relative_label("foo").repo_name. The other functions, with the exception of native.module_version, can also mostly be derived from that label. We wouldn't really be exposing more information that way, but improve consistency between the APIs available to macros and initializers. Which additional risk do you see?

@fmeum
Copy link
Collaborator Author

fmeum commented Apr 2, 2024

@comius Friendly ping

@comius
Copy link
Contributor

comius commented Apr 9, 2024

I’d feel more comfortable accepting just package_relative_label, because it seems this function doesn’t lead into parsing and concatenating the labels and is covered by a clear usecase. Other functions seem more risky.

I have made the change to only allow this function, but I don't quite follow your reasoning: With native.package_relative_label, I can implement native.repo_name as native.package_relative_label("foo").repo_name. The other functions, with the exception of native.module_version, can also mostly be derived from that label. We wouldn't really be exposing more information that way, but improve consistency between the APIs available to macros and initializers. Which additional risk do you see?

The problem is that once you have native.repo_name you can implement native.package_relative_label. But in any such implementation you probably need to make assumptions about how a label is composed of different parts.

Also I see package_relative_label backed up by a use-case. Other functions aren't.

@@ -68,6 +68,8 @@ public class BazelStarlarkContext implements StarlarkThread.UncheckedExceptionCo
public enum Phase {
WORKSPACE,
LOADING,
/** Evaluation for a rule initializer, which does not allow all loading phase operations. */
INITIALIZER,
Copy link
Contributor

Choose a reason for hiding this comment

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

Introducing a new phase was avoided before and introducing it now for a single function looks like an overkill.

This also potentially interacts with other locations that use phases. And potentially also with symbolic macros.

@brandjon

@fmeum
Copy link
Collaborator Author

fmeum commented Apr 9, 2024

The problem is that once you have native.repo_name you can implement native.package_relative_label.

I see your point, just want to remark that this is not possible: native.package_relative_label crucially applies the calling package's repository mapping to resolve the apparent to a canonical repo name, which is not something you can't emulate with any other API.

@fmeum fmeum changed the title Allow certain native functions in initializers Allow native.package_relative_label in initializers Apr 9, 2024
@fmeum fmeum requested a review from comius April 9, 2024 09:28
@fmeum
Copy link
Collaborator Author

fmeum commented Apr 9, 2024

@comius I special cased the setup for native.package_relative_label by just providing the LabelConverter as a thread local, thus getting rid of the new phase. PTAL, this is much simpler now.

@fmeum
Copy link
Collaborator Author

fmeum commented Apr 18, 2024

@comius Friendly ping

@comius comius added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts and removed team-Configurability Issues for Configurability team awaiting-review PR is awaiting review from an assigned reviewer labels Apr 25, 2024
@fmeum
Copy link
Collaborator Author

fmeum commented Apr 25, 2024

@bazel-io fork 7.2.0

@fmeum
Copy link
Collaborator Author

fmeum commented May 3, 2024

@comius @iancha1992 Friendly ping, is this still on track for merging?

@iancha1992
Copy link
Member

@comius @iancha1992 Friendly ping, is this still on track for merging?

@fmeum Yes. We are currently working on this :)

@iancha1992
Copy link
Member

iancha1992 commented May 7, 2024

@fmeum can you please resolve the conflicts from src/main/java/com/google/devtools/build/lib/packages/StarlarkNativeModule.java? There is a conflict that I could not resolve on my own from the file. Thanks :)

RELNOTES: The following functions on `native` can now be used in rule
initializers: `repo_name`, `package_name`, `package_relative_label`,
`module_name`, `module_version`.
@fmeum
Copy link
Collaborator Author

fmeum commented May 7, 2024

@iancha1992 Done

@copybara-service copybara-service bot closed this in 8e7ef00 May 7, 2024
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label May 7, 2024
@fmeum fmeum deleted the initializer-native branch May 7, 2024 21:29
fmeum added a commit to fmeum/bazel that referenced this pull request May 10, 2024
Work towards bazelbuild#21622

RELNOTES: `native.package_relative_label` can now be used in rule initializers.

Closes bazelbuild#21740.

PiperOrigin-RevId: 631546734
Change-Id: Id6eb237f0f79195b678bb954deaef071e1c45ab1
Kila2 pushed a commit to Kila2/bazel that referenced this pull request May 13, 2024
Work towards bazelbuild#21622

RELNOTES: `native.package_relative_label` can now be used in rule initializers.

Closes bazelbuild#21740.

PiperOrigin-RevId: 631546734
Change-Id: Id6eb237f0f79195b678bb954deaef071e1c45ab1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants