Skip to content

Commit

Permalink
Move exception types out of PrerequisiteProducer.
Browse files Browse the repository at this point in the history
Moves NoMatchingPlatformException and IncompatibleTargetException out of
PrerequisiteProducer. These are used from a different package in a future CL.

PiperOrigin-RevId: 524093594
Change-Id: I008b793ff0c1cec14149cefd3f39805b9c5a71ff
  • Loading branch information
aoeui authored and copybara-github committed Apr 13, 2023
1 parent 5040b40 commit c8d036d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ public static Optional<RuleConfiguredTargetValue> createIndirectlyIncompatibleTa
transitivePackages));
}

/** Thrown if this target is platform-incompatible with the current build. */
public static class IncompatibleTargetException extends Exception {
private final RuleConfiguredTargetValue target;

public IncompatibleTargetException(RuleConfiguredTargetValue target) {
this.target = target;
}

public RuleConfiguredTargetValue target() {
return target;
}
}

/** Creates an incompatible target. */
private static RuleConfiguredTargetValue createIncompatibleRuleConfiguredTarget(
Target target,
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ java_library(
":map_as_package_roots",
":metadata_consumer_for_metrics",
":no_matching_platform_data",
":no_matching_platform_exception",
":node_dropping_inconsistency_receiver",
":output_store",
":package_error_function",
":package_error_message_function",
":package_identifier_batching_callback",
Expand Down Expand Up @@ -1660,6 +1660,16 @@ java_library(
],
)

java_library(
name = "no_matching_platform_exception",
srcs = ["NoMatchingPlatformException.java"],
deps = [
":no_matching_platform_data",
":toolchain_exception",
"//src/main/protobuf:failure_details_java_proto",
],
)

java_library(
name = "output_store",
srcs = ["OutputStore.java"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.devtools.build.lib.analysis.config.TransitionResolver;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.constraints.IncompatibleTargetChecker;
import com.google.devtools.build.lib.analysis.constraints.IncompatibleTargetChecker.IncompatibleTargetException;
import com.google.devtools.build.lib.analysis.test.AnalysisFailurePropagationException;
import com.google.devtools.build.lib.causes.AnalysisFailedCause;
import com.google.devtools.build.lib.causes.Cause;
Expand Down Expand Up @@ -266,7 +267,7 @@ public SkyValue compute(SkyKey key, Environment env)
new EmptyConfiguredTarget(
configuredTargetKey.getLabel(), configuredTargetKey.getConfigurationKey()),
state.transitivePackages == null ? null : state.transitivePackages.build());
} catch (PrerequisiteProducer.IncompatibleTargetException e) {
} catch (IncompatibleTargetException e) {
return e.target();
} catch (ConfiguredValueCreationException e) {
if (!e.getMessage().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.skyframe;

import com.google.devtools.build.lib.server.FailureDetails;

/** Indicates a missing execution platform. */
public final class NoMatchingPlatformException extends ToolchainException {
public NoMatchingPlatformException(NoMatchingPlatformData error) {
super(error.formatError());
}

@Override
protected FailureDetails.Toolchain.Code getDetailedCode() {
return FailureDetails.Toolchain.Code.NO_MATCHING_EXECUTION_PLATFORM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import com.google.devtools.build.lib.analysis.config.DependencyEvaluationException;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition;
import com.google.devtools.build.lib.analysis.constraints.IncompatibleTargetChecker;
import com.google.devtools.build.lib.analysis.constraints.IncompatibleTargetChecker.IncompatibleTargetException;
import com.google.devtools.build.lib.analysis.constraints.IncompatibleTargetChecker.IncompatibleTargetProducer;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.bugreport.BugReport;
Expand All @@ -70,7 +70,6 @@
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.server.FailureDetails;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetEvaluationExceptions.ReportedException;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetEvaluationExceptions.UnreportedException;
Expand Down Expand Up @@ -197,23 +196,6 @@ public void acceptValidationException(ValidationException e) {
*/
static class InconsistentNullConfigException extends Exception {}

/**
* Thrown if this target is platform-incompatible with the current build.
*
* <p>See {@link IncompatibleTargetChecker}.
*/
static class IncompatibleTargetException extends Exception {
private final RuleConfiguredTargetValue target;

public IncompatibleTargetException(RuleConfiguredTargetValue target) {
this.target = target;
}

public RuleConfiguredTargetValue target() {
return target;
}
}

/** Lets calling logic provide a semaphore to restrict the number of concurrent analysis calls. */
public interface SemaphoreAcquirer {
void acquireSemaphore() throws InterruptedException;
Expand Down Expand Up @@ -888,7 +870,7 @@ static ComputedToolchainContexts computeUnloadedToolchainContexts(
* any constraints added by the target, including those added for the target on the command line.
*/
public static ImmutableSet<Label> getExecutionPlatformConstraints(
Rule rule, PlatformConfiguration platformConfiguration) {
Rule rule, @Nullable PlatformConfiguration platformConfiguration) {
if (platformConfiguration == null) {
return ImmutableSet.of(); // See NoConfigTransition.
}
Expand Down Expand Up @@ -1308,15 +1290,4 @@ static DetailedExitCode getPrioritizedDetailedExitCode(NestedSet<Cause> causes)
}
return prioritizedDetailedExitCode;
}

private static class NoMatchingPlatformException extends ToolchainException {
NoMatchingPlatformException(NoMatchingPlatformData error) {
super(error.formatError());
}

@Override
protected FailureDetails.Toolchain.Code getDetailedCode() {
return FailureDetails.Toolchain.Code.NO_MATCHING_EXECUTION_PLATFORM;
}
}
}

0 comments on commit c8d036d

Please sign in to comment.