aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/buildeventstream
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-05-18 12:46:54 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-18 12:48:25 -0700
commitfbf2756c649649bc821595c562721ebf1af10361 (patch)
treef1251754c292c922f421a9368c01841232d322ad /src/main/java/com/google/devtools/build/lib/buildeventstream
parentbeaaf669b6f3651445da222cf43b6c33546c0fb7 (diff)
Add BuildEventProtocolOptions; use to enable/disable important_outputs
The important_outputs field is deprecated, and this adds a flag to disable its generation entirely. PiperOrigin-RevId: 197186530
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/buildeventstream')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventContext.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventProtocolOptions.java34
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransport.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactory.java33
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/FileTransport.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransport.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransport.java13
8 files changed, 105 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BUILD b/src/main/java/com/google/devtools/build/lib/buildeventstream/BUILD
index 4817398ebb..0891970004 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BUILD
@@ -18,6 +18,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/vfs",
+ "//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventContext.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventContext.java
index 72422bde41..62aa48bc25 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventContext.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventContext.java
@@ -31,4 +31,9 @@ public interface BuildEventContext {
* com.google.devtools.build.lib.actions.EventReportingArtifacts} interface.
*/
ArtifactGroupNamer artifactGroupNamer();
+
+ /**
+ * Returns the options for the build event stream.
+ */
+ BuildEventProtocolOptions getOptions();
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventProtocolOptions.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventProtocolOptions.java
new file mode 100644
index 0000000000..e22d1669ef
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventProtocolOptions.java
@@ -0,0 +1,34 @@
+// 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.buildeventstream;
+
+import com.google.devtools.common.options.Option;
+import com.google.devtools.common.options.OptionDocumentationCategory;
+import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.OptionsBase;
+
+/** Options used to configure the build event protocol. */
+public class BuildEventProtocolOptions extends OptionsBase {
+
+ @Option(
+ name = "legacy_important_outputs",
+ defaultValue = "true",
+ documentationCategory = OptionDocumentationCategory.LOGGING,
+ effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
+ help = "Use this to suppress generation of the legacy important_outputs field in the "
+ + "TargetComplete event"
+ )
+ public boolean legacyImportantOutputs;
+}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransport.java
index 025fee5809..71e4fd878a 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransport.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransport.java
@@ -19,19 +19,24 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer;
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
+import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
+import java.io.IOException;
/**
* A simple {@link BuildEventTransport} that writes a varint delimited binary representation of
* {@link BuildEvent} protocol buffers to a file.
*/
public final class BinaryFormatFileTransport extends FileTransport {
-
+ private final BuildEventProtocolOptions options;
private final PathConverter pathConverter;
- BinaryFormatFileTransport(String path, PathConverter pathConverter) {
+ BinaryFormatFileTransport(
+ String path, BuildEventProtocolOptions options, PathConverter pathConverter)
+ throws IOException {
super(path);
+ this.options = options;
this.pathConverter = pathConverter;
}
@@ -49,10 +54,16 @@ public final class BinaryFormatFileTransport extends FileTransport {
public PathConverter pathConverter() {
return pathConverter;
}
+
@Override
public ArtifactGroupNamer artifactGroupNamer() {
return namer;
}
+
+ @Override
+ public BuildEventProtocolOptions getOptions() {
+ return options;
+ }
};
write(event.asStreamProto(converters));
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactory.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactory.java
index cf6d0c936c..0cc84b0f74 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactory.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.buildeventstream.transports;
import static com.google.common.base.Strings.isNullOrEmpty;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.devtools.build.lib.vfs.Path;
@@ -33,10 +34,13 @@ public enum BuildEventTransportFactory {
}
@Override
- protected BuildEventTransport create(BuildEventStreamOptions options,
+ protected BuildEventTransport create(
+ BuildEventStreamOptions options,
+ BuildEventProtocolOptions protocolOptions,
PathConverter pathConverter) throws IOException {
return new TextFormatFileTransport(
options.getBuildEventTextFile(),
+ protocolOptions,
options.getBuildEventTextFilePathConversion() ? pathConverter : new NullPathConverter());
}
},
@@ -48,10 +52,13 @@ public enum BuildEventTransportFactory {
}
@Override
- protected BuildEventTransport create(BuildEventStreamOptions options,
+ protected BuildEventTransport create(
+ BuildEventStreamOptions options,
+ BuildEventProtocolOptions protocolOptions,
PathConverter pathConverter) throws IOException {
return new BinaryFormatFileTransport(
options.getBuildEventBinaryFile(),
+ protocolOptions,
options.getBuildEventBinaryFilePathConversion()
? pathConverter
: new NullPathConverter());
@@ -66,9 +73,12 @@ public enum BuildEventTransportFactory {
@Override
protected BuildEventTransport create(
- BuildEventStreamOptions options, PathConverter pathConverter) throws IOException {
+ BuildEventStreamOptions options,
+ BuildEventProtocolOptions protocolOptions,
+ PathConverter pathConverter) throws IOException {
return new JsonFormatFileTransport(
options.getBuildEventJsonFile(),
+ protocolOptions,
options.getBuildEventJsonFilePathConversion() ? pathConverter : new NullPathConverter());
}
};
@@ -81,12 +91,16 @@ public enum BuildEventTransportFactory {
* @return A {@link ImmutableSet} of BuildEventTransports. This set may be empty.
* @throws IOException Exception propagated from a {@link BuildEventTransport} creation failure.
*/
- public static ImmutableSet<BuildEventTransport> createFromOptions(BuildEventStreamOptions options,
- PathConverter pathConverter) throws IOException {
+ public static ImmutableSet<BuildEventTransport> createFromOptions(
+ BuildEventStreamOptions options,
+ BuildEventProtocolOptions protocolOptions,
+ PathConverter pathConverter)
+ throws IOException {
ImmutableSet.Builder<BuildEventTransport> buildEventTransportsBuilder = ImmutableSet.builder();
for (BuildEventTransportFactory transportFactory : BuildEventTransportFactory.values()) {
if (transportFactory.enabled(options)) {
- buildEventTransportsBuilder.add(transportFactory.create(options, pathConverter));
+ buildEventTransportsBuilder.add(
+ transportFactory.create(options, protocolOptions, pathConverter));
}
}
return buildEventTransportsBuilder.build();
@@ -96,8 +110,11 @@ public enum BuildEventTransportFactory {
protected abstract boolean enabled(BuildEventStreamOptions options);
/** Creates a BuildEventTransport from the specified options. */
- protected abstract BuildEventTransport create(BuildEventStreamOptions options,
- PathConverter pathConverter) throws IOException;
+ protected abstract BuildEventTransport create(
+ BuildEventStreamOptions options,
+ BuildEventProtocolOptions protocolOptions,
+ PathConverter pathConverter)
+ throws IOException;
private static class NullPathConverter implements PathConverter {
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/FileTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/FileTransport.java
index 6a59e96c12..a2d1164bb2 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/FileTransport.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/FileTransport.java
@@ -29,20 +29,17 @@ import java.util.logging.Logger;
* Non-blocking file transport.
*
* <p>Implementors of this class need to implement {@code #sendBuildEvent(BuildEvent)} which
- * serializes the build event and writes it to file using {@link #writeData(byte[])}.
+ * serializes the build event and writes it to file using {@link
+ * AsynchronousFileOutputStream#write}.
*/
abstract class FileTransport implements BuildEventTransport {
-
private static final Logger logger = Logger.getLogger(FileTransport.class.getName());
+
@VisibleForTesting
final AsynchronousFileOutputStream out;
- FileTransport(String path) {
- try {
- out = new AsynchronousFileOutputStream(path);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ FileTransport(String path) throws IOException {
+ out = new AsynchronousFileOutputStream(path);
}
// Silent wrappers to AsynchronousFileOutputStream methods.
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransport.java
index 1f9f41e077..3d51c4f632 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransport.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransport.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.buildeventstream.transports;
import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer;
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
+import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.protobuf.InvalidProtocolBufferException;
@@ -28,11 +29,14 @@ import java.io.IOException;
* representation of the events to a file.
*/
public final class JsonFormatFileTransport extends FileTransport {
-
+ private final BuildEventProtocolOptions options;
private final PathConverter pathConverter;
- JsonFormatFileTransport(String path, PathConverter pathConverter) throws IOException {
+ JsonFormatFileTransport(
+ String path, BuildEventProtocolOptions options, PathConverter pathConverter)
+ throws IOException {
super(path);
+ this.options = options;
this.pathConverter = pathConverter;
}
@@ -54,6 +58,11 @@ public final class JsonFormatFileTransport extends FileTransport {
public ArtifactGroupNamer artifactGroupNamer() {
return namer;
}
+
+ @Override
+ public BuildEventProtocolOptions getOptions() {
+ return options;
+ }
};
String protoJsonRepresentation;
try {
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransport.java
index 24b23c457b..2735712bfb 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransport.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransport.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.buildeventstream.transports;
import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer;
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
+import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.protobuf.TextFormat;
@@ -29,11 +30,14 @@ import java.io.IOException;
* <p>This class is used for debugging.
*/
public final class TextFormatFileTransport extends FileTransport {
-
+ private final BuildEventProtocolOptions options;
private final PathConverter pathConverter;
- TextFormatFileTransport(String path, PathConverter pathConverter) throws IOException {
+ TextFormatFileTransport(
+ String path, BuildEventProtocolOptions options, PathConverter pathConverter)
+ throws IOException {
super(path);
+ this.options = options;
this.pathConverter = pathConverter;
}
@@ -55,6 +59,11 @@ public final class TextFormatFileTransport extends FileTransport {
public ArtifactGroupNamer artifactGroupNamer() {
return namer;
}
+
+ @Override
+ public BuildEventProtocolOptions getOptions() {
+ return options;
+ }
};
String protoTextRepresentation = TextFormat.printToString(event.asStreamProto(converters));
write("event {\n" + protoTextRepresentation + "}\n\n");