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

Fixups to use of Labels to support bzlmod #872

Merged
merged 5 commits into from
Apr 7, 2022

Conversation

jsharpe
Copy link
Member

@jsharpe jsharpe commented Feb 9, 2022

No description provided.

@jsharpe jsharpe requested a review from UebelAndre February 9, 2022 22:00
@jsharpe jsharpe marked this pull request as ready for review February 9, 2022 22:00
@jsharpe
Copy link
Member Author

jsharpe commented Feb 9, 2022

For context see PR to bzlmod registry:
bazelbuild/bazel-central-registry#65 (comment)

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Good to know, Thanks!

Just a nit and a question 😄

doc = "The label of a `.bzl` source which defines toolchain commands",
allow_files = [".bzl"],
"commands_src": attr.string(
doc = "The string of a `.bzl` source which defines toolchain commands",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove the .bzl restriction?

Copy link
Member Author

Choose a reason for hiding this comment

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

because it becomes a string here - bzlmod remaps the names of the repos and so we can't evaluate the Label at this point as it gets used in the context of another repo so unfortunately we need to pass it through as a string here. It's a bit brittle but as its all internal it works but isn't great.
I guess the real solution is to move the .bzl into the generated repo itself so we don't need to resolve a label to access it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oooh, I didn't notice that the type changed. I'm more nervous about making larger changes than needing to restrict the values here. This seems fine.

@@ -96,7 +89,7 @@ def register_framework_toolchains(register_toolchains = True):

for item in TOOLCHAIN_MAPPINGS:
# Generate a toolchain name without the `.bzl` suffix
toolchain_name = "rules_foreign_cc_framework_toolchain_" + item.file.name[:-len(".bzl")]
toolchain_name = "rules_foreign_cc_framework_toolchain_" + item.file.split(":")[1][:-len(".bzl")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Always nervous about raw indexing. Can you update the comment to be a bit more descriptive about that?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not great - the generated name you get within bzlmod is even more horific due to the injection of the .ext. from the extension name into the repo name. Maybe we should just put the name of the repo explicitly into TOOLCHAIN_MAPPING instead of trying to do string manipulation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine just want to make sure the expectation is super clear as indexing is easy to miss.

I think it's probably time to discuss writing a process wrapper instead of making more changes to the toolchain. If you could assign item.file.split(":")[1][:-len(".bzl")] to another value with some comment I'd be happy.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the name of the repo into TOOLCHAIN_MAPPING so it is now explicit as to what this name is rather than deriving something from a string.
I also slightly simplified the generated repo but at the expense of some boiler plate in each of the *_commands.bzl files to export a struct.
I think I'd follow this up with a commit that would remove the whole generated repo logic here in favour of just explicitly enumerating the toolchain instances in a BUILD file in the main repo. Its overly complex at the moment for no real reason.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good pending the comment about the indexing 😄

doc = "The label of a `.bzl` source which defines toolchain commands",
allow_files = [".bzl"],
"commands_src": attr.string(
doc = "The string of a `.bzl` source which defines toolchain commands",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oooh, I didn't notice that the type changed. I'm more nervous about making larger changes than needing to restrict the values here. This seems fine.

@@ -96,7 +89,7 @@ def register_framework_toolchains(register_toolchains = True):

for item in TOOLCHAIN_MAPPINGS:
# Generate a toolchain name without the `.bzl` suffix
toolchain_name = "rules_foreign_cc_framework_toolchain_" + item.file.name[:-len(".bzl")]
toolchain_name = "rules_foreign_cc_framework_toolchain_" + item.file.split(":")[1][:-len(".bzl")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine just want to make sure the expectation is super clear as indexing is easy to miss.

I think it's probably time to discuss writing a process wrapper instead of making more changes to the toolchain. If you could assign item.file.split(":")[1][:-len(".bzl")] to another value with some comment I'd be happy.

@jsharpe
Copy link
Member Author

jsharpe commented Apr 6, 2022

@UebelAndre PTAL when you get a moment, hopefully the changes I've made end up in simpler code in the end despite being a bit more churn.

@jsharpe jsharpe merged commit 4aa243d into bazel-contrib:main Apr 7, 2022
@jsharpe jsharpe deleted the bzlmod_labels branch April 7, 2022 15:44
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