From 66a8d8410988e47fb82406e95d6866e5729288b5 Mon Sep 17 00:00:00 2001 From: Marc Zych Date: Thu, 16 Mar 2023 15:01:22 -0700 Subject: [PATCH 1/4] 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 --- site/en/extending/platforms.md | 3 +- .../build/lib/analysis/BuildView.java | 8 +++++- .../TopLevelConstraintSemantics.java | 18 +++++++----- .../AnalysisAndExecutionPhaseRunner.java | 1 + .../lib/buildtool/AnalysisPhaseRunner.java | 1 + .../lib/buildtool/BuildRequestOptions.java | 9 ++++++ .../lib/skyframe/BuildDriverFunction.java | 9 ++++-- .../build/lib/skyframe/BuildDriverKey.java | 13 ++++++++- .../build/lib/skyframe/SkyframeBuildView.java | 5 +++- .../analysis/util/BuildViewForTesting.java | 1 + .../target_compatible_with_test.sh | 28 +++++++++++++++++++ 11 files changed, 82 insertions(+), 14 deletions(-) diff --git a/site/en/extending/platforms.md b/site/en/extending/platforms.md index e6b3ff889b7068..7fc73e8d05975a 100644 --- a/site/en/extending/platforms.md +++ b/site/en/extending/platforms.md @@ -162,7 +162,8 @@ In other words, `test_suite` targets on the command line behave like `:all` and `test_suite` targets with incompatible tests to also be incompatible. Explicitly specifying an incompatible target on the command line results in an -error message and a failed build. +error message and a failed build unless `--skip_incompatible_explicit_targets` +is enabled: ```console $ bazel build --platforms=//:myplatform //:target_incompatible_with_myplatform diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java index cc3fa45f7fc1d0..cd4087524188a8 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java @@ -211,6 +211,7 @@ public AnalysisResult update( ImmutableMap aspectsParameters, AnalysisOptions viewOptions, boolean keepGoing, + boolean skipIncompatibleExplicitTargets, boolean checkForActionConflicts, QuiescingExecutors executors, TopLevelArtifactContext topLevelOptions, @@ -426,6 +427,7 @@ public AnalysisResult update( getCoverageArtifactsHelper( configuredTargets, allTargetsToTest, eventHandler, eventBus, loadingResult), keepGoing, + skipIncompatibleExplicitTargets, targetOptions.get(CoreOptions.class).strictConflictChecks, checkForActionConflicts, executors, @@ -492,7 +494,11 @@ public AnalysisResult update( PlatformRestrictionsResult platformRestrictions = topLevelConstraintSemantics.checkPlatformRestrictions( - skyframeAnalysisResult.getConfiguredTargets(), explicitTargetPatterns, keepGoing); + skyframeAnalysisResult.getConfiguredTargets(), + explicitTargetPatterns, + keepGoing, + skipIncompatibleExplicitTargets + ); if (!platformRestrictions.targetsWithErrors().isEmpty()) { // If there are any errored targets (e.g. incompatible targets that are explicitly diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java index a1003ea5638ec7..08481de8e57c72 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java @@ -112,7 +112,8 @@ public static PlatformCompatibility compatibilityWithPlatformRestrictions( ConfiguredTarget configuredTarget, ExtendedEventHandler eventHandler, boolean eagerlyThrowError, - boolean explicitlyRequested) + boolean explicitlyRequested, + boolean skipIncompatibleExplicitTargets) throws TargetCompatibilityCheckException { RuleContextConstraintSemantics.IncompatibleCheckResult incompatibleCheckResult = @@ -124,7 +125,7 @@ public static PlatformCompatibility compatibilityWithPlatformRestrictions( // We need the label in unambiguous form here. I.e. with the "@" prefix for targets in the // main repository. explicitTargetPatterns is also already in the unambiguous form to make // comparison succeed regardless of the provided form. - if (explicitlyRequested) { + if (!skipIncompatibleExplicitTargets && explicitlyRequested) { if (eagerlyThrowError) { // Use the slightly simpler form for printing error messages. I.e. no "@" prefix for // targets in the main repository. @@ -136,7 +137,8 @@ public static PlatformCompatibility compatibilityWithPlatformRestrictions( String.format(TARGET_INCOMPATIBLE_ERROR_TEMPLATE, configuredTarget.getLabel(), ""))); return PlatformCompatibility.INCOMPATIBLE_EXPLICIT; } - // If this is not an explicitly requested target we can safely skip it. + // We can safely skip this target if it wasn't explicitly requested or we've been instructed + // to skip explicitly requested targets. return PlatformCompatibility.INCOMPATIBLE_IMPLICIT; } @@ -240,8 +242,8 @@ public static EnvironmentCompatibility compatibilityWithTargetEnvironment( * the command line should be skipped. * *

Targets that are incompatible with the target platform and *are* explicitly requested on the - * command line are errored. Having one or more errored targets will cause the entire build to - * fail with an error message. + * command line are errored unless --skip_incompatible_explicit_targets is enabled. Having one or + * more errored targets will cause the entire build to fail with an error message. * * @param topLevelTargets the build's top-level targets * @param explicitTargetPatterns the set of explicit target patterns specified by the user on the @@ -254,7 +256,8 @@ public static EnvironmentCompatibility compatibilityWithTargetEnvironment( public PlatformRestrictionsResult checkPlatformRestrictions( ImmutableSet topLevelTargets, ImmutableSet