aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2018-07-17 16:15:13 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-17 16:16:53 -0700
commitceafeaef5977d0671c44c86864b9a4b2b0e5ee04 (patch)
treed43eb99c1b18f53390c262c237eab28892111da8 /src/main/java/com
parentf341e0d376cdb517a2fb6c68d835657c89e46b9a (diff)
Move target pattern work to new util class
Change-Id: Ib1a29a927fa6fd3f49e03efa3b73e1547df6cacd PiperOrigin-RevId: 204993474
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java103
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java68
4 files changed, 110 insertions, 74 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
index 4ec5e7faca..ae7697641d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
@@ -69,12 +69,12 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
ImmutableList<Label> platformLabels;
try {
platformLabels =
- ToolchainUtil.expandTargetPatterns(
+ TargetPatternUtil.expandTargetPatterns(
env, targetPatterns.build(), FilteringPolicies.ruleType("platform", true));
if (env.valuesMissing()) {
return null;
}
- } catch (ToolchainUtil.InvalidTargetPatternException e) {
+ } catch (TargetPatternUtil.InvalidTargetPatternException e) {
throw new RegisteredExecutionPlatformsFunctionException(
new InvalidExecutionPlatformLabelException(e), Transience.PERSISTENT);
}
@@ -144,7 +144,8 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
*/
static final class InvalidExecutionPlatformLabelException extends Exception {
- public InvalidExecutionPlatformLabelException(ToolchainUtil.InvalidTargetPatternException e) {
+ public InvalidExecutionPlatformLabelException(
+ TargetPatternUtil.InvalidTargetPatternException e) {
this(e.getInvalidPattern(), e.getTpe());
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
index b581130b8b..8b39dd94f6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
@@ -72,12 +72,12 @@ public class RegisteredToolchainsFunction implements SkyFunction {
ImmutableList<Label> toolchainLabels;
try {
toolchainLabels =
- ToolchainUtil.expandTargetPatterns(
+ TargetPatternUtil.expandTargetPatterns(
env, targetPatterns.build(), FilteringPolicies.ruleType("toolchain", true));
if (env.valuesMissing()) {
return null;
}
- } catch (ToolchainUtil.InvalidTargetPatternException e) {
+ } catch (TargetPatternUtil.InvalidTargetPatternException e) {
throw new RegisteredToolchainsFunctionException(
new InvalidToolchainLabelException(e), Transience.PERSISTENT);
}
@@ -181,7 +181,7 @@ public class RegisteredToolchainsFunction implements SkyFunction {
"target does not provide the DeclaredToolchainInfo provider"));
}
- public InvalidToolchainLabelException(ToolchainUtil.InvalidTargetPatternException e) {
+ public InvalidToolchainLabelException(TargetPatternUtil.InvalidTargetPatternException e) {
this(e.getInvalidPattern(), e.getTpe());
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java
new file mode 100644
index 0000000000..cd692f9ef1
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java
@@ -0,0 +1,103 @@
+// 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.skyframe;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.TargetParsingException;
+import com.google.devtools.build.lib.pkgcache.FilteringPolicy;
+import com.google.devtools.build.skyframe.SkyFunction.Environment;
+import com.google.devtools.build.skyframe.SkyKey;
+import com.google.devtools.build.skyframe.ValueOrException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * Utility class to help with evaluating target patterns.
+ */
+public class TargetPatternUtil {
+
+ /**
+ * Expand the given {@code targetPatterns}, using the {@code filteringPolicy}. This handles the
+ * needed underlying Skyframe calls (via {@code env}), and no will return {@code null} to signal a
+ * Skyframe restart.
+ */
+ @Nullable
+ public static ImmutableList<Label> expandTargetPatterns(
+ Environment env, List<String> targetPatterns, FilteringPolicy filteringPolicy)
+ throws InvalidTargetPatternException, InterruptedException {
+
+ // First parse the patterns, and throw any errors immediately.
+ List<TargetPatternValue.TargetPatternKey> patternKeys = new ArrayList<>();
+ for (TargetPatternValue.TargetPatternSkyKeyOrException keyOrException :
+ TargetPatternValue.keys(targetPatterns, filteringPolicy, "")) {
+
+ try {
+ patternKeys.add(keyOrException.getSkyKey());
+ } catch (TargetParsingException e) {
+ throw new InvalidTargetPatternException(keyOrException.getOriginalPattern(), e);
+ }
+ }
+
+ // Then, resolve the patterns.
+ Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns =
+ env.getValuesOrThrow(patternKeys, TargetParsingException.class);
+ boolean valuesMissing = env.valuesMissing();
+ ImmutableList.Builder<Label> labels = valuesMissing ? null : new ImmutableList.Builder<>();
+
+ for (TargetPatternValue.TargetPatternKey pattern : patternKeys) {
+ TargetPatternValue value;
+ try {
+ value = (TargetPatternValue) resolvedPatterns.get(pattern).get();
+ if (!valuesMissing && value != null) {
+ labels.addAll(value.getTargets().getTargets());
+ }
+ } catch (TargetParsingException e) {
+ throw new InvalidTargetPatternException(pattern.getPattern(), e);
+ }
+ }
+
+ if (valuesMissing) {
+ return null;
+ }
+
+ return labels.build();
+ }
+
+ /**
+ * Exception used when an error occurs in {@link #expandTargetPatterns(Environment, List,
+ * FilteringPolicy)}.
+ */
+ static final class InvalidTargetPatternException extends Exception {
+ private String invalidPattern;
+ private TargetParsingException tpe;
+
+ public InvalidTargetPatternException(String invalidPattern, TargetParsingException tpe) {
+ super(tpe);
+ this.invalidPattern = invalidPattern;
+ this.tpe = tpe;
+ }
+
+ public String getInvalidPattern() {
+ return invalidPattern;
+ }
+
+ public TargetParsingException getTpe() {
+ return tpe;
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
index 443959b284..5b5a92e979 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
@@ -31,16 +31,13 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.Event;
-import com.google.devtools.build.lib.pkgcache.FilteringPolicy;
import com.google.devtools.build.lib.skyframe.ConstraintValueLookupUtil.InvalidConstraintValueException;
import com.google.devtools.build.lib.skyframe.PlatformLookupUtil.InvalidPlatformException;
import com.google.devtools.build.lib.skyframe.RegisteredToolchainsFunction.InvalidToolchainLabelException;
import com.google.devtools.build.lib.skyframe.ToolchainResolutionFunction.NoToolchainFoundException;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
-import com.google.devtools.build.skyframe.ValueOrException;
import com.google.devtools.build.skyframe.ValueOrException2;
import java.util.ArrayList;
import java.util.List;
@@ -358,48 +355,6 @@ public class ToolchainUtil {
}
@Nullable
- static ImmutableList<Label> expandTargetPatterns(
- Environment env, List<String> targetPatterns, FilteringPolicy filteringPolicy)
- throws InvalidTargetPatternException, InterruptedException {
-
- // First parse the patterns, and throw any errors immediately.
- List<TargetPatternValue.TargetPatternKey> patternKeys = new ArrayList<>();
- for (TargetPatternValue.TargetPatternSkyKeyOrException keyOrException :
- TargetPatternValue.keys(targetPatterns, filteringPolicy, "")) {
-
- try {
- patternKeys.add(keyOrException.getSkyKey());
- } catch (TargetParsingException e) {
- throw new InvalidTargetPatternException(keyOrException.getOriginalPattern(), e);
- }
- }
-
- // Then, resolve the patterns.
- Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns =
- env.getValuesOrThrow(patternKeys, TargetParsingException.class);
- boolean valuesMissing = env.valuesMissing();
- ImmutableList.Builder<Label> labels = valuesMissing ? null : new ImmutableList.Builder<>();
-
- for (TargetPatternValue.TargetPatternKey pattern : patternKeys) {
- TargetPatternValue value;
- try {
- value = (TargetPatternValue) resolvedPatterns.get(pattern).get();
- if (!valuesMissing && value != null) {
- labels.addAll(value.getTargets().getTargets());
- }
- } catch (TargetParsingException e) {
- throw new InvalidTargetPatternException(pattern.getPattern(), e);
- }
- }
-
- if (valuesMissing) {
- return null;
- }
-
- return labels.build();
- }
-
- @Nullable
private static ImmutableList<ConfiguredTargetKey> filterPlatforms(
ImmutableList<ConfiguredTargetKey> platformKeys,
ImmutableList<ConfiguredTargetKey> constraintKeys,
@@ -495,29 +450,6 @@ public class ToolchainUtil {
}
}
- /**
- * Exception used when an error occurs in {@link #expandTargetPatterns(Environment, List,
- * FilteringPolicy)}.
- */
- static final class InvalidTargetPatternException extends ToolchainException {
- private String invalidPattern;
- private TargetParsingException tpe;
-
- public InvalidTargetPatternException(String invalidPattern, TargetParsingException tpe) {
- super(tpe);
- this.invalidPattern = invalidPattern;
- this.tpe = tpe;
- }
-
- public String getInvalidPattern() {
- return invalidPattern;
- }
-
- public TargetParsingException getTpe() {
- return tpe;
- }
- }
-
/** Exception used when a toolchain type is required but no matching toolchain is found. */
public static final class UnresolvedToolchainsException extends ToolchainException {
private final ImmutableList<Label> missingToolchainTypes;