diff options
Diffstat (limited to 'src')
18 files changed, 176 insertions, 40 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"); diff --git a/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java b/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java index 2b3afda7cd..45cded6792 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.actions.ActionExecutedEvent; import com.google.devtools.build.lib.actions.ActionExecutedEvent.ErrorTiming; import com.google.devtools.build.lib.actions.util.ActionsTestUtil; import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions; +import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions; import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.build.lib.buildeventstream.transports.BinaryFormatFileTransport; import com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions; @@ -112,6 +113,8 @@ public class BazelBuildEventServiceModuleTest { when(optionsProvider.getOptions(BuildEventServiceOptions.class)).thenReturn(besOptions); when(optionsProvider.getOptions(AuthAndTLSOptions.class)) .thenReturn(Options.getDefaults(AuthAndTLSOptions.class)); + when(optionsProvider.getOptions(BuildEventProtocolOptions.class)) + .thenReturn(Options.getDefaults(BuildEventProtocolOptions.class)); } @After diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD index f8d35d5f20..e39b9d378d 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD @@ -21,6 +21,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", "//src/main/java/com/google/devtools/build/lib/buildeventstream/transports", "//src/main/java/com/google/devtools/build/lib/vfs", + "//src/main/java/com/google/devtools/common/options", "//src/test/java/com/google/devtools/build/lib:packages_testutil", "//third_party:guava", "//third_party:junit4", diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java index 0940ab3fb6..51951e4f8a 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java @@ -20,11 +20,13 @@ import static org.mockito.Mockito.when; 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.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Progress; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TargetComplete; import com.google.devtools.build.lib.buildeventstream.PathConverter; +import com.google.devtools.common.options.Options; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; @@ -44,6 +46,8 @@ import org.mockito.MockitoAnnotations; /** Tests {@link BinaryFormatFileTransport}. **/ @RunWith(JUnit4.class) public class BinaryFormatFileTransportTest { + private final BuildEventProtocolOptions defaultOpts = + Options.getDefaults(BuildEventProtocolOptions.class); @Rule public TemporaryFolder tmp = new TemporaryFolder(); @@ -72,7 +76,7 @@ public class BinaryFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(output.getAbsolutePath(), pathConverter); + new BinaryFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); transport.sendBuildEvent(buildEvent, artifactGroupNamer); BuildEventStreamProtos.BuildEvent progress = @@ -108,7 +112,8 @@ public class BinaryFormatFileTransportTest { .setStarted(BuildStarted.newBuilder().setCommand("build")) .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); - BinaryFormatFileTransport transport = new BinaryFormatFileTransport(path, pathConverter); + BinaryFormatFileTransport transport = + new BinaryFormatFileTransport(path, defaultOpts, pathConverter); transport.sendBuildEvent(buildEvent, artifactGroupNamer); transport.close().get(); @@ -129,7 +134,7 @@ public class BinaryFormatFileTransportTest { when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(output.getAbsolutePath(), pathConverter); + new BinaryFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); // Close the stream. transport.out.close(); @@ -156,7 +161,7 @@ public class BinaryFormatFileTransportTest { when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(output.getAbsolutePath(), pathConverter); + new BinaryFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); transport.sendBuildEvent(buildEvent, artifactGroupNamer); Future<Void> closeFuture = transport.close(); diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java index ccbd9dbc18..e5d5133cca 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java @@ -23,10 +23,12 @@ import com.google.common.collect.ImmutableSet; 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.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; import com.google.devtools.build.lib.buildeventstream.PathConverter; +import com.google.devtools.common.options.Options; import java.io.File; import java.io.IOException; import java.util.concurrent.Future; @@ -59,6 +61,9 @@ public class BuildEventTransportFactoryTest { .setStarted(BuildStarted.newBuilder().setCommand("build")) .build(); + private final BuildEventProtocolOptions protocolOpts = + Options.getDefaults(BuildEventProtocolOptions.class); + @Rule public TemporaryFolder tmp = new TemporaryFolder(); @Mock public BuildEventStreamOptions options; @@ -87,7 +92,7 @@ public class BuildEventTransportFactoryTest { when(options.getBuildEventTextFilePathConversion()).thenReturn(true); when(options.getBuildEventBinaryFile()).thenReturn(""); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, pathConverter); + BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -101,7 +106,7 @@ public class BuildEventTransportFactoryTest { when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); when(options.getBuildEventBinaryFilePathConversion()).thenReturn(true); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, pathConverter); + BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -117,7 +122,7 @@ public class BuildEventTransportFactoryTest { when(options.getBuildEventBinaryFilePathConversion()).thenReturn(true); when(options.getBuildEventTextFilePathConversion()).thenReturn(true); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, pathConverter); + BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class, BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -129,7 +134,7 @@ public class BuildEventTransportFactoryTest { public void testCreatesNoTransports() throws IOException { when(options.getBuildEventTextFile()).thenReturn(""); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, pathConverter); + BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); assertThat(transports).isEmpty(); } diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java index f051891358..e667a7d787 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java @@ -20,9 +20,11 @@ import static org.mockito.Mockito.when; 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.BuildStarted; import com.google.devtools.build.lib.buildeventstream.PathConverter; +import com.google.devtools.common.options.Options; import com.google.protobuf.util.JsonFormat; import java.io.File; import java.io.FileInputStream; @@ -44,6 +46,8 @@ import org.mockito.MockitoAnnotations; /** Tests {@link TextFormatFileTransport}. * */ @RunWith(JUnit4.class) public class JsonFormatFileTransportTest { + private final BuildEventProtocolOptions defaultOpts = + Options.getDefaults(BuildEventProtocolOptions.class); @Rule public TemporaryFolder tmp = new TemporaryFolder(); @@ -72,7 +76,7 @@ public class JsonFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); JsonFormatFileTransport transport = - new JsonFormatFileTransport(output.getAbsolutePath(), pathConverter); + new JsonFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); transport.sendBuildEvent(buildEvent, artifactGroupNamer); transport.close().get(); diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java index 9a552d8c26..c3ad19d0d6 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java @@ -22,11 +22,13 @@ import com.google.common.io.Files; 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.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Progress; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TargetComplete; import com.google.devtools.build.lib.buildeventstream.PathConverter; +import com.google.devtools.common.options.Options; import com.google.protobuf.TextFormat; import java.io.File; import java.nio.charset.StandardCharsets; @@ -45,6 +47,8 @@ import org.mockito.MockitoAnnotations; /** Tests {@link TextFormatFileTransport}. **/ @RunWith(JUnit4.class) public class TextFormatFileTransportTest { + private final BuildEventProtocolOptions defaultOpts = + Options.getDefaults(BuildEventProtocolOptions.class); @Rule public TemporaryFolder tmp = new TemporaryFolder(); @@ -73,7 +77,7 @@ public class TextFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); TextFormatFileTransport transport = - new TextFormatFileTransport(output.getAbsolutePath(), pathConverter); + new TextFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); transport.sendBuildEvent(buildEvent, artifactGroupNamer); BuildEventStreamProtos.BuildEvent progress = diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java index 5a0ea34e55..d50717d9a7 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java @@ -43,6 +43,7 @@ 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.BuildEventId; +import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId.NamedSetOfFilesId; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; @@ -62,6 +63,7 @@ import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.Root; +import com.google.devtools.common.options.Options; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -118,6 +120,11 @@ public class BuildEventStreamerTest extends FoundationTestCase { } }; } + + @Override + public BuildEventProtocolOptions getOptions() { + return Options.getDefaults(BuildEventProtocolOptions.class); + } })); } |