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

Fix label conversion for --experimental_propagate_custom_flag #25259

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

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Feb 12, 2025

Also fix and enable a test in Bazel.

Fixes #25208

@fmeum fmeum requested a review from a team as a code owner February 12, 2025 07:51
@fmeum fmeum requested review from gregestren and removed request for a team February 12, 2025 07:51
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Feb 12, 2025
@@ -234,6 +234,42 @@ public String getTypeDescription() {
}
}

/**
* Flag converter for canonicalizing a label (possibly with a "/..." suffix) and/or define by
* converting the label to ambiguous canonical form.
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean "unambiguous canonical form", or is "ambiguous" correct here and I am misunderstanding?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I really did mean "ambiguous" since the implementation used toString(), but I now changed this to getUnambiguousCanonicalForm() for clarity.

}
// A "/..." suffix is not valid label syntax, so replace it with valid syntax and transform
// it back after conversion.
String invalidSubpackagesSuffix = "/...";
Copy link
Member

Choose a reason for hiding this comment

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

Make these constants in the CustomFlagConverter class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made /... a constant as it has meaning, but :__subpackages__ is arbitrary and not used anywhere else, so defining a constant for it may, in my opinion, even hurt readability.

String validSubpackagesSuffix = ":__subpackages__";
String escapedUnconvertedLabel =
input.endsWith(invalidSubpackagesSuffix)
? input.substring(0, input.length() - invalidSubpackagesSuffix.length())
Copy link
Member

Choose a reason for hiding this comment

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

Instead of the substring call, use String.replace. Any instance of /... inside the label is invalid anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wouldn't //...super_hidden_folder:foo be a valid label? I can still do this, but I'm not sure it's theoretically correct.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, I hope no-one is naming packages like that but it's technically possible, so leave this as-is.

@@ -234,6 +234,42 @@ public String getTypeDescription() {
}
}

/**
* Flag converter for canonicalizing a label (possibly with a "/..." suffix) and/or define by
Copy link
Member

Choose a reason for hiding this comment

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

Why does this mention --define (also the comment on line 245). It doesn't look like this converter is used except for with --experimental_propagate_custom_flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The option accepts both Starlark flags and --defines.

@fmeum fmeum requested a review from katre February 12, 2025 21:45
String validSubpackagesSuffix = ":__subpackages__";
String escapedUnconvertedLabel =
input.endsWith(invalidSubpackagesSuffix)
? input.substring(0, input.length() - invalidSubpackagesSuffix.length())
Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, I hope no-one is naming packages like that but it's technically possible, so leave this as-is.

@katre katre added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Feb 12, 2025
@fmeum
Copy link
Collaborator Author

fmeum commented Feb 12, 2025

@bazel-io fork 8.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally team-Configurability platforms, toolchains, cquery, select(), config transitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--experimental_propagate_custom_flag is error-prone
3 participants