Add `--skip_incompatible_explicit_targets` option

This adds an argument to skip incompatible targets even if they were explicitly requested on the command line. This is useful for CI to allow it to build changed targets from rdeps queries without needing to filter them all through a cquery to check if they are compatible.

Closes #17403

RELNOTES: Add `--skip_incompatible_explicit_targets` option

Closes #17404.

PiperOrigin-RevId: 519636134
Change-Id: I16d6a4896cf920f42364cba162001b1bb7658e65
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java
index 80a9da6..f182416 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java
@@ -29,6 +29,7 @@
   private final TestType testType;
   private final boolean strictActionConflictCheck;
   private final boolean explicitlyRequested;
+  private final boolean skipIncompatibleExplicitTargets;
   private final boolean isTopLevelAspectDriver;
 
   private BuildDriverKey(
@@ -36,12 +37,14 @@
       TopLevelArtifactContext topLevelArtifactContext,
       boolean strictActionConflictCheck,
       boolean explicitlyRequested,
+      boolean skipIncompatibleExplicitTargets,
       boolean isTopLevelAspectDriver,
       TestType testType) {
     this.actionLookupKey = actionLookupKey;
     this.topLevelArtifactContext = topLevelArtifactContext;
     this.strictActionConflictCheck = strictActionConflictCheck;
     this.explicitlyRequested = explicitlyRequested;
+    this.skipIncompatibleExplicitTargets = skipIncompatibleExplicitTargets;
     this.isTopLevelAspectDriver = isTopLevelAspectDriver;
     this.testType = testType;
   }
@@ -50,13 +53,15 @@
       ActionLookupKey actionLookupKey,
       TopLevelArtifactContext topLevelArtifactContext,
       boolean strictActionConflictCheck,
-      boolean explicitlyRequested) {
+      boolean explicitlyRequested,
+      boolean skipIncompatibleExplicitTargets) {
     return new BuildDriverKey(
         actionLookupKey,
         topLevelArtifactContext,
         strictActionConflictCheck,
         explicitlyRequested,
-        /*isTopLevelAspectDriver=*/ true,
+        skipIncompatibleExplicitTargets,
+        /* isTopLevelAspectDriver= */ true,
         TestType.NOT_TEST);
   }
 
@@ -65,13 +70,15 @@
       TopLevelArtifactContext topLevelArtifactContext,
       boolean strictActionConflictCheck,
       boolean explicitlyRequested,
+      boolean skipIncompatibleExplicitTargets,
       TestType testType) {
     return new BuildDriverKey(
         actionLookupKey,
         topLevelArtifactContext,
         strictActionConflictCheck,
         explicitlyRequested,
-        /*isTopLevelAspectDriver=*/ false,
+        skipIncompatibleExplicitTargets,
+        /* isTopLevelAspectDriver= */ false,
         testType);
   }
 
@@ -99,6 +106,10 @@
     return explicitlyRequested;
   }
 
+  public boolean shouldSkipIncompatibleExplicitTargets() {
+    return skipIncompatibleExplicitTargets;
+  }
+
   public boolean isTopLevelAspectDriver() {
     return isTopLevelAspectDriver;
   }