diff --git a/site/en/extending/platforms.md b/site/en/extending/platforms.md index e6b3ff889b7068..901e18806bad1b 100644 --- a/site/en/extending/platforms.md +++ b/site/en/extending/platforms.md @@ -172,6 +172,9 @@ ERROR: Target //:target_incompatible_with_myplatform is incompatible and cannot FAILED: Build did NOT complete successfully ``` +Incompatible explicit targets are silently skipped if +`--skip_incompatible_explicit_targets` is enabled. + ### More expressive constraints {:#expressive-constraints} For more flexibility in expressing constraints, use the diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java index f6c9ed8fa3655e..7cd66de8b88283 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java @@ -51,6 +51,18 @@ public class AnalysisOptions extends OptionsBase { ) public int maxConfigChangesToShow; + @Option( + name = "skip_incompatible_explicit_targets", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY, + effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, + help = + "Skip incompatible targets that are explicitly listed on the command line. " + + "By default, building such targets results in an error but they are " + + "silently skipped when this option is enabled. See: " + + "https://bazel.build/extending/platforms#skipping-incompatible-targets") + public boolean skipIncompatibleExplicitTargets; + @Option( name = "experimental_extra_action_filter", defaultValue = "", 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..29be53e217354e 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,10 @@ 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..75baaddf1abf52 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