You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the check for being a package metadata rule
This allows the refactoring which will happen after default_applicable_licenses is renamed to default_package_metadata. The current behavior is intended to prevent
`applicable_licenses` from being set on a `license` rule. The required behavior is that we don't set `applicable_licenses` on any of the metadata rules.
Future changes might have to take into account the ability to set the license for a tool rule within `rules_package`.
For background, see https://docs.google.com/document/d/1uyJjkKbE8kV8EinakaR9q-Un25zCukhoH_dRBkWHSKQ/edit#heading=h.izpa22p82m6cCloses#16596.
PiperOrigin-RevId: 485457037
Change-Id: Ifb105f646ae0c291a6841b3ddb84ed536e9d71e3
* Returns true if this rule is a <code>license()</code> as described in
2701
+
* https://docs.google.com/document/d/1uwBuhAoBNrw8tmFs-NxlssI6VRolidGYdYqagLqHWt8/edit# or
2702
+
* similar metadata.
2703
+
*
2704
+
* <p>The intended use is to detect if this rule is of a type which would be used in <code>
2705
+
* default_package_metadata</code>, so that we don't apply it to an instanced of itself when
2706
+
* <code>applicable_licenses</code> is left unset. Doing so causes a self-referential loop. To
2707
+
* prevent that, we are overly cautious at this time, treating all rules from <code>@rules_license
2708
+
* </code> as potential metadata rules.
2709
+
*
2710
+
* <p>Most users will only use declarations from <code>@rules_license</code>. If they which to
2711
+
* create organization local rules, they must be careful to avoid loops by explicitly setting
2712
+
* <code>applicable_licenses</code> on each of the metadata targets they define, so that default
2713
+
* processing is not an issue.
2714
+
*/
2715
+
publicbooleanisPackageMetadataRule() {
2716
+
// If it was not defined in Starlark, it can not be a new style package metadata rule.
2717
+
if (ruleDefinitionEnvironmentLabel == null) {
2718
+
returnfalse;
2719
+
}
2720
+
if (ruleDefinitionEnvironmentLabel.getRepository().getName().equals("rules_license")) {
2721
+
// For now, we treat all rules in rules_license as potenial metadate rules.
2722
+
// In the future we should add a way to disambiguate the two. The least invasive
2723
+
// thing is to add a hidden attribute to mark metadata rules. That attribute
2724
+
// could have a default value referencing @rules_license//<something>. That style
2725
+
// of checking would allow users to apply it to their own metadata rules. We are
2726
+
// not building it today because the exact needs are not clear.
2727
+
returntrue;
2728
+
}
2729
+
// BEGIN-INTERNAL
2730
+
// TODO(aiuto): This is a Google-ism, remove from Bazel.
0 commit comments