diff options
author | 2018-01-16 13:04:56 -0800 | |
---|---|---|
committer | 2018-01-16 13:06:21 -0800 | |
commit | 47ef92d437972aee06ab2caff2cb12cd617adc9a (patch) | |
tree | 41008957feccdf3d3473402957a8e0855d97d26a /src/main/java/com/google/devtools/build/lib/analysis/config | |
parent | 225b57bfbb74a62a3212c7013ef92ce95ceaf79e (diff) |
Remove ConfigurationTransitionProxy.NULL
PiperOrigin-RevId: 182099803
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/config')
3 files changed, 42 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/TransitionResolver.java b/src/main/java/com/google/devtools/build/lib/analysis/config/TransitionResolver.java index 09fa8a1741..44530445c5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/TransitionResolver.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/TransitionResolver.java @@ -19,6 +19,7 @@ import com.google.common.base.Preconditions; import com.google.devtools.build.lib.analysis.TargetAndConfiguration; import com.google.devtools.build.lib.analysis.config.transitions.ComposingSplitTransition; import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransitionProxy; +import com.google.devtools.build.lib.analysis.config.transitions.NullTransition; import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition; import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition; import com.google.devtools.build.lib.analysis.config.transitions.Transition; @@ -70,7 +71,7 @@ public final class TransitionResolver { // I. Input files and package groups have no configurations. We don't want to duplicate them. if (usesNullConfiguration(toTarget)) { - return ConfigurationTransitionProxy.NULL; + return NullTransition.INSTANCE; } // II. Host configurations never switch to another. All prerequisites of host targets have the @@ -166,9 +167,9 @@ public final class TransitionResolver { return transition1; } else if (transition2 == ConfigurationTransitionProxy.NONE) { return transition1; - } else if (transition2 == ConfigurationTransitionProxy.NULL) { + } else if (transition2 == NullTransition.INSTANCE) { // A NULL transition can just replace earlier transitions: no need to compose them. - return ConfigurationTransitionProxy.NULL; + return NullTransition.INSTANCE; } else if (transition2.isHostTransition()) { // A HOST transition can just replace earlier transitions: no need to compose them. // But it also improves performance: host transitions are common, and @@ -189,7 +190,7 @@ public final class TransitionResolver { * be composed after it. */ private static boolean isFinal(Transition transition) { - return (transition == ConfigurationTransitionProxy.NULL + return (transition == NullTransition.INSTANCE || transition == HostTransition.INSTANCE); } @@ -197,7 +198,7 @@ public final class TransitionResolver { * Applies the given split and composes it after an existing transition. */ private static Transition split(Transition currentTransition, SplitTransition split) { - Preconditions.checkState(currentTransition != ConfigurationTransitionProxy.NULL, + Preconditions.checkState(currentTransition != NullTransition.INSTANCE, "cannot apply splits after null transitions (null transitions are expected to be final)"); Preconditions.checkState(currentTransition != HostTransition.INSTANCE, "cannot apply splits after host transitions (host transitions are expected to be final)"); diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ConfigurationTransitionProxy.java b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ConfigurationTransitionProxy.java index 3df17bf1af..6a19b36fbb 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ConfigurationTransitionProxy.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ConfigurationTransitionProxy.java @@ -25,9 +25,6 @@ public enum ConfigurationTransitionProxy implements Transition { /** No transition, i.e., the same configuration as the current. */ NONE, - /** Transition to a null configuration (applies to, e.g., input files). */ - NULL, - /** Transition from the target configuration to the data configuration. */ // TODO(bazel-team): Move this elsewhere. DATA, diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/NullTransition.java b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/NullTransition.java new file mode 100644 index 0000000000..2edbb9fb0f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/NullTransition.java @@ -0,0 +1,36 @@ +// Copyright 2018 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.analysis.config.transitions; + +import com.google.devtools.build.lib.analysis.config.BuildOptions; + +/** + * A {@link PatchTransition} to a null configuration. + */ +public class NullTransition implements PatchTransition { + + public static final NullTransition INSTANCE = new NullTransition(); + + private NullTransition() { + } + + @Override + public BuildOptions apply(BuildOptions options) { + throw new UnsupportedOperationException( + "This is only referenced in a few places, so it's easier and more efficient to optimize " + + "Blaze's transition logic in the presence of null transitions vs. actually call this " + + "method to get results we know ahead of time. If there's ever a need to properly " + + "implement this method we can always do so."); + } +} |