aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/buildeventstream
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-04-07 14:25:27 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-04-07 16:44:52 +0200
commitee3e19202ab9aaf3ed6ff13af029a7f643af7f3a (patch)
treea6971718cfc642ece74520a057fe8fed88c7fbd5 /src/main/java/com/google/devtools/build/lib/buildeventstream
parent90349cace2d7e883616c62f15cb9a19d625f0515 (diff)
BEP: Extend infrastructure to allow reporting artifacts only once
Extend the functionality of the BuildEventStreamer to report those parts of NestedSets of Artifacts not reported earlier. In this way, duplicate reporting can be avoided, without the events themselves having to know which artifacts are known already. Change-Id: Ia959c28c440301860eac57ea5d9a712c0d49ebdf PiperOrigin-RevId: 152497672
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/buildeventstream')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/ArtifactGroupNamer.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventConverters.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventTransport.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransport.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/FileTransport.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransport.java22
7 files changed, 77 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/ArtifactGroupNamer.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/ArtifactGroupNamer.java
new file mode 100644
index 0000000000..ede4767e41
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/ArtifactGroupNamer.java
@@ -0,0 +1,26 @@
+// Copyright 2017 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;
+
+
+/** Interface for conversion of paths to URIs. */
+public interface ArtifactGroupNamer {
+ /**
+ * Return the name of a declared group of artifacts, identified by the identifier of their {@link
+ * NestedSetView}. A {@link BuildEvent} should only assume that this function is defined if the
+ * corresponding {@link NestedSet<Artifact>} is declared via the {@link EventReportingArtifacts}
+ * interface. On undefined positions, the value null is returned.
+ */
+ BuildEventStreamProtos.BuildEventId.NamedSetOfFilesId apply(Object id);
+}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventConverters.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventConverters.java
index 1943c1f2cf..2ade08695d 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventConverters.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventConverters.java
@@ -24,4 +24,10 @@ public interface BuildEventConverters {
* be reported in the event.
*/
PathConverter pathConverter();
+
+ /**
+ * Return the {@link ArtifactGroupNamer} that can be used to refer to a {@link
+ * NestedSet<Artifact>} declared via the {@link EventReportingArtifacts} interface.
+ */
+ ArtifactGroupNamer artifactGroupNamer();
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java
index 7fa1bf1c60..33151e9837 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java
@@ -156,6 +156,13 @@ public final class BuildEventId implements Serializable {
.build());
}
+ public static BuildEventId fromArtifactGroupName(String name) {
+ BuildEventStreamProtos.BuildEventId.NamedSetOfFilesId namedSetId =
+ BuildEventStreamProtos.BuildEventId.NamedSetOfFilesId.newBuilder().setId(name).build();
+ return new BuildEventId(
+ BuildEventStreamProtos.BuildEventId.newBuilder().setNamedSet(namedSetId).build());
+ }
+
public static BuildEventId testResult(Label target, Integer run, Integer shard, Integer attempt) {
BuildEventStreamProtos.BuildEventId.TestResultId resultId =
BuildEventStreamProtos.BuildEventId.TestResultId.newBuilder()
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventTransport.java
index 318282fc27..dba5a123d2 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventTransport.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventTransport.java
@@ -38,7 +38,7 @@ public interface BuildEventTransport {
*
* @param event the event to sendBuildEvent.
*/
- void sendBuildEvent(BuildEvent event);
+ void sendBuildEvent(BuildEvent event, ArtifactGroupNamer namer);
/**
* Initiates a close. Callers may listen to the returned future to be notified when the close
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 ccfa14c0b2..9de20b7175 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,7 +16,9 @@ package com.google.devtools.build.lib.buildeventstream.transports;
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.BuildEventConverters;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
@@ -34,13 +36,26 @@ public final class BinaryFormatFileTransport extends FileTransport {
private static final Logger log = Logger.getLogger(BinaryFormatFileTransport.class.getName());
private static final int MAX_VARINT_BYTES = 9;
+ private final PathConverter pathConverter;
BinaryFormatFileTransport(String path, PathConverter pathConverter) {
- super(path, pathConverter);
+ super(path);
+ this.pathConverter = pathConverter;
}
@Override
- public void sendBuildEvent(BuildEvent event) {
+ public synchronized void sendBuildEvent(BuildEvent event, final ArtifactGroupNamer namer) {
+ BuildEventConverters converters =
+ new BuildEventConverters() {
+ @Override
+ public PathConverter pathConverter() {
+ return pathConverter;
+ }
+ @Override
+ public ArtifactGroupNamer artifactGroupNamer() {
+ return namer;
+ }
+ };
checkNotNull(event);
BuildEventStreamProtos.BuildEvent protoEvent = event.asStreamProto(converters);
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 e691df1819..6744df3ef6 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
@@ -20,9 +20,7 @@ import static com.google.common.base.Preconditions.checkState;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.SettableFuture;
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
-import com.google.devtools.build.lib.buildeventstream.BuildEventConverters;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
-import com.google.devtools.build.lib.buildeventstream.PathConverter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousFileChannel;
@@ -55,7 +53,6 @@ abstract class FileTransport implements BuildEventTransport {
@VisibleForTesting
final AsynchronousFileChannel ch;
private final WriteCompletionHandler completionHandler = new WriteCompletionHandler();
- protected final BuildEventConverters converters;
// The offset in the file to begin the next write at.
private long writeOffset;
// Number of writes that haven't completed yet.
@@ -63,19 +60,13 @@ abstract class FileTransport implements BuildEventTransport {
// The future returned by close()
private SettableFuture<Void> closeFuture;
- FileTransport(String path, final PathConverter pathConverter) {
+ FileTransport(String path) {
try {
ch = AsynchronousFileChannel.open(Paths.get(path), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
} catch (IOException e) {
throw new RuntimeException(e);
}
- this.converters = new BuildEventConverters() {
- @Override
- public PathConverter pathConverter() {
- return pathConverter;
- }
- };
}
synchronized void writeData(byte[] data) {
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 e331c0c573..cf892955a7 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
@@ -14,7 +14,9 @@
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.BuildEventConverters;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.protobuf.TextFormat;
@@ -28,15 +30,29 @@ import java.io.IOException;
*/
public final class TextFormatFileTransport extends FileTransport {
+ private final PathConverter pathConverter;
+
TextFormatFileTransport(String path, PathConverter pathConverter) throws IOException {
- super(path, pathConverter);
+ super(path);
+ this.pathConverter = pathConverter;
}
@Override
- public void sendBuildEvent(BuildEvent event) {
+ public synchronized void sendBuildEvent(BuildEvent event, final ArtifactGroupNamer namer) {
+ BuildEventConverters converters =
+ new BuildEventConverters() {
+ @Override
+ public PathConverter pathConverter() {
+ return pathConverter;
+ }
+
+ @Override
+ public ArtifactGroupNamer artifactGroupNamer() {
+ return namer;
+ }
+ };
String protoTextRepresentation = TextFormat.printToString(event.asStreamProto(converters));
String line = "event {\n" + protoTextRepresentation + "}\n\n";
-
writeData(line.getBytes());
}
}