Add method to ConstraintCollection to enable checking for the presence of a specific constraint value.

Part of the work on #10368.

PiperOrigin-RevId: 285080167
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
index 049f573..4e40cd5 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
@@ -42,6 +42,7 @@
 import com.google.devtools.build.lib.util.Fingerprint;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Objects;
 import java.util.function.Function;
 import javax.annotation.Nullable;
 
@@ -208,6 +209,12 @@
     return false;
   }
 
+  @Override
+  public boolean hasConstraintValue(ConstraintValueInfo constraintValue) {
+    ConstraintValueInfo discoveredConstraintValue = this.get(constraintValue.constraint());
+    return Objects.equals(constraintValue, discoveredConstraintValue);
+  }
+
   /**
    * Returns the {@link ConstraintValueInfo} for the given {@link ConstraintSettingInfo}, or {@code
    * null} if none exists.
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/ConstraintCollectionApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/ConstraintCollectionApi.java
index 8561ff3..fdd0a18 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/ConstraintCollectionApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/ConstraintCollectionApi.java
@@ -70,4 +70,17 @@
       },
       enableOnlyWithFlag = FlagIdentifier.EXPERIMENTAL_PLATFORM_API)
   boolean has(ConstraintSettingInfoT constraint);
+
+  @SkylarkCallable(
+      name = "has_constraint_value",
+      doc = "Returns whether the specific ConstraintValueInfo is set.",
+      parameters = {
+        @Param(
+            name = "constraint_value",
+            type = ConstraintValueInfoApi.class,
+            named = true,
+            doc = "The constraint value to check.")
+      },
+      enableOnlyWithFlag = FlagIdentifier.EXPERIMENTAL_PLATFORM_API)
+  boolean hasConstraintValue(ConstraintValueInfoT constraintValue);
 }
diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintCollectionApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintCollectionApiTest.java
index 18f7309..f1865ed 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintCollectionApiTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintCollectionApiTest.java
@@ -124,11 +124,13 @@
         "  value_from_get = constraint_collection.get(constraint_setting)",
         "  used_constraints = constraint_collection.constraint_settings",
         "  has_constraint = constraint_collection.has(constraint_setting)",
+        "  has_constraint_value = constraint_collection.has_constraint_value(value_from_get)",
         "  return [result(",
         "    value_from_index = value_from_index,",
         "    value_from_get = value_from_get,",
         "    used_constraints = used_constraints,",
         "    has_constraint = has_constraint,",
+        "    has_constraint_value = has_constraint_value,",
         "  )]",
         "verify = rule(",
         "  implementation = _impl,",
@@ -178,6 +180,9 @@
 
     boolean hasConstraint = (boolean) info.getValue("has_constraint");
     assertThat(hasConstraint).isTrue();
+
+    boolean hasConstraintValue = (boolean) info.getValue("has_constraint_value");
+    assertThat(hasConstraintValue).isTrue();
   }
 
   @Test