aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java
diff options
context:
space:
mode:
authorGravatar Mark Schaller <mschaller@google.com>2015-05-19 20:27:43 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-05-21 09:46:11 +0000
commitf6e32d64fdf3bf2710ed8f32f64d4113064e3200 (patch)
tree7dc91f1046953c3f4f902dc477c2503904440124 /src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java
parent111634a5f7b4ba71c84b660a33af8325284b77d8 (diff)
Teach skyframe about excluded directories, paths
RecursivePkgFunction now expects both a rooted path to load packages beneath and a set of paths to exclude. This also augments existing machinery to deliver this set of paths to exclude. This leads toward more efficient processing of target patterns in target pattern sequence evaluation. -- MOS_MIGRATED_REVID=94020331
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java
index 4013b9024f..56ed0e504a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java
@@ -13,13 +13,19 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
+import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
+import java.io.Serializable;
+import java.util.Objects;
+
/**
* This value represents the result of looking up all the packages under a given package path root,
* starting at a given directory.
@@ -38,11 +44,64 @@ public class RecursivePkgValue implements SkyValue {
* Create a transitive package lookup request.
*/
@ThreadSafe
- public static SkyKey key(RootedPath rootedPath) {
- return new SkyKey(SkyFunctions.RECURSIVE_PKG, rootedPath);
+ public static SkyKey key(RootedPath rootedPath, ImmutableSet<PathFragment> excludedPaths) {
+ return new SkyKey(SkyFunctions.RECURSIVE_PKG, new RecursivePkgKey(rootedPath, excludedPaths));
}
public NestedSet<String> getPackages() {
return packages;
}
+
+ /**
+ * A RecursivePkgKey is a tuple of a {@link RootedPath}, {@code rootedPath}, defining the
+ * directory to recurse beneath in search of packages, and an {@link ImmutableSet} of {@link
+ * PathFragment}s, {@code excludedPaths}, relative to {@code rootedPath.getRoot}, defining the
+ * set of subdirectories beneath {@code rootedPath} to skip.
+ *
+ * <p>Throws {@link IllegalArgumentException} if {@code excludedPaths} contains any paths that
+ * are not beneath {@code rootedPath}.
+ */
+ @ThreadSafe
+ public static final class RecursivePkgKey implements Serializable {
+ private final RootedPath rootedPath;
+ private final ImmutableSet<PathFragment> excludedPaths;
+
+ private RecursivePkgKey(RootedPath rootedPath, ImmutableSet<PathFragment> excludedPaths) {
+ this.rootedPath = Preconditions.checkNotNull(rootedPath);
+ this.excludedPaths = Preconditions.checkNotNull(excludedPaths);
+
+ PathFragment rootedPathFragment = rootedPath.getRelativePath();
+ for (PathFragment excludedPath : excludedPaths) {
+ Preconditions.checkArgument(!excludedPath.equals(rootedPathFragment)
+ && excludedPath.startsWith(rootedPathFragment), "%s is not beneath %s", excludedPath,
+ rootedPathFragment);
+ }
+ }
+
+ public RootedPath getRootedPath() {
+ return rootedPath;
+ }
+
+ public ImmutableSet<PathFragment> getExcludedPaths() {
+ return excludedPaths;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof RecursivePkgKey)) {
+ return false;
+ }
+
+ RecursivePkgKey that = (RecursivePkgKey) o;
+ return excludedPaths.equals(that.excludedPaths) && rootedPath.equals(that.rootedPath);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(rootedPath, excludedPaths);
+ }
+ }
}