aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2016-02-05 22:09:09 +0000
committerGravatar David Chen <dzc@google.com>2016-02-07 11:33:18 +0000
commitbc8b5e09ff667c7d0bf7186a7a207629e6d7bad5 (patch)
treeaa1b70b0471bcdcc6d26c27d0e579971bf0de414 /src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
parent26152a6fc8db13f82553770b675e1a355a8e17ae (diff)
Add an intermediate SkyFunction for resolving the external package
The WORKSPACE file parsing needs to be separated into several parts to enable load of labels in the WORKSPACE file. This change adds an intermediate SkyFunction, ExternalPackageFunction, that requires all the WORKSPACE file part to be parsed to resolve //external: labels. Issue #824 Step 1. -- MOS_MIGRATED_REVID=113984026
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
new file mode 100644
index 0000000000..877d7c5e33
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileValue.java
@@ -0,0 +1,152 @@
+// Copyright 2016 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.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException;
+import com.google.devtools.build.lib.packages.Package;
+import com.google.devtools.build.lib.util.Preconditions;
+import com.google.devtools.build.lib.vfs.RootedPath;
+import com.google.devtools.build.skyframe.SkyKey;
+import com.google.devtools.build.skyframe.SkyValue;
+
+import java.util.Objects;
+
+/**
+ * A SkyValue that contains the result of the parsing of one part of the WORKSPACE file. The parsing
+ * of the WORKSPACE file is split before each series of load statement because we need to resolve
+ * repositories before being able to load from those repositories.
+ */
+public class WorkspaceFileValue implements SkyValue {
+
+ /**
+ * Argument for the SkyKey to request a WorkspaceFileValue.
+ */
+ @Immutable
+ public static class WorkspaceFileKey {
+ private final RootedPath path;
+ private final int idx;
+
+ /**
+ * Creates a Key for the WorkspaceFileFunction. The path to the workspace file is specified
+ * by {@code path}. This key will ask WorkspaceFileFunction to get the {@code idx+1}-th part of
+ * the workspace file (so idx = 0 represents the first part, idx = 1, the second part, etc...).
+ */
+ public WorkspaceFileKey(RootedPath path, int idx) {
+ this.path = path;
+ this.idx = idx;
+ }
+
+ public RootedPath getPath() {
+ return path;
+ }
+
+ public int getIndex() {
+ return idx;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof WorkspaceFileKey)) {
+ return false;
+ }
+ WorkspaceFileKey other = (WorkspaceFileKey) obj;
+ return Objects.equals(path, other.path) && idx == other.idx;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(path.hashCode(), idx);
+ }
+
+ @Override
+ public String toString() {
+ return path + ", " + idx;
+ }
+ }
+
+ private final Package pkg;
+ private final int idx;
+ private final RootedPath path;
+ private final boolean hasNext;
+
+ public WorkspaceFileValue(Package pkg, RootedPath path, int idx, boolean hasNext) {
+ this.pkg = Preconditions.checkNotNull(pkg);
+ this.idx = idx;
+ this.path = path;
+ this.hasNext = hasNext;
+ }
+
+ /**
+ * Returns the package. This package may contain errors, in which case the caller should throw
+ * a {@link BuildFileContainsErrorsException}.
+ */
+ public Package getPackage() {
+ return pkg;
+ }
+
+ @Override
+ public String toString() {
+ return "<WorkspaceFileValue idx=" + idx + ">";
+ }
+
+ private static SkyKey key(RootedPath path, int idx) {
+ return new SkyKey(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileKey(path, idx));
+ }
+
+ public static SkyKey key(RootedPath path) {
+ return key(path, 0);
+ }
+
+ /**
+ * Get the key for the next WorkspaceFileValue or null if this value is the last part of the
+ * workspace file.
+ */
+ public SkyKey next() {
+ if (hasNext) {
+ return key(path, idx + 1);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * The workspace file parsing is cut in several parts and this function returns the index of the
+ * part of the workspace file that this value holds. For the first part, this index will be 0, for
+ * the second part, it will be 1 and so on.
+ */
+ public int getIndex() {
+ return idx;
+ }
+
+ /**
+ * The workspace file parsing is cut in several parts and this function returns true if there is
+ * a part following the part holds by this value (or false if this is the last part of the
+ * WORKSPACE file.
+ *
+ * <p>This method is public for serialization of the WorkspaceFileValue, #next() should be used
+ * to iterate instead of this method.
+ */
+ public boolean hasNext() {
+ return hasNext;
+ }
+
+ public RootedPath getPath() {
+ return path;
+ }
+}