blob: eb5358b7f546357ba72f2d0a804bbb22dcf52f1c [file] [log] [blame]
aehlig61c0da12017-10-26 18:36:14 +02001// Copyright 2017 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.buildeventstream;
15
16import com.google.common.collect.ImmutableList;
tomlu2348a752018-07-04 08:55:42 -070017import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType;
aehlig61c0da12017-10-26 18:36:14 +020018import com.google.devtools.build.lib.util.Pair;
19import com.google.devtools.build.lib.vfs.Path;
20import com.google.protobuf.ByteString;
aehlig61c0da12017-10-26 18:36:14 +020021import java.util.Collection;
22
23/** Event reporting on statistics about the build. */
24public class BuildToolLogs implements BuildEventWithOrderConstraint {
aehligb064d532017-11-14 00:59:01 -080025 private final Collection<Pair<String, ByteString>> directValues;
aehlig61c0da12017-10-26 18:36:14 +020026 private final Collection<Pair<String, Path>> logFiles;
27
28 public BuildToolLogs(
aehligb064d532017-11-14 00:59:01 -080029 Collection<Pair<String, ByteString>> directValues, Collection<Pair<String, Path>> logFiles) {
aehlig61c0da12017-10-26 18:36:14 +020030 this.directValues = directValues;
31 this.logFiles = logFiles;
32 }
33
34 @Override
35 public BuildEventId getEventId() {
36 return BuildEventId.buildToolLogs();
37 }
38
39 @Override
40 public Collection<BuildEventId> getChildrenEvents() {
tomlu2348a752018-07-04 08:55:42 -070041 return ImmutableList.of();
aehlig61c0da12017-10-26 18:36:14 +020042 }
43
44 @Override
tomlu2348a752018-07-04 08:55:42 -070045 public Collection<LocalFile> referencedLocalFiles() {
46 ImmutableList.Builder<LocalFile> localFiles = ImmutableList.builder();
ulfjack68aa4102018-06-15 01:40:02 -070047 for (Pair<String, Path> logFile : logFiles) {
tomlu2348a752018-07-04 08:55:42 -070048 localFiles.add(new LocalFile(logFile.getSecond(), LocalFileType.LOG));
ulfjack68aa4102018-06-15 01:40:02 -070049 }
tomlu2348a752018-07-04 08:55:42 -070050 return localFiles.build();
ulfjack68aa4102018-06-15 01:40:02 -070051 }
52
53 @Override
ulfjack26e586d2018-05-17 08:42:13 -070054 public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) {
aehlig61c0da12017-10-26 18:36:14 +020055 BuildEventStreamProtos.BuildToolLogs.Builder toolLogs =
56 BuildEventStreamProtos.BuildToolLogs.newBuilder();
aehligb064d532017-11-14 00:59:01 -080057 for (Pair<String, ByteString> direct : directValues) {
aehlig61c0da12017-10-26 18:36:14 +020058 toolLogs.addLog(
59 BuildEventStreamProtos.File.newBuilder()
60 .setName(direct.getFirst())
aehligb064d532017-11-14 00:59:01 -080061 .setContents(direct.getSecond())
aehlig61c0da12017-10-26 18:36:14 +020062 .build());
63 }
64 for (Pair<String, Path> logFile : logFiles) {
tomlufb8332f2018-07-11 12:21:23 -070065 String uri = converters.pathConverter().apply(logFile.getSecond());
66 if (uri != null) {
67 toolLogs.addLog(
68 BuildEventStreamProtos.File.newBuilder()
69 .setName(logFile.getFirst())
70 .setUri(uri)
71 .build());
72 }
aehlig61c0da12017-10-26 18:36:14 +020073 }
74 return GenericBuildEvent.protoChaining(this).setBuildToolLogs(toolLogs.build()).build();
75 }
76
77 @Override
78 public Collection<BuildEventId> postedAfter() {
79 return ImmutableList.of(BuildEventId.buildFinished());
80 }
81}