Klaus Aehlig | a62fb6d | 2016-03-23 15:59:40 +0000 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 15 | package com.google.devtools.build.lib.analysis; |
| 16 | |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableList; |
| 18 | import com.google.devtools.build.lib.buildeventstream.BuildEvent; |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.buildeventstream.BuildEventContext; |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 20 | import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil; |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 21 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 22 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId; |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 23 | import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; |
| 24 | import com.google.devtools.build.lib.buildeventstream.ProgressEvent; |
lpino | 9fbd31f | 2018-09-26 09:55:26 -0700 | [diff] [blame] | 25 | import com.google.devtools.build.lib.util.ProcessUtils; |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 26 | import java.util.Collection; |
| 27 | |
| 28 | /** This event raised to indicate that no build will be happening for the given command. */ |
| 29 | public final class NoBuildEvent implements BuildEvent { |
Klaus Aehlig | a4aef1c | 2017-08-09 13:51:46 +0200 | [diff] [blame] | 30 | private final String id; |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 31 | private final String command; |
| 32 | private final Long startTimeMillis; |
Klaus Aehlig | 280a671 | 2017-06-23 21:12:47 +0200 | [diff] [blame] | 33 | private final boolean separateFinishedEvent; |
Benjamin Peterson | 7c074b5 | 2017-07-28 11:37:30 +0200 | [diff] [blame] | 34 | private final boolean showProgress; |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 35 | |
nharmata | f4023b9 | 2018-11-07 14:33:51 -0800 | [diff] [blame] | 36 | public NoBuildEvent( |
Klaus Aehlig | a4aef1c | 2017-08-09 13:51:46 +0200 | [diff] [blame] | 37 | String command, |
| 38 | Long startTimeMillis, |
| 39 | boolean separateFinishedEvent, |
| 40 | boolean showProgress, |
nharmata | f4023b9 | 2018-11-07 14:33:51 -0800 | [diff] [blame] | 41 | String id) { |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 42 | this.command = command; |
| 43 | this.startTimeMillis = startTimeMillis; |
Klaus Aehlig | 280a671 | 2017-06-23 21:12:47 +0200 | [diff] [blame] | 44 | this.separateFinishedEvent = separateFinishedEvent; |
Benjamin Peterson | 7c074b5 | 2017-07-28 11:37:30 +0200 | [diff] [blame] | 45 | this.showProgress = showProgress; |
Klaus Aehlig | a4aef1c | 2017-08-09 13:51:46 +0200 | [diff] [blame] | 46 | this.id = id; |
Klaus Aehlig | 57ff834 | 2017-07-14 12:25:11 +0200 | [diff] [blame] | 47 | } |
| 48 | |
nharmata | f4023b9 | 2018-11-07 14:33:51 -0800 | [diff] [blame] | 49 | public NoBuildEvent(String command, Long startTimeMillis, boolean separateFinishedEvent) { |
| 50 | this(command, startTimeMillis, separateFinishedEvent, false, null); |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 51 | } |
| 52 | |
nharmata | f4023b9 | 2018-11-07 14:33:51 -0800 | [diff] [blame] | 53 | public NoBuildEvent() { |
| 54 | this(null, null, false); |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Collection<BuildEventId> getChildrenEvents() { |
Klaus Aehlig | 280a671 | 2017-06-23 21:12:47 +0200 | [diff] [blame] | 59 | if (separateFinishedEvent) { |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 60 | return ImmutableList.of( |
| 61 | ProgressEvent.INITIAL_PROGRESS_UPDATE, BuildEventIdUtil.buildFinished()); |
nharmata | f4023b9 | 2018-11-07 14:33:51 -0800 | [diff] [blame] | 62 | } else { |
| 63 | return ImmutableList.of(ProgressEvent.INITIAL_PROGRESS_UPDATE); |
Klaus Aehlig | 280a671 | 2017-06-23 21:12:47 +0200 | [diff] [blame] | 64 | } |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public BuildEventId getEventId() { |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 69 | return BuildEventIdUtil.buildStartedId(); |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 73 | public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) { |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 74 | BuildEventStreamProtos.BuildStarted.Builder started = |
| 75 | BuildEventStreamProtos.BuildStarted.newBuilder() |
| 76 | .setBuildToolVersion(BlazeVersionInfo.instance().getVersion()); |
| 77 | if (command != null) { |
| 78 | started.setCommand(command); |
| 79 | } |
| 80 | if (startTimeMillis != null) { |
| 81 | started.setStartTimeMillis(startTimeMillis); |
| 82 | } |
Klaus Aehlig | a4aef1c | 2017-08-09 13:51:46 +0200 | [diff] [blame] | 83 | if (id != null) { |
| 84 | started.setUuid(id); |
| 85 | } |
lpino | 9fbd31f | 2018-09-26 09:55:26 -0700 | [diff] [blame] | 86 | started.setServerPid(ProcessUtils.getpid()); |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 87 | return GenericBuildEvent.protoChaining(this).setStarted(started.build()).build(); |
| 88 | } |
Klaus Aehlig | 280a671 | 2017-06-23 21:12:47 +0200 | [diff] [blame] | 89 | |
felly | 22cdcc5 | 2019-01-23 07:47:22 -0800 | [diff] [blame] | 90 | /** |
| 91 | * Iff true, clients will expect to a receive a separate {@link |
| 92 | * com.google.devtools.build.lib.buildeventstream.BuildCompletingEvent}. |
| 93 | */ |
Klaus Aehlig | 280a671 | 2017-06-23 21:12:47 +0200 | [diff] [blame] | 94 | public boolean separateFinishedEvent() { |
| 95 | return separateFinishedEvent; |
| 96 | } |
Klaus Aehlig | 57ff834 | 2017-07-14 12:25:11 +0200 | [diff] [blame] | 97 | |
Benjamin Peterson | 7c074b5 | 2017-07-28 11:37:30 +0200 | [diff] [blame] | 98 | public boolean showProgress() { |
| 99 | return showProgress; |
Klaus Aehlig | 57ff834 | 2017-07-14 12:25:11 +0200 | [diff] [blame] | 100 | } |
Klaus Aehlig | d8c286d | 2017-06-16 17:30:27 +0200 | [diff] [blame] | 101 | } |