Add --incompatible_disable_third_party_license_checking.
This flag makes all license-related BUILD syntax no-ops.
After this flag is permanently turned on in Bazel, we can start
stripping out the syntax.
This is unfortunately complex because it has to coherently interplay
with the related flag --check_third_party_targets_have_licenses.
See #7444 and #7553.
PiperOrigin-RevId: 235779781
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index 7f96fc4..a71cdaa 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -48,6 +48,7 @@
import com.google.devtools.build.lib.packages.BuildType.SelectorList;
import com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy.MissingFragmentPolicy;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
+import com.google.devtools.build.lib.packages.RuleClass.Builder.ThirdPartyLicenseExistencePolicy;
import com.google.devtools.build.lib.packages.RuleFactory.AttributeValues;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
@@ -671,6 +672,31 @@
private boolean supportsConstraintChecking = true;
+ /**
+ * The policy on whether Bazel should enforce that third_party rules declare <code>licenses().
+ * </code>. This is only intended for the migration of <a
+ * href="https://github.com/bazelbuild/bazel/issues/7444">GitHub #7444</a>. Our final end state
+ * is to have no license-related logic whatsoever. But that's going to take some time.
+ */
+ public enum ThirdPartyLicenseExistencePolicy {
+ /**
+ * Always do this check, overriding whatever {@link
+ * StarlarkSemanticsOptions#checkThirdPartyTargetsHaveLicenses} says.
+ */
+ ALWAYS_CHECK,
+
+ /**
+ * Never do this check, overriding whatever {@link
+ * StarlarkSemanticsOptions#checkThirdPartyTargetsHaveLicenses} says.
+ */
+ NEVER_CHECK,
+
+ /** Do whatever {@link StarlarkSemanticsOptions#checkThirdPartyTargetsHaveLicenses} says. */
+ USER_CONTROLLABLE
+ }
+
+ private ThirdPartyLicenseExistencePolicy thirdPartyLicenseExistencePolicy;
+
private final Map<String, Attribute> attributes = new LinkedHashMap<>();
private final Set<Label> requiredToolchains = new HashSet<>();
private boolean supportsPlatforms = true;
@@ -826,6 +852,7 @@
ruleDefinitionEnvironmentHashCode,
configurationFragmentPolicy.build(),
supportsConstraintChecking,
+ thirdPartyLicenseExistencePolicy,
requiredToolchains,
supportsPlatforms,
executionPlatformConstraintsAllowed,
@@ -1026,6 +1053,11 @@
return this;
}
+ public Builder setThirdPartyLicenseExistencePolicy(ThirdPartyLicenseExistencePolicy policy) {
+ this.thirdPartyLicenseExistencePolicy = policy;
+ return this;
+ }
+
public Builder setValidityPredicate(PredicateWithMessage<Rule> predicate) {
this.validityPredicate = predicate;
return this;
@@ -1497,6 +1529,8 @@
*/
private final boolean supportsConstraintChecking;
+ private final ThirdPartyLicenseExistencePolicy thirdPartyLicenseExistencePolicy;
+
private final ImmutableSet<Label> requiredToolchains;
private final boolean supportsPlatforms;
private final ExecutionPlatformConstraintsAllowed executionPlatformConstraintsAllowed;
@@ -1552,6 +1586,7 @@
String ruleDefinitionEnvironmentHashCode,
ConfigurationFragmentPolicy configurationFragmentPolicy,
boolean supportsConstraintChecking,
+ ThirdPartyLicenseExistencePolicy thirdPartyLicenseExistencePolicy,
Set<Label> requiredToolchains,
boolean supportsPlatforms,
ExecutionPlatformConstraintsAllowed executionPlatformConstraintsAllowed,
@@ -1591,6 +1626,7 @@
this.ignorePackageLicenses = ignorePackageLicenses;
this.configurationFragmentPolicy = configurationFragmentPolicy;
this.supportsConstraintChecking = supportsConstraintChecking;
+ this.thirdPartyLicenseExistencePolicy = thirdPartyLicenseExistencePolicy;
this.requiredToolchains = ImmutableSet.copyOf(requiredToolchains);
this.supportsPlatforms = supportsPlatforms;
this.executionPlatformConstraintsAllowed = executionPlatformConstraintsAllowed;
@@ -1835,7 +1871,17 @@
populateAttributeLocations(rule, ast);
}
checkForDuplicateLabels(rule, eventHandler);
- if (checkThirdPartyRulesHaveLicenses) {
+
+ boolean actuallyCheckLicense;
+ if (thirdPartyLicenseExistencePolicy == ThirdPartyLicenseExistencePolicy.ALWAYS_CHECK) {
+ actuallyCheckLicense = true;
+ } else if (thirdPartyLicenseExistencePolicy == ThirdPartyLicenseExistencePolicy.NEVER_CHECK) {
+ actuallyCheckLicense = false;
+ } else {
+ actuallyCheckLicense = checkThirdPartyRulesHaveLicenses;
+ }
+
+ if (actuallyCheckLicense) {
checkThirdPartyRuleHasLicense(rule, pkgBuilder, eventHandler);
}
checkForValidSizeAndTimeoutValues(rule, eventHandler);