-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really did mean "ambiguous" since the implementation used |
||
*/ | ||
public static class CustomFlagConverter implements Converter<String> { | ||
@Override | ||
public String convert(String input, Object conversionContext) throws OptionsParsingException { | ||
if (!input.startsWith("//") && !input.startsWith("@")) { | ||
// This is a --define flag. | ||
return input; | ||
} | ||
// A "/..." suffix is not valid label syntax, so replace it with valid syntax and transform | ||
// it back after conversion. | ||
String invalidSubpackagesSuffix = "/..."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make these constants in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made |
||
String validSubpackagesSuffix = ":__subpackages__"; | ||
String escapedUnconvertedLabel = | ||
input.endsWith(invalidSubpackagesSuffix) | ||
? input.substring(0, input.length() - invalidSubpackagesSuffix.length()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
+ validSubpackagesSuffix | ||
: input; | ||
String escapedConvertedLabel = | ||
convertOptionsLabel(escapedUnconvertedLabel, conversionContext).toString(); | ||
if (escapedConvertedLabel.endsWith(validSubpackagesSuffix)) { | ||
return escapedConvertedLabel.substring( | ||
0, escapedConvertedLabel.length() - validSubpackagesSuffix.length()) | ||
+ invalidSubpackagesSuffix; | ||
} | ||
return escapedConvertedLabel; | ||
} | ||
|
||
@Override | ||
public String getTypeDescription() { | ||
return "an absolute label or define"; | ||
} | ||
} | ||
|
||
/** Values for the --strict_*_deps option */ | ||
public enum StrictDepsMode { | ||
/** Silently allow referencing transitive dependencies. */ | ||
|
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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
--define
s.