Remove third party license checking from Bazel.

This doesn't remove --incompatible_disable_third_party_license_checking
but makes it a no-op. This is so the Google version of Bazel can migrate
on its own timeframe.

Because this logic was created before Bazel existed, removing it
from Google is going to take more time. We don't want that to slow
Bazel development.

See https://github.com/bazelbuild/bazel/issues/7444.

PiperOrigin-RevId: 241946385
diff --git a/src/main/java/com/google/devtools/build/lib/packages/License.java b/src/main/java/com/google/devtools/build/lib/packages/License.java
index c980444..3c44a0e 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/License.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/License.java
@@ -14,7 +14,6 @@
 
 package com.google.devtools.build.lib.packages;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
@@ -76,7 +75,6 @@
    * @param types a collection of license types
    * @return the least restrictive license type
    */
-  @VisibleForTesting
   public static LicenseType leastRestrictive(Collection<LicenseType> types) {
     // TODO(gregce): move this method to LicenseCheckingModule when Bazel's tests no longer use it
     return types.isEmpty() ? LicenseType.BY_EXCEPTION_ONLY : Collections.max(types);
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
index 64c982b..9dc7cca 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
@@ -751,9 +751,7 @@
             == ThirdPartyLicenseExistencePolicy.NEVER_CHECK) {
           checkLicenses = false;
         } else {
-          checkLicenses =
-              env.getSemantics().checkThirdPartyTargetsHaveLicenses()
-                  && !env.getSemantics().incompatibleDisableThirdPartyLicenseChecking();
+          checkLicenses = !env.getSemantics().incompatibleDisableThirdPartyLicenseChecking();
         }
 
         if (checkLicenses
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 328a840..4bdf988 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
@@ -693,17 +693,20 @@
     public enum ThirdPartyLicenseExistencePolicy {
       /**
        * Always do this check, overriding whatever {@link
-       * StarlarkSemanticsOptions#checkThirdPartyTargetsHaveLicenses} says.
+       * StarlarkSemanticsOptions#incompatibleDisableThirdPartyLicenseChecking} says.
        */
       ALWAYS_CHECK,
 
       /**
        * Never do this check, overriding whatever {@link
-       * StarlarkSemanticsOptions#checkThirdPartyTargetsHaveLicenses} says.
+       * StarlarkSemanticsOptions#incompatibleDisableThirdPartyLicenseChecking} says.
        */
       NEVER_CHECK,
 
-      /** Do whatever {@link StarlarkSemanticsOptions#checkThirdPartyTargetsHaveLicenses} says. */
+      /**
+       * Do whatever {@link StarlarkSemanticsOptions#incompatibleDisableThirdPartyLicenseChecking}
+       * says.
+       */
       USER_CONTROLLABLE
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
index efea73a..35517ed 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
@@ -128,20 +128,14 @@
     AttributesAndLocation generator =
         generatorAttributesForMacros(attributeValues, env, location, label);
     try {
-      // Examines --check_third_party_targets_have_licenses and
-      // --incompatible_disable_third_party_license_checking to see if we should check third_party
-      // targets for license existence. The latter flag overrides the former.
+      // Examines --incompatible_disable_third_party_license_checking to see if we should check
+      // third party targets for license existence.
       //
-      // Note that *both* flags are overridable by RuleClass.ThirdPartyLicenseEnforcementPolicy
-      // (which is checked in RuleClass). This lets Bazel and Blaze migrate away from license logic
-      // on independent timelines. See --incompatible_disable_third_party_license_checking comments
-      // for details.
-      boolean checkThirdPartyLicenses;
-      if (env == null || env.getSemantics().incompatibleDisableThirdPartyLicenseChecking()) {
-        checkThirdPartyLicenses = false;
-      } else {
-        checkThirdPartyLicenses = env.getSemantics().checkThirdPartyTargetsHaveLicenses();
-      }
+      // This flag is overridable by RuleClass.ThirdPartyLicenseEnforcementPolicy (which is checked
+      // in RuleClass). This lets Bazel and Blaze migrate away from license logic on independent
+      // timelines. See --incompatible_disable_third_party_license_checking comments for details.
+      boolean checkThirdPartyLicenses =
+          env != null && !env.getSemantics().incompatibleDisableThirdPartyLicenseChecking();
       return ruleClass.createRule(
           pkgBuilder,
           label,
diff --git a/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java
index af68aa1..29a2f4a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java
@@ -60,18 +60,6 @@
 
   // <== Add new options here in alphabetic order ==>
 
-  /**
-   * This can be overridden by {@link RuleClass.Builder.ThirdPartyLicenseExistencePolicy} and {@link
-   * #incompatibleDisableThirdPartyLicenseChecking}.
-   */
-  @Option(
-      name = "check_third_party_targets_have_licenses",
-      defaultValue = "true",
-      documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
-      effectTags = OptionEffectTag.BUILD_FILE_SEMANTICS,
-      help = "If true, all rules and files under //third_party must declare licenses([])")
-  public boolean checkThirdPartyTargetsHaveLicenses;
-
   @Option(
       name = "experimental_build_setting_api",
       defaultValue = "false",
@@ -221,22 +209,14 @@
       help = "If set to true, disallow use of deprecated resource fields on the Objc provider.")
   public boolean incompatibleDisableObjcProviderResources;
 
-  // Once this migration is complete, instead of removing this flag we need to make it a no-op.
-  // This is because we'll need to keep it around for a while so Google's migration can complete
-  // after Bazel's. This is an example of Bazel's Google roots being methodically torn out:
-  // because this functionality was introduced for Google before Bazel existed, Google's
-  // dependency on it is deeper. We don't want this to add unnecessary baggage to Bazel or slow
-  // down Bazel's development. So this approach, while slightly awkward, relieves Bazel of
-  // Google's technical debt (which shouldn't be Bazel's problem). This means you as a Bazel
-  // user are getting better code than Google has! (for a while, at least)
+  // For Bazel, this flag is a no-op. Bazel doesn't support built-in third party license checking
+  // (see https://github.com/bazelbuild/bazel/issues/7444).
   //
-  // Track migration at https://github.com/bazelbuild/bazel/issues/7444. When we're ready to
-  // remove Bazel support, instead of removing the flag we should do these things:
-  //
-  // 1) BazelRuleClassProvider: set the third party license existence policy to NEVER_CHECK (see
-  //    the related TODO(gregce) comment in that file).
-  // 2) Remove LicenseCheckingModule.
-  // 3) Remove --check_third_party_targets_have_licenses.
+  // For Blaze in Google, this flag is still needed to deprecate the logic that's already been
+  // removed from Bazel. That logic was introduced before Bazel existed, so Google's dependency on
+  // it is deeper. But we don't want that to add unnecessary baggage to Bazel or slow down Bazel's
+  // development. So this flag lets Blaze migrate on a slower timeline without blocking Bazel. This
+  // means you as a Bazel user are getting better code than Google has! (for a while, at least)
   @Option(
       name = "incompatible_disable_third_party_license_checking",
       defaultValue = "true",
@@ -246,9 +226,7 @@
         OptionMetadataTag.INCOMPATIBLE_CHANGE,
         OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
       },
-      help =
-          "If true, disables all license checking logic. This overrides "
-              + "--check_third_party_targets_have_licenses")
+      help = "If true, disables all license checking logic")
   public boolean incompatibleDisableThirdPartyLicenseChecking;
 
   @Option(
@@ -534,7 +512,6 @@
   public StarlarkSemantics toSkylarkSemantics() {
     return StarlarkSemantics.builder()
         // <== Add new options here in alphabetic order ==>
-        .checkThirdPartyTargetsHaveLicenses(checkThirdPartyTargetsHaveLicenses)
         .experimentalBuildSettingApi(experimentalBuildSettingApi)
         .experimentalCcSkylarkApiEnabledPackages(experimentalCcSkylarkApiEnabledPackages)
         .experimentalEnableAndroidMigrationApis(experimentalEnableAndroidMigrationApis)