Add new global attribute: applicable_licenses
- Package level default with default_applicable_licenses
- guarded by --incompatible_applicable_licenses (default true for Blaze, false for Bazel)

Import features:
- applicable_licenses is not configurable. Software does not get a different
  license in different environments. The license it is provided under dictates
  what type of environments you may use it in.
- applicable_licenses is exempt from compatible_with checks. For the same
  reason.

Since there is currently no actual behavior within Bazel, the test cases
are located with @rules_license. In the future, we will add provider
checking to applicable_licenses. (b/148601291), at which point there
must be positive and negative tests alongside the Bazel code.

RELNOTES:
Add new global attribute: applicable_licenses
- Package level default with default_applicable_licenses
- guarded by --incompatible_applicable_licenses (default true for Blaze, false for Bazel)
- In support of https://docs.google.com/document/d/1uwBuhAoBNrw8tmFs-NxlssI6VRolidGYdYqagLqHWt8/edit#
PiperOrigin-RevId: 296042678
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 301cc77..4e78bea 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
@@ -135,6 +135,10 @@
   public static final PathFragment EXPERIMENTAL_PREFIX = PathFragment.create("experimental");
   public static final String EXEC_COMPATIBLE_WITH_ATTR = "exec_compatible_with";
   public static final String EXEC_PROPERTIES = "exec_properties";
+  /*
+   * The attribute that declares the set of license labels which apply to this target.
+   */
+  public static final String APPLICABLE_LICENSES_ATTR = "applicable_licenses";
 
   /**
    * A constraint for the package name of the Rule instances.
@@ -2183,6 +2187,11 @@
    */
   private static Object getAttributeNoncomputedDefaultValue(Attribute attr,
       Package.Builder pkgBuilder) {
+    // TODO(b/149505729): Determine the right semantics for someone trying to define their own
+    // attribute named applicable_licenses.
+    if (attr.getName().equals("applicable_licenses")) {
+      return pkgBuilder.getDefaultApplicableLicenses();
+    }
     // Starlark rules may define their own "licenses" attributes with different types -
     // we shouldn't trigger the special "licenses" on those cases.
     if (attr.getName().equals("licenses") && attr.getType() == BuildType.LICENSE) {