aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/pkgcache
diff options
context:
space:
mode:
authorGravatar juliexxia <juliexxia@google.com>2018-05-03 11:09:52 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-03 11:11:18 -0700
commit42025b2dfb8319d90b4a5566ab583084cfcb2de8 (patch)
treec00da6578342684654174a39f1fe8cd381da8832 /src/main/java/com/google/devtools/build/lib/pkgcache
parent07bd86df11d00a56466fa9bf3f1220d2429cfab7 (diff)
Consolidate fields and methods of recursive package providers into an abstract class. This is also helpful for the new recursive package provider I'll be adding to support recursive patterns in cquery.
PiperOrigin-RevId: 195279920
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/pkgcache')
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/AbstractRecursivePackageProvider.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/AbstractRecursivePackageProvider.java b/src/main/java/com/google/devtools/build/lib/pkgcache/AbstractRecursivePackageProvider.java
new file mode 100644
index 0000000000..4252f1d44c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/AbstractRecursivePackageProvider.java
@@ -0,0 +1,61 @@
+// 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.Label;
+import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import com.google.devtools.build.lib.packages.NoSuchPackageException;
+import com.google.devtools.build.lib.packages.NoSuchTargetException;
+import com.google.devtools.build.lib.packages.Target;
+import com.google.devtools.build.lib.vfs.Path;
+
+/** Partial implementation of RecursivePackageProvider to provide some common methods. */
+public abstract class AbstractRecursivePackageProvider implements RecursivePackageProvider {
+
+ private final PathPackageLocator pkgPath;
+
+ protected AbstractRecursivePackageProvider(PathPackageLocator pkgPath) {
+ this.pkgPath = pkgPath;
+ }
+
+ @Override
+ public Path getBuildFileForPackage(PackageIdentifier packageName) {
+ try {
+ return pkgPath.getPackageBuildFile(packageName);
+ } catch (NoSuchPackageException e) {
+ return null;
+ }
+ }
+
+ public PathPackageLocator getPkgPath() {
+ return pkgPath;
+ }
+
+
+ @Override
+ public Target getTarget(ExtendedEventHandler eventHandler, Label label)
+ throws NoSuchPackageException, NoSuchTargetException, InterruptedException {
+ return getPackage(eventHandler, label.getPackageIdentifier()).getTarget(label.getName());
+ }
+
+ /**
+ * Indicates that a missing dependency is needed before target parsing can proceed. Currently
+ * used only in skyframe to notify the framework of missing dependencies. Caught by the compute
+ * method in {@link com.google.devtools.build.lib.skyframe.TargetPatternFunction}, which then
+ * returns null in accordance with the skyframe missing dependency policy.
+ */
+ public static class MissingDepException extends RuntimeException {
+ }
+}