From dadde6f1bf93efa3e73dbbbf557ec37a57a0eefe Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 18 Jan 2017 17:32:07 +0000 Subject: Support mapping of Paths to URIs Bazel-created files (like log files of test runs) are internally reported as Paths. However, this is not always the most useful representation of the location of that artifact for a consumer of build events. Therefore, support a mapping of paths to more useful URIs. -- PiperOrigin-RevId: 144843525 MOS_MIGRATED_REVID=144843525 --- .../build/lib/buildeventstream/transports/BUILD | 1 + .../transports/BinaryFormatFileTransport.java | 8 ++++++-- .../transports/BuildEventTransportFactory.java | 20 ++++++++++++-------- .../transports/TextFormatFileTransport.java | 8 ++++++-- 4 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/buildeventstream/transports') diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD index 11b6c22ccc..14674f56b9 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD @@ -10,6 +10,7 @@ java_library( srcs = glob(["*.java"]), deps = [ "//src/main/java/com/google/devtools/build/lib:buildeventstream", + "//src/main/java/com/google/devtools/build/lib:vfs", "//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", "//src/main/java/com/google/devtools/common/options", "//third_party:guava", 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 c0f341e2eb..1bf30b7c0e 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 @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.buildeventstream.transports; import com.google.devtools.build.lib.buildeventstream.BuildEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -29,14 +30,17 @@ import java.io.IOException; */ public final class BinaryFormatFileTransport implements BuildEventTransport { private final BufferedOutputStream out; + private final PathConverter pathConverter; - public BinaryFormatFileTransport(String path) throws IOException { + public BinaryFormatFileTransport(String path, PathConverter pathConverter) + throws IOException { this.out = new BufferedOutputStream(new FileOutputStream(new File(path))); + this.pathConverter = pathConverter; } @Override public synchronized void sendBuildEvent(BuildEvent event) throws IOException { - event.asStreamProto().writeDelimitedTo(out); + event.asStreamProto(pathConverter).writeDelimitedTo(out); out.flush(); } 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 f456b189d6..6d8f97f17f 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 @@ -19,6 +19,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import java.io.IOException; /** Factory used to create a Set of BuildEventTransports from BuildEventStreamOptions. */ @@ -30,8 +31,9 @@ public enum BuildEventTransportFactory { } @Override - protected BuildEventTransport create(BuildEventStreamOptions options) throws IOException { - return new TextFormatFileTransport(options.getBuildEventTextFile()); + protected BuildEventTransport create(BuildEventStreamOptions options, + PathConverter pathConverter) throws IOException { + return new TextFormatFileTransport(options.getBuildEventTextFile(), pathConverter); } }, @@ -42,8 +44,9 @@ public enum BuildEventTransportFactory { } @Override - protected BuildEventTransport create(BuildEventStreamOptions options) throws IOException { - return new BinaryFormatFileTransport(options.getBuildEventBinaryFile()); + protected BuildEventTransport create(BuildEventStreamOptions options, + PathConverter pathConverter) throws IOException { + return new BinaryFormatFileTransport(options.getBuildEventBinaryFile(), pathConverter); } }; @@ -55,12 +58,12 @@ 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 createFromOptions(BuildEventStreamOptions options) - throws IOException { + public static ImmutableSet createFromOptions(BuildEventStreamOptions options, + PathConverter pathConverter) throws IOException { Builder buildEventTransportsBuilder = ImmutableSet.builder(); for (BuildEventTransportFactory transportFactory : BuildEventTransportFactory.values()) { if (transportFactory.enabled(options)) { - buildEventTransportsBuilder.add(transportFactory.create(options)); + buildEventTransportsBuilder.add(transportFactory.create(options, pathConverter)); } } return buildEventTransportsBuilder.build(); @@ -70,5 +73,6 @@ public enum BuildEventTransportFactory { protected abstract boolean enabled(BuildEventStreamOptions options); /** Creates a BuildEventTransport from the specified options. */ - protected abstract BuildEventTransport create(BuildEventStreamOptions options) throws IOException; + protected abstract BuildEventTransport create(BuildEventStreamOptions options, + PathConverter pathConverter) throws IOException; } 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 98b7520c33..5f8f59d338 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 @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.buildeventstream.transports; import com.google.devtools.build.lib.buildeventstream.BuildEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.protobuf.TextFormat; import java.io.File; import java.io.FileOutputStream; @@ -28,15 +29,18 @@ import java.nio.charset.StandardCharsets; */ public final class TextFormatFileTransport implements BuildEventTransport { private FileOutputStream out; + private final PathConverter pathConverter; - public TextFormatFileTransport(String path) throws IOException { + public TextFormatFileTransport(String path, PathConverter pathConverter) + throws IOException { this.out = new FileOutputStream(new File(path)); + this.pathConverter = pathConverter; } @Override public synchronized void sendBuildEvent(BuildEvent event) throws IOException { if (out != null) { - String protoTextRepresentation = TextFormat.printToString(event.asStreamProto()); + String protoTextRepresentation = TextFormat.printToString(event.asStreamProto(pathConverter)); out.write(("event {\n" + protoTextRepresentation + "}\n\n").getBytes(StandardCharsets.UTF_8)); out.flush(); } -- cgit v1.2.3