diff options
Diffstat (limited to 'src/main')
11 files changed, 137 insertions, 30 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java index e6f5c3f281..a3594460f1 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java @@ -232,10 +232,12 @@ public final class TargetCompleteEvent // TODO(aehlig): remove direct reporting of artifacts as soon as clients no longer // need it. - addImportantOutputs(builder, converters, getLegacyFilteredImportantArtifacts()); - if (baselineCoverageArtifacts != null) { - addImportantOutputs( - builder, (artifact -> BASELINE_COVERAGE), converters, baselineCoverageArtifacts); + if (converters.getOptions().legacyImportantOutputs) { + addImportantOutputs(builder, converters, getLegacyFilteredImportantArtifacts()); + if (baselineCoverageArtifacts != null) { + addImportantOutputs( + builder, (artifact -> BASELINE_COVERAGE), converters, baselineCoverageArtifacts); + } } BuildEventStreamProtos.TargetComplete complete = builder.build(); diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java index 4ff32f1e02..a4e295751c 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java @@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions; import com.google.devtools.build.lib.buildeventservice.client.BuildEventServiceClient; +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.buildeventstream.transports.BuildEventStreamOptions; @@ -63,7 +64,11 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions @Override public Iterable<Class<? extends OptionsBase>> getCommonCommandOptions() { - return ImmutableList.of(optionsClass(), AuthAndTLSOptions.class, BuildEventStreamOptions.class); + return ImmutableList.of( + optionsClass(), + AuthAndTLSOptions.class, + BuildEventStreamOptions.class, + BuildEventProtocolOptions.class); } @Override @@ -151,6 +156,9 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions BuildEventStreamOptions bepOptions = checkNotNull(optionsProvider.getOptions(BuildEventStreamOptions.class), "Could not get BuildEventStreamOptions."); + BuildEventProtocolOptions protocolOptions = + checkNotNull(optionsProvider.getOptions(BuildEventProtocolOptions.class), + "Could not get BuildEventProtocolOptions."); BuildEventTransport besTransport = null; try { @@ -163,6 +171,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions commandName, moduleEnvironment, clock, + protocolOptions, pathConverter, commandLineReporter, startupOptionsProvider); @@ -178,7 +187,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions } ImmutableSet<BuildEventTransport> bepTransports = - BuildEventTransportFactory.createFromOptions(bepOptions, pathConverter); + BuildEventTransportFactory.createFromOptions(bepOptions, protocolOptions, pathConverter); ImmutableSet.Builder<BuildEventTransport> transportsBuilder = ImmutableSet.<BuildEventTransport>builder().addAll(bepTransports); @@ -207,6 +216,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions String commandName, ModuleEnvironment moduleEnvironment, Clock clock, + BuildEventProtocolOptions protocolOptions, PathConverter pathConverter, EventHandler commandLineReporter, OptionsProvider startupOptionsProvider) @@ -244,6 +254,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions commandName, moduleEnvironment, clock, + protocolOptions, pathConverter, commandLineReporter, besOptions.projectId, diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java index 8783ef01df..ee5c654d95 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.buildeventservice.client.BuildEventServiceC 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.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEvent.PayloadCase; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildFinished; @@ -94,6 +95,7 @@ public class BuildEventServiceTransport implements BuildEventTransport { private final BuildEventServiceProtoUtil besProtoUtil; private final ModuleEnvironment moduleEnvironment; private final EventHandler commandLineReporter; + private final BuildEventProtocolOptions protocolOptions; private final PathConverter pathConverter; private final Sleeper sleeper; /** Contains all pendingAck events that might be retried in case of failures. */ @@ -130,13 +132,14 @@ public class BuildEventServiceTransport implements BuildEventTransport { String command, ModuleEnvironment moduleEnvironment, Clock clock, + BuildEventProtocolOptions protocolOptions, PathConverter pathConverter, EventHandler commandLineReporter, @Nullable String projectId, Set<String> keywords) { this(besClient, uploadTimeout, bestEffortUpload, publishLifecycleEvents, buildRequestId, - invocationId, command, moduleEnvironment, clock, pathConverter, commandLineReporter, - projectId, keywords, new JavaSleeper()); + invocationId, command, moduleEnvironment, clock, protocolOptions, pathConverter, + commandLineReporter, projectId, keywords, new JavaSleeper()); } @VisibleForTesting @@ -150,6 +153,7 @@ public class BuildEventServiceTransport implements BuildEventTransport { String command, ModuleEnvironment moduleEnvironment, Clock clock, + BuildEventProtocolOptions protocolOptions, PathConverter pathConverter, EventHandler commandLineReporter, @Nullable String projectId, @@ -169,6 +173,7 @@ public class BuildEventServiceTransport implements BuildEventTransport { // loop by publishEventStream re-submitting itself to the executor. // TODO(buchgr): Fix it. this.uploaderExecutorService = listeningDecorator(Executors.newFixedThreadPool(2)); + this.protocolOptions = protocolOptions; this.pathConverter = pathConverter; this.invocationResult = UNKNOWN_STATUS; this.uploadTimeout = uploadTimeout; @@ -292,10 +297,16 @@ public class BuildEventServiceTransport implements BuildEventTransport { public PathConverter pathConverter() { return pathConverter; } + @Override public ArtifactGroupNamer artifactGroupNamer() { return namer; } + + @Override + public BuildEventProtocolOptions getOptions() { + return protocolOptions; + } }); if (PayloadCase.FINISHED.equals(eventProto.getPayloadCase())) { BuildFinished finished = eventProto.getFinished(); 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"); |