aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 1 | // 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. |
| 14 | package com.google.devtools.build.lib.buildeventstream; |
| 15 | |
| 16 | import com.google.common.collect.ImmutableList; |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 17 | import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType; |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 18 | import com.google.devtools.build.lib.util.Pair; |
| 19 | import com.google.devtools.build.lib.vfs.Path; |
| 20 | import com.google.protobuf.ByteString; |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 21 | import java.util.Collection; |
| 22 | |
| 23 | /** Event reporting on statistics about the build. */ |
| 24 | public class BuildToolLogs implements BuildEventWithOrderConstraint { |
aehlig | b064d53 | 2017-11-14 00:59:01 -0800 | [diff] [blame] | 25 | private final Collection<Pair<String, ByteString>> directValues; |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 26 | private final Collection<Pair<String, Path>> logFiles; |
| 27 | |
| 28 | public BuildToolLogs( |
aehlig | b064d53 | 2017-11-14 00:59:01 -0800 | [diff] [blame] | 29 | Collection<Pair<String, ByteString>> directValues, Collection<Pair<String, Path>> logFiles) { |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 30 | 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() { |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 41 | return ImmutableList.of(); |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | @Override |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 45 | public Collection<LocalFile> referencedLocalFiles() { |
| 46 | ImmutableList.Builder<LocalFile> localFiles = ImmutableList.builder(); |
ulfjack | 68aa410 | 2018-06-15 01:40:02 -0700 | [diff] [blame] | 47 | for (Pair<String, Path> logFile : logFiles) { |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 48 | localFiles.add(new LocalFile(logFile.getSecond(), LocalFileType.LOG)); |
ulfjack | 68aa410 | 2018-06-15 01:40:02 -0700 | [diff] [blame] | 49 | } |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 50 | return localFiles.build(); |
ulfjack | 68aa410 | 2018-06-15 01:40:02 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 54 | public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) { |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 55 | BuildEventStreamProtos.BuildToolLogs.Builder toolLogs = |
| 56 | BuildEventStreamProtos.BuildToolLogs.newBuilder(); |
aehlig | b064d53 | 2017-11-14 00:59:01 -0800 | [diff] [blame] | 57 | for (Pair<String, ByteString> direct : directValues) { |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 58 | toolLogs.addLog( |
| 59 | BuildEventStreamProtos.File.newBuilder() |
| 60 | .setName(direct.getFirst()) |
aehlig | b064d53 | 2017-11-14 00:59:01 -0800 | [diff] [blame] | 61 | .setContents(direct.getSecond()) |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 62 | .build()); |
| 63 | } |
| 64 | for (Pair<String, Path> logFile : logFiles) { |
tomlu | fb8332f | 2018-07-11 12:21:23 -0700 | [diff] [blame] | 65 | 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 | } |
aehlig | 61c0da1 | 2017-10-26 18:36:14 +0200 | [diff] [blame] | 73 | } |
| 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 | } |