blob: e124cb4649241c016675d9cd6e8927bde7fa2058 [file] [log] [blame]
Klaus Aehliga62fb6d2016-03-23 15:59:40 +00001// 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
15package com.google.devtools.build.lib.analysis;
16
Klaus Aehligd8c286d2017-06-16 17:30:27 +020017import com.google.common.collect.ImmutableList;
18import com.google.devtools.build.lib.buildeventstream.BuildEvent;
ulfjack26e586d2018-05-17 08:42:13 -070019import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
janakr3ca24682020-04-01 09:12:03 -070020import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil;
Klaus Aehligd8c286d2017-06-16 17:30:27 +020021import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
janakr3ca24682020-04-01 09:12:03 -070022import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId;
Klaus Aehligd8c286d2017-06-16 17:30:27 +020023import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
24import com.google.devtools.build.lib.buildeventstream.ProgressEvent;
lpino9fbd31f2018-09-26 09:55:26 -070025import com.google.devtools.build.lib.util.ProcessUtils;
Klaus Aehligd8c286d2017-06-16 17:30:27 +020026import java.util.Collection;
27
28/** This event raised to indicate that no build will be happening for the given command. */
29public final class NoBuildEvent implements BuildEvent {
Klaus Aehliga4aef1c2017-08-09 13:51:46 +020030 private final String id;
Klaus Aehligd8c286d2017-06-16 17:30:27 +020031 private final String command;
32 private final Long startTimeMillis;
Klaus Aehlig280a6712017-06-23 21:12:47 +020033 private final boolean separateFinishedEvent;
Benjamin Peterson7c074b52017-07-28 11:37:30 +020034 private final boolean showProgress;
Klaus Aehligd8c286d2017-06-16 17:30:27 +020035
nharmataf4023b92018-11-07 14:33:51 -080036 public NoBuildEvent(
Klaus Aehliga4aef1c2017-08-09 13:51:46 +020037 String command,
38 Long startTimeMillis,
39 boolean separateFinishedEvent,
40 boolean showProgress,
nharmataf4023b92018-11-07 14:33:51 -080041 String id) {
Klaus Aehligd8c286d2017-06-16 17:30:27 +020042 this.command = command;
43 this.startTimeMillis = startTimeMillis;
Klaus Aehlig280a6712017-06-23 21:12:47 +020044 this.separateFinishedEvent = separateFinishedEvent;
Benjamin Peterson7c074b52017-07-28 11:37:30 +020045 this.showProgress = showProgress;
Klaus Aehliga4aef1c2017-08-09 13:51:46 +020046 this.id = id;
Klaus Aehlig57ff8342017-07-14 12:25:11 +020047 }
48
nharmataf4023b92018-11-07 14:33:51 -080049 public NoBuildEvent(String command, Long startTimeMillis, boolean separateFinishedEvent) {
50 this(command, startTimeMillis, separateFinishedEvent, false, null);
Klaus Aehligd8c286d2017-06-16 17:30:27 +020051 }
52
nharmataf4023b92018-11-07 14:33:51 -080053 public NoBuildEvent() {
54 this(null, null, false);
Klaus Aehligd8c286d2017-06-16 17:30:27 +020055 }
56
57 @Override
58 public Collection<BuildEventId> getChildrenEvents() {
Klaus Aehlig280a6712017-06-23 21:12:47 +020059 if (separateFinishedEvent) {
janakr3ca24682020-04-01 09:12:03 -070060 return ImmutableList.of(
61 ProgressEvent.INITIAL_PROGRESS_UPDATE, BuildEventIdUtil.buildFinished());
nharmataf4023b92018-11-07 14:33:51 -080062 } else {
63 return ImmutableList.of(ProgressEvent.INITIAL_PROGRESS_UPDATE);
Klaus Aehlig280a6712017-06-23 21:12:47 +020064 }
Klaus Aehligd8c286d2017-06-16 17:30:27 +020065 }
66
67 @Override
68 public BuildEventId getEventId() {
janakr3ca24682020-04-01 09:12:03 -070069 return BuildEventIdUtil.buildStartedId();
Klaus Aehligd8c286d2017-06-16 17:30:27 +020070 }
71
72 @Override
ulfjack26e586d2018-05-17 08:42:13 -070073 public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) {
Klaus Aehligd8c286d2017-06-16 17:30:27 +020074 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 Aehliga4aef1c2017-08-09 13:51:46 +020083 if (id != null) {
84 started.setUuid(id);
85 }
lpino9fbd31f2018-09-26 09:55:26 -070086 started.setServerPid(ProcessUtils.getpid());
Klaus Aehligd8c286d2017-06-16 17:30:27 +020087 return GenericBuildEvent.protoChaining(this).setStarted(started.build()).build();
88 }
Klaus Aehlig280a6712017-06-23 21:12:47 +020089
felly22cdcc52019-01-23 07:47:22 -080090 /**
91 * Iff true, clients will expect to a receive a separate {@link
92 * com.google.devtools.build.lib.buildeventstream.BuildCompletingEvent}.
93 */
Klaus Aehlig280a6712017-06-23 21:12:47 +020094 public boolean separateFinishedEvent() {
95 return separateFinishedEvent;
96 }
Klaus Aehlig57ff8342017-07-14 12:25:11 +020097
Benjamin Peterson7c074b52017-07-28 11:37:30 +020098 public boolean showProgress() {
99 return showProgress;
Klaus Aehlig57ff8342017-07-14 12:25:11 +0200100 }
Klaus Aehligd8c286d2017-06-16 17:30:27 +0200101}