Automated rollback of commit 774fdb4be128b642332531f1d0376810b4c5377f.
PiperOrigin-RevId: 576897399
Change-Id: I3bef1732930bbd6acc2d3aa6f24b880e9d20438a
diff --git a/src/main/java/com/google/devtools/build/lib/actions/BUILD b/src/main/java/com/google/devtools/build/lib/actions/BUILD
index f458831..61448de 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/actions/BUILD
@@ -109,6 +109,7 @@
"MapBasedActionGraph.java",
"MiddlemanAction.java",
"MiddlemanFactory.java",
+ "MissingDepExecException.java",
"MissingInputFileException.java",
"MutableActionGraph.java",
"NotifyOnActionCacheHit.java",
diff --git a/src/main/java/com/google/devtools/build/lib/actions/InputMetadataProvider.java b/src/main/java/com/google/devtools/build/lib/actions/InputMetadataProvider.java
index 68b88ea..82b325a 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/InputMetadataProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/InputMetadataProvider.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.actions;
+import com.google.devtools.build.lib.actions.Artifact.DerivedArtifact;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.vfs.FileSystem;
import java.io.IOException;
@@ -27,6 +28,11 @@
* <p>The returned {@link FileArtifactValue} instance corresponds to the final target of a symlink
* and therefore must not have a type of {@link FileStateType#SYMLINK}.
*
+ * <p>If {@link #mayGetGeneratingActionsFromSkyframe} is {@code true} and the {@linkplain
+ * DerivedArtifact#getGeneratingActionKey generating action} is not immediately available, this
+ * method returns {@code null} to signify that a skyframe restart is necessary to obtain the
+ * metadata for the requested {@link Artifact.DerivedArtifact}.
+ *
* @param input the input to retrieve the digest for
* @return the artifact's digest or null if digest cannot be obtained (due to artifact
* non-existence, lookup errors, or any other reason)
@@ -52,4 +58,12 @@
default FileSystem getFileSystemForInputResolution() {
return null;
}
+
+ /**
+ * Indicates whether calls to {@link #getInputMetadata} with a {@link Artifact.DerivedArtifact}
+ * may require a skyframe lookup.
+ */
+ default boolean mayGetGeneratingActionsFromSkyframe() {
+ return false;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/MissingDepExecException.java b/src/main/java/com/google/devtools/build/lib/actions/MissingDepExecException.java
new file mode 100644
index 0000000..806cde4
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/actions/MissingDepExecException.java
@@ -0,0 +1,35 @@
+// 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.actions;
+
+import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
+
+/**
+ * Exception to be thrown if an action failed to execute because it is missing Skyframe
+ * dependencies.
+ *
+ * <p>This is expected to be possible when {@link
+ * InputMetadataProvider#mayGetGeneratingActionsFromSkyframe} is {@code true}.
+ */
+public final class MissingDepExecException extends ExecException {
+
+ public MissingDepExecException() {
+ super("Missing skyframe dependency");
+ }
+
+ @Override
+ protected FailureDetail getFailureDetail(String message) {
+ throw new UnsupportedOperationException("MissingDepException should be handled");
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/LegacyIncludeScanner.java b/src/main/java/com/google/devtools/build/lib/includescanning/LegacyIncludeScanner.java
index bcd97d2..444baef 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/LegacyIncludeScanner.java
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/LegacyIncludeScanner.java
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.actions.ArtifactFactory;
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.ExecException;
+import com.google.devtools.build.lib.actions.MissingDepExecException;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.AbstractQueueVisitor;
import com.google.devtools.build.lib.concurrent.ErrorClassifier;
@@ -607,7 +608,15 @@
grepIncludes,
includeScanningHeaderData);
- visitor.processInternal(mainSource, sources, cmdlineIncludes, includes, pathHints);
+ try {
+ visitor.processInternal(mainSource, sources, cmdlineIncludes, includes, pathHints);
+ } catch (MissingDepExecException e) {
+ // This happens when a skyframe restart is necessary. Callers are responsible for checking
+ // env.valuesMissing() as per this method's contract, so we can just ignore the exception.
+ if (!env.valuesMissing()) {
+ throw new IllegalStateException("Missing dep without skyframe request", e);
+ }
+ }
}
private static void checkForInterrupt(String operation, Object source)