From 678f5a0299d2ea5cdd25740f58571bd43f27e1e2 Mon Sep 17 00:00:00 2001 From: janakr Date: Tue, 27 Feb 2018 12:55:05 -0800 Subject: @AutoCodec WriteBuildInfoHeaderAction. PiperOrigin-RevId: 187218309 --- .../lib/rules/cpp/WriteBuildInfoHeaderAction.java | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java index 03a3594086..e75153a1b5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java @@ -17,7 +17,6 @@ package com.google.devtools.build.lib.rules.cpp; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionKeyContext; @@ -26,6 +25,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.WorkspaceStatusAction; import com.google.devtools.build.lib.analysis.actions.AbstractFileWriteAction; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.util.Fingerprint; import java.io.IOException; import java.io.OutputStream; @@ -36,45 +36,47 @@ import java.util.LinkedHashMap; import java.util.Map; /** - * An action that creates a C++ header containing the build information in the - * form of #define directives. + * An action that creates a C++ header containing the build information in the form of #define + * directives. */ @Immutable +@AutoCodec public final class WriteBuildInfoHeaderAction extends AbstractFileWriteAction { private static final String GUID = "62be38ad-1243-46b9-9948-9bdfa81f8918"; - private final ImmutableList valueArtifacts; - private final boolean writeVolatileInfo; private final boolean writeStableInfo; /** * Creates an action that writes a C++ header with the build information. * - *

It reads the set of build info keys from an action context that is usually contributed - * to Bazel by the workspace status module, and the value associated with said keys from the + *

It reads the set of build info keys from an action context that is usually contributed to + * Bazel by the workspace status module, and the value associated with said keys from the * workspace status files (stable and volatile) written by the workspace status action. * *

Without input artifacts this action uses redacted build information. - * @param inputs Artifacts that contain build information, or an empty - * collection to use redacted build information - * @param output the C++ header Artifact created by this action - * @param writeVolatileInfo whether to write the volatile part of the build - * information to the generated header - * @param writeStableInfo whether to write the non-volatile part of the - * build information to the generated header + * + * @param inputs Artifacts that contain build information, or an empty collection to use redacted + * build information + * @param primaryOutput the C++ header Artifact created by this action + * @param writeVolatileInfo whether to write the volatile part of the build information to the + * generated header + * @param writeStableInfo whether to write the non-volatile part of the build information to the + * generated header */ - public WriteBuildInfoHeaderAction(Collection inputs, - Artifact output, boolean writeVolatileInfo, boolean writeStableInfo) { - super(ActionOwner.SYSTEM_ACTION_OWNER, inputs, output, /*makeExecutable=*/ false); - valueArtifacts = ImmutableList.copyOf(inputs); + public WriteBuildInfoHeaderAction( + Collection inputs, + Artifact primaryOutput, + boolean writeVolatileInfo, + boolean writeStableInfo) { + super(ActionOwner.SYSTEM_ACTION_OWNER, inputs, primaryOutput, /*makeExecutable=*/ false); if (!inputs.isEmpty()) { // With non-empty inputs we should not generate both volatile and non-volatile data // in the same header file. Preconditions.checkState(writeVolatileInfo ^ writeStableInfo); } Preconditions.checkState( - output.isConstantMetadata() == (writeVolatileInfo && !inputs.isEmpty())); + primaryOutput.isConstantMetadata() == (writeVolatileInfo && !inputs.isEmpty())); this.writeVolatileInfo = writeVolatileInfo; this.writeStableInfo = writeStableInfo; @@ -95,11 +97,11 @@ public final class WriteBuildInfoHeaderAction extends AbstractFileWriteAction { } final Map values = new LinkedHashMap<>(); - for (Artifact valueFile : valueArtifacts) { + for (Artifact valueFile : getInputs()) { values.putAll(WorkspaceStatusAction.parseValues(valueFile.getPath())); } - final boolean redacted = valueArtifacts.isEmpty(); + final boolean redacted = Iterables.isEmpty(getInputs()); return new DeterministicWriter() { @Override -- cgit v1.2.3