aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/pkgcache
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-06-12 04:56:24 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-12 04:57:48 -0700
commitede315264b2191baf76d4cb76bbcf5db85da2630 (patch)
treefa8c1c7435d3893f014e7c93cbfac9ed815faf49 /src/main/java/com/google/devtools/build/lib/pkgcache
parent6abc7497941dd81c27674d6636090867ea13101f (diff)
Split TargetPatternEvaluator into two interfaces
- the TargetPatternPreloader is still used for query in all its forms - the remaining TargetPatternEvaluator part is no longer used except in tests - also make both implementations stateless and pass the offset to the methods instead; note that they both modify the underlying skyframe graph, so there are side effects to the calls even if there's no direct state anymore The intent is to migrate the relevant tests to LoadingPhaseRunnerTest (which could also now be renamed since it's not doing a loading phase), and then delete the TargetPatternEvaluator interface. This depends on the previous commit that removed the last direct use of TPE from an internal command. PiperOrigin-RevId: 200198067
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/pkgcache')
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/PackageManager.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluator.java45
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternPreloader.java46
3 files changed, 48 insertions, 45 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/PackageManager.java b/src/main/java/com/google/devtools/build/lib/pkgcache/PackageManager.java
index 0bbfae7ced..13f38cd1e5 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/PackageManager.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/PackageManager.java
@@ -59,7 +59,7 @@ public interface PackageManager extends PackageProvider, CachingPackageLocator {
/**
* Retrieve a target pattern parser that works with this package manager.
*/
- TargetPatternEvaluator newTargetPatternEvaluator();
+ TargetPatternPreloader newTargetPatternPreloader();
/**
* Construct a new {@link TransitivePackageLoader}.
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluator.java b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluator.java
index a9e69bd5b4..ea2651d6ab 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluator.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluator.java
@@ -14,17 +14,13 @@
package com.google.devtools.build.lib.pkgcache;
-import com.google.common.annotations.VisibleForTesting;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.concurrent.ThreadSafety;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadHostile;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.Collection;
import java.util.List;
-import java.util.Map;
/**
* A parser for target patterns. Target patterns are a generalisation of
@@ -50,49 +46,10 @@ public interface TargetPatternEvaluator {
* computed. Implements the specification described in the class-level comment.
*/
ResolvedTargets<Target> parseTargetPatternList(
+ PathFragment relativeWorkingDirectory,
ExtendedEventHandler eventHandler,
List<String> targetPatterns,
FilteringPolicy policy,
boolean keepGoing)
throws TargetParsingException, InterruptedException;
-
- /**
- * Attempts to parse a single target pattern while consulting the package cache to check for the
- * existence of packages and directories and the build targets in them. Implements the
- * specification described in the class-level comment. Returns a {@link ResolvedTargets} object.
- *
- * <p>If an error is encountered, a {@link TargetParsingException} is thrown, unless {@code
- * keepGoing} is set to true. In that case, the returned object will have its error bit set.
- */
- ResolvedTargets<Target> parseTargetPattern(
- ExtendedEventHandler eventHandler, String pattern, boolean keepGoing)
- throws TargetParsingException, InterruptedException;
-
- /**
- * Attempts to parse and load the given collection of patterns; the returned map contains the
- * results for each pattern successfully parsed.
- *
- * <p>If an error is encountered, a {@link TargetParsingException} is thrown, unless {@code
- * keepGoing} is set to true. In that case, the patterns that failed to load have the error flag
- * set.
- */
- Map<String, ResolvedTargets<Target>> preloadTargetPatterns(
- ExtendedEventHandler eventHandler, Collection<String> patterns, boolean keepGoing)
- throws TargetParsingException, InterruptedException;
-
- /**
- * Update the parser's offset, given the workspace and working directory.
- *
- * @param relativeWorkingDirectory the working directory relative to the workspace
- */
- @ThreadHostile
- void updateOffset(PathFragment relativeWorkingDirectory);
-
- /**
- * @return the offset of this parser from the root of the workspace.
- * Non-absolute package-names will be resolved relative
- * to this offset.
- */
- @VisibleForTesting
- String getOffset();
}
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternPreloader.java b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternPreloader.java
new file mode 100644
index 0000000000..3b89098be2
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternPreloader.java
@@ -0,0 +1,46 @@
+// 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.pkgcache;
+
+import com.google.devtools.build.lib.cmdline.ResolvedTargets;
+import com.google.devtools.build.lib.cmdline.TargetParsingException;
+import com.google.devtools.build.lib.concurrent.ThreadSafety;
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import com.google.devtools.build.lib.packages.Target;
+import com.google.devtools.build.lib.vfs.PathFragment;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * A preloader for target patterns. See {@link TargetPatternEvaluator} for more details.
+ */
+@ThreadSafety.ThreadSafe
+public interface TargetPatternPreloader {
+ /**
+ * Attempts to parse and load the given collection of patterns; the returned map contains the
+ * results for each pattern successfully parsed. As a side effect, calling this method populates
+ * the Skyframe graph, so subsequent calls are faster.
+ *
+ * <p>If an error is encountered, a {@link TargetParsingException} is thrown, unless {@code
+ * keepGoing} is set to true. In that case, the patterns that failed to load have the error flag
+ * set.
+ */
+ Map<String, ResolvedTargets<Target>> preloadTargetPatterns(
+ ExtendedEventHandler eventHandler,
+ PathFragment relativeWorkingDirectory,
+ Collection<String> patterns,
+ boolean keepGoing)
+ throws TargetParsingException, InterruptedException;
+}