aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2017-10-07 00:46:20 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-10-07 11:07:30 +0200
commit4050a89a1e3fb6a9a9c6bd080cf4e3081a9f2012 (patch)
tree0df531d72015ad33f3a6c8ff670846808714e8bd /src/main/java/com/google/devtools/build/lib/rules/cpp
parent5f39475bb51f48182180e34e4310edb650bea462 (diff)
More SpawnResult-related plumbing changes to Actions, Strategies, ActionContexts, etc., so that SpawnResult metadata is returned upwards.
Note that the TODOs mostly refer to changes that will appear in a subsequent CL (a CL to return SpawnResults, contained in ActionResults, from Actions/AbstractActions). I split off the remaining SpawnResult-related changes into this CL and kept the ActionResult-related changes separate. RELNOTES: None. PiperOrigin-RevId: 171355611
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionContext.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionResult.java68
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/SpawnGccStrategy.java13
6 files changed, 91 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index 8c09e6c8cb..1ac5cf2ecc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -1164,8 +1164,12 @@ public class CppCompileAction extends AbstractAction
actionExecutionContext.getFileOutErr().setErrorFilter(showIncludesFilterForStderr);
}
try {
- reply = actionExecutionContext.getContext(actionContext)
- .execWithReply(this, actionExecutionContext);
+ CppCompileActionResult cppCompileActionResult =
+ actionExecutionContext
+ .getContext(actionContext)
+ .execWithReply(this, actionExecutionContext);
+ // TODO(b/62588075) Save spawnResults from cppCompileActionResult and return them upwards.
+ reply = cppCompileActionResult.contextReply();
} catch (ExecException e) {
throw e.toActionExecutionException(
"C++ compilation of rule '" + getOwner().getLabel() + "'",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionContext.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionContext.java
index 1f2e5369b8..5e890d6dcd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionContext.java
@@ -51,7 +51,10 @@ public interface CppCompileActionContext extends ActionContext {
/**
* Executes the given action and return the reply of the executor.
+ *
+ * @return a CppCompileActionResult with information resulting from the action's execution
*/
- Reply execWithReply(CppCompileAction action,
- ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException;
+ CppCompileActionResult execWithReply(
+ CppCompileAction action, ActionExecutionContext actionExecutionContext)
+ throws ExecException, InterruptedException;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionResult.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionResult.java
new file mode 100644
index 0000000000..93e3ae4ef8
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionResult.java
@@ -0,0 +1,68 @@
+// Copyright 2017 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.rules.cpp;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.actions.SpawnResult;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+/** Contains information about the result of a CppCompileAction's execution. */
+@AutoValue
+public abstract class CppCompileActionResult {
+
+ /** Returns the SpawnResults created by the action, if any. */
+ public abstract Set<SpawnResult> spawnResults();
+
+ /**
+ * Gets the optional CppCompileActionContext.Reply for the action.
+ *
+ * <p>Could be null if there is no reply (e.g. if there is no .d file documenting which #include
+ * statements are actually required.)
+ */
+ @Nullable
+ public abstract CppCompileActionContext.Reply contextReply();
+
+ /** Returns a builder that can be used to construct a {@link CppCompileActionResult} object. */
+ public static Builder builder() {
+ return new AutoValue_CppCompileActionResult.Builder();
+ }
+
+ /** Builder for a {@link CppCompileActionResult} instance, which is immutable once built. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+
+ /** Returns the SpawnResults for the action, if any. */
+ abstract Set<SpawnResult> spawnResults();
+
+ /** Sets the SpawnResults for the action. */
+ public abstract Builder setSpawnResults(Set<SpawnResult> spawnResults);
+
+ /** Sets the CppCompileActionContext.Reply for the action. */
+ public abstract Builder setContextReply(CppCompileActionContext.Reply reply);
+
+ abstract CppCompileActionResult realBuild();
+
+ /**
+ * Returns an immutable CppCompileActionResult object.
+ *
+ * <p>The set of SpawnResults is also made immutable here.
+ */
+ public CppCompileActionResult build() {
+ return this.setSpawnResults(ImmutableSet.copyOf(spawnResults())).realBuild();
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java
index 1daec4300b..dc36e72f69 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java
@@ -129,7 +129,10 @@ public class FakeCppCompileAction extends CppCompileAction {
CppCompileActionContext context = actionExecutionContext.getContext(actionContext);
CppCompileActionContext.Reply reply = null;
try {
- reply = context.execWithReply(this, actionExecutionContext);
+ CppCompileActionResult cppCompileActionResult =
+ context.execWithReply(this, actionExecutionContext);
+ // TODO(b/62588075) Save spawnResults from cppCompileActionResult and return them upwards.
+ reply = cppCompileActionResult.contextReply();
} catch (ExecException e) {
throw e.toActionExecutionException(
"C++ compilation of rule '" + getOwner().getLabel() + "'",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java
index b53d38bbfd..2192c3f8cb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java
@@ -161,12 +161,6 @@ public final class LtoBackendAction extends SpawnAction {
}
@Override
- public void execute(ActionExecutionContext actionExecutionContext)
- throws ActionExecutionException, InterruptedException {
- super.execute(actionExecutionContext);
- }
-
- @Override
protected String computeKey() {
Fingerprint f = new Fingerprint();
f.addString(GUID);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/SpawnGccStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/SpawnGccStrategy.java
index f24be92101..a5a82f1b13 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/SpawnGccStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/SpawnGccStrategy.java
@@ -25,7 +25,9 @@ import com.google.devtools.build.lib.actions.ExecutionStrategy;
import com.google.devtools.build.lib.actions.SimpleSpawn;
import com.google.devtools.build.lib.actions.Spawn;
import com.google.devtools.build.lib.actions.SpawnActionContext;
+import com.google.devtools.build.lib.actions.SpawnResult;
import com.google.devtools.build.lib.actions.UserExecException;
+import java.util.Set;
/**
* A context for C++ compilation that calls into a {@link SpawnActionContext}.
@@ -45,7 +47,7 @@ public class SpawnGccStrategy implements CppCompileActionContext {
}
@Override
- public CppCompileActionContext.Reply execWithReply(
+ public CppCompileActionResult execWithReply(
CppCompileAction action, ActionExecutionContext actionExecutionContext)
throws ExecException, InterruptedException {
if (action.getDotdFile() != null && action.getDotdFile().artifact() == null) {
@@ -65,9 +67,10 @@ public class SpawnGccStrategy implements CppCompileActionContext {
action.getOutputs().asList(),
action.estimateResourceConsumptionLocal());
- actionExecutionContext
- .getSpawnActionContext(action.getMnemonic())
- .exec(spawn, actionExecutionContext);
- return null;
+ Set<SpawnResult> spawnResults =
+ actionExecutionContext
+ .getSpawnActionContext(action.getMnemonic())
+ .exec(spawn, actionExecutionContext);
+ return CppCompileActionResult.builder().setSpawnResults(spawnResults).build();
}
}