blob: 53a3f16e7e118aac813128f33c78e522b0411cee [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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
Googlerf592df92018-02-22 19:04:23 -080017import static com.google.devtools.build.lib.buildeventstream.TestFileNameConstants.BASELINE_COVERAGE;
18
tomlua155b532017-11-08 20:12:47 +010019import com.google.common.base.Preconditions;
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +000020import com.google.common.collect.ImmutableList;
Klaus Aehlig4901d8b2017-04-10 15:13:59 +000021import com.google.common.collect.ImmutableSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022import com.google.common.collect.Iterables;
Jakob Buchgraberfb646092017-02-27 18:53:25 +000023import com.google.devtools.build.lib.actions.Artifact;
Klaus Aehlig4901d8b2017-04-10 15:13:59 +000024import com.google.devtools.build.lib.actions.EventReportingArtifacts;
Jakob Buchgraberfb646092017-02-27 18:53:25 +000025import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup;
Klaus Aehlig71c993b2017-05-09 07:49:46 -040026import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
gregce593f7f92017-09-19 02:02:21 +020027import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
Klaus Aehligcba24ab2017-09-27 05:14:11 -040028import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider;
ulfjackab21d182017-08-10 15:36:14 +020029import com.google.devtools.build.lib.analysis.test.TestProvider;
Klaus Aehlig4901d8b2017-04-10 15:13:59 +000030import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer;
Klaus Aehliga708a022017-07-11 12:54:40 +020031import com.google.devtools.build.lib.buildeventstream.BuildEvent;
tomlu2348a752018-07-04 08:55:42 -070032import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType;
ulfjack26e586d2018-05-17 08:42:13 -070033import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +000034import com.google.devtools.build.lib.buildeventstream.BuildEventId;
35import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
Klaus Aehlig0a6cd622017-04-21 17:09:40 +020036import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.File;
Jakob Buchgraberfb646092017-02-27 18:53:25 +000037import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.OutputGroup;
Klaus Aehliga708a022017-07-11 12:54:40 +020038import com.google.devtools.build.lib.buildeventstream.BuildEventWithConfiguration;
Klaus Aehlig74d716b2016-11-23 12:38:24 +000039import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint;
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +000040import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
Klaus Aehligd1f4a162016-10-25 14:51:55 +000041import com.google.devtools.build.lib.causes.Cause;
Klaus Aehlig1f452c32017-02-02 10:19:15 +000042import com.google.devtools.build.lib.cmdline.Label;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010043import com.google.devtools.build.lib.collect.nestedset.NestedSet;
44import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
Klaus Aehlig4901d8b2017-04-10 15:13:59 +000045import com.google.devtools.build.lib.collect.nestedset.NestedSetView;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010046import com.google.devtools.build.lib.collect.nestedset.Order;
Jakob Buchgraberfb646092017-02-27 18:53:25 +000047import com.google.devtools.build.lib.packages.AttributeMap;
mjhalupka14dbe132018-02-13 13:00:52 -080048import com.google.devtools.build.lib.packages.ConfiguredAttributeMapper;
49import com.google.devtools.build.lib.packages.Rule;
Googlere3a0b092018-04-17 07:09:37 -070050import com.google.devtools.build.lib.packages.TestTimeout;
Klaus Aehligce129732017-09-29 07:04:24 -040051import com.google.devtools.build.lib.rules.AliasConfiguredTarget;
janakr60554e42018-03-27 10:26:36 -070052import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
janakr5bd23652018-05-22 17:04:00 -070053import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
Jakob Buchgraberfb646092017-02-27 18:53:25 +000054import com.google.devtools.build.lib.syntax.Type;
janakr5bd23652018-05-22 17:04:00 -070055import com.google.devtools.build.lib.vfs.Path;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010056import com.google.devtools.build.skyframe.SkyValue;
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +000057import java.util.Collection;
Googlerf592df92018-02-22 19:04:23 -080058import java.util.function.Function;
janakr5bd23652018-05-22 17:04:00 -070059import javax.annotation.Nullable;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +000061/** This event is fired as soon as a target is either built or fails. */
Klaus Aehlig4901d8b2017-04-10 15:13:59 +000062public final class TargetCompleteEvent
Klaus Aehlig71c993b2017-05-09 07:49:46 -040063 implements SkyValue,
64 BuildEventWithOrderConstraint,
65 EventReportingArtifacts,
66 BuildEventWithConfiguration {
janakr5bd23652018-05-22 17:04:00 -070067
68 /** Lightweight data needed about the configured target in this event. */
69 public static class ExecutableTargetData {
70 @Nullable private final Path runfilesDirectory;
71 @Nullable private final Artifact executable;
72
73 private ExecutableTargetData(ConfiguredTargetAndData targetAndData) {
74 FilesToRunProvider provider =
75 targetAndData.getConfiguredTarget().getProvider(FilesToRunProvider.class);
76 if (provider != null) {
77 this.executable = provider.getExecutable();
78 if (null != provider.getRunfilesSupport()) {
79 this.runfilesDirectory = provider.getRunfilesSupport().getRunfilesDirectory();
80 } else {
81 this.runfilesDirectory = null;
82 }
83 } else {
84 this.executable = null;
85 this.runfilesDirectory = null;
86 }
87 }
88
89 @Nullable
90 public Path getRunfilesDirectory() {
91 return runfilesDirectory;
92 }
93
94 @Nullable
95 public Artifact getExecutable() {
96 return executable;
97 }
98 }
99
100 private final Label label;
101 private final ConfiguredTargetKey configuredTargetKey;
Klaus Aehligd1f4a162016-10-25 14:51:55 +0000102 private final NestedSet<Cause> rootCauses;
ulfjackd8a93442017-12-22 00:59:05 -0800103 private final ImmutableList<BuildEventId> postedAfter;
ulfjackb6eae772018-05-16 06:06:08 -0700104 private final NestedSet<ArtifactsInOutputGroup> outputs;
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400105 private final NestedSet<Artifact> baselineCoverageArtifacts;
janakr5bd23652018-05-22 17:04:00 -0700106 private final Label aliasLabel;
Klaus Aehlig6f978502016-11-30 12:12:56 +0000107 private final boolean isTest;
janakr5bd23652018-05-22 17:04:00 -0700108 @Nullable private final Long testTimeoutSeconds;
109 @Nullable private final TestProvider.TestParams testParams;
110 private final BuildEvent configurationEvent;
111 private final BuildEventId configEventId;
112 private final Iterable<String> tags;
113 private final ExecutableTargetData executableTargetData;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100114
Klaus Aehlig6f978502016-11-30 12:12:56 +0000115 private TargetCompleteEvent(
janakr60554e42018-03-27 10:26:36 -0700116 ConfiguredTargetAndData targetAndData,
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000117 NestedSet<Cause> rootCauses,
ulfjackb6eae772018-05-16 06:06:08 -0700118 NestedSet<ArtifactsInOutputGroup> outputs,
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000119 boolean isTest) {
Klaus Aehligd1f4a162016-10-25 14:51:55 +0000120 this.rootCauses =
121 (rootCauses == null) ? NestedSetBuilder.<Cause>emptySet(Order.STABLE_ORDER) : rootCauses;
janakr5bd23652018-05-22 17:04:00 -0700122 this.executableTargetData = new ExecutableTargetData(targetAndData);
ulfjackd8a93442017-12-22 00:59:05 -0800123 ImmutableList.Builder<BuildEventId> postedAfterBuilder = ImmutableList.builder();
janakr5bd23652018-05-22 17:04:00 -0700124 this.label = targetAndData.getConfiguredTarget().getLabel();
janakr60554e42018-03-27 10:26:36 -0700125 if (targetAndData.getConfiguredTarget() instanceof AliasConfiguredTarget) {
janakr5bd23652018-05-22 17:04:00 -0700126 this.aliasLabel =
127 ((AliasConfiguredTarget) targetAndData.getConfiguredTarget()).getOriginalLabel();
128 } else {
129 this.aliasLabel = label;
Klaus Aehligd9aa4032018-02-12 01:22:31 -0800130 }
janakr5bd23652018-05-22 17:04:00 -0700131 this.configuredTargetKey =
132 ConfiguredTargetKey.of(
133 targetAndData.getConfiguredTarget(), targetAndData.getConfiguration());
134 postedAfterBuilder.add(BuildEventId.targetConfigured(aliasLabel));
Klaus Aehlig74d716b2016-11-23 12:38:24 +0000135 for (Cause cause : getRootCauses()) {
136 postedAfterBuilder.add(BuildEventId.fromCause(cause));
137 }
138 this.postedAfter = postedAfterBuilder.build();
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000139 this.outputs = outputs;
Klaus Aehlig6f978502016-11-30 12:12:56 +0000140 this.isTest = isTest;
janakr5bd23652018-05-22 17:04:00 -0700141 this.testTimeoutSeconds = isTest ? getTestTimeoutSeconds(targetAndData) : null;
142 BuildConfiguration configuration = targetAndData.getConfiguration();
143 this.configEventId =
144 configuration != null ? configuration.getEventId() : BuildEventId.nullConfigurationId();
145 this.configurationEvent = configuration != null ? configuration.toBuildEvent() : null;
146 this.testParams =
147 isTest
148 ? targetAndData.getConfiguredTarget().getProvider(TestProvider.class).getTestParams()
149 : null;
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400150 InstrumentedFilesProvider instrumentedFilesProvider =
janakr5bd23652018-05-22 17:04:00 -0700151 targetAndData.getConfiguredTarget().getProvider(InstrumentedFilesProvider.class);
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400152 if (instrumentedFilesProvider == null) {
153 this.baselineCoverageArtifacts = null;
154 } else {
155 NestedSet<Artifact> baselineCoverageArtifacts =
156 instrumentedFilesProvider.getBaselineCoverageArtifacts();
157 if (!baselineCoverageArtifacts.isEmpty()) {
158 this.baselineCoverageArtifacts = baselineCoverageArtifacts;
159 } else {
160 this.baselineCoverageArtifacts = null;
161 }
162 }
janakr5bd23652018-05-22 17:04:00 -0700163 // For tags, we are only interested in targets that are rules.
164 if (!(targetAndData.getConfiguredTarget() instanceof RuleConfiguredTarget)) {
165 this.tags = ImmutableList.of();
166 } else {
167 AttributeMap attributes =
168 ConfiguredAttributeMapper.of(
169 (Rule) targetAndData.getTarget(),
170 ((RuleConfiguredTarget) targetAndData.getConfiguredTarget()).getConfigConditions());
171 // Every rule (implicitly) has a "tags" attribute.
172 this.tags = attributes.get("tags", Type.STRING_LIST);
173 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100174 }
175
Klaus Aehlig6f978502016-11-30 12:12:56 +0000176 /** Construct a successful target completion event. */
ulfjackd8a93442017-12-22 00:59:05 -0800177 public static TargetCompleteEvent successfulBuild(
janakr60554e42018-03-27 10:26:36 -0700178 ConfiguredTargetAndData ct, NestedSet<ArtifactsInOutputGroup> outputs) {
179 return new TargetCompleteEvent(ct, null, outputs, false);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100180 }
181
Klaus Aehlig6f978502016-11-30 12:12:56 +0000182 /** Construct a successful target completion event for a target that will be tested. */
mjhalupka14dbe132018-02-13 13:00:52 -0800183 public static TargetCompleteEvent successfulBuildSchedulingTest(
janakr60554e42018-03-27 10:26:36 -0700184 ConfiguredTargetAndData ct, NestedSet<ArtifactsInOutputGroup> outputs) {
185 return new TargetCompleteEvent(ct, null, outputs, true);
Klaus Aehlig6f978502016-11-30 12:12:56 +0000186 }
187
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100188 /**
189 * Construct a target completion event for a failed target, with the given non-empty root causes.
190 */
mjhalupka14dbe132018-02-13 13:00:52 -0800191 public static TargetCompleteEvent createFailed(
janakr60554e42018-03-27 10:26:36 -0700192 ConfiguredTargetAndData ct, NestedSet<Cause> rootCauses) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100193 Preconditions.checkArgument(!Iterables.isEmpty(rootCauses));
ulfjackb6eae772018-05-16 06:06:08 -0700194 return new TargetCompleteEvent(
195 ct, rootCauses, NestedSetBuilder.emptySet(Order.STABLE_ORDER), false);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100196 }
197
janakr5bd23652018-05-22 17:04:00 -0700198 /** Returns the label of the target associated with the event. */
199 public Label getLabel() {
200 return label;
201 }
202
203 public ConfiguredTargetKey getConfiguredTargetKey() {
204 return configuredTargetKey;
205 }
206
207 public ExecutableTargetData getExecutableTargetData() {
208 return executableTargetData;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100209 }
210
mjhalupka14dbe132018-02-13 13:00:52 -0800211 /** Determines whether the target has failed or succeeded. */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100212 public boolean failed() {
213 return !rootCauses.isEmpty();
214 }
215
Klaus Aehligd1f4a162016-10-25 14:51:55 +0000216 /** Get the root causes of the target. May be empty. */
217 public Iterable<Cause> getRootCauses() {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100218 return rootCauses;
219 }
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000220
ulfjackb6eae772018-05-16 06:06:08 -0700221 public Iterable<Artifact> getLegacyFilteredImportantArtifacts() {
222 // TODO(ulfjack): This duplicates code in ArtifactsToBuild.
223 NestedSetBuilder<Artifact> builder = new NestedSetBuilder<>(outputs.getOrder());
224 for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs) {
225 if (artifactsInOutputGroup.areImportant()) {
226 builder.addTransitive(artifactsInOutputGroup.getArtifacts());
227 }
228 }
229 return Iterables.filter(
230 builder.build(),
231 (artifact) -> !artifact.isSourceArtifact() && !artifact.isMiddlemanArtifact());
232 }
233
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000234 @Override
235 public BuildEventId getEventId() {
janakr5bd23652018-05-22 17:04:00 -0700236 return BuildEventId.targetCompleted(aliasLabel, configEventId);
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000237 }
238
239 @Override
240 public Collection<BuildEventId> getChildrenEvents() {
ulfjackd8a93442017-12-22 00:59:05 -0800241 ImmutableList.Builder<BuildEventId> childrenBuilder = ImmutableList.builder();
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000242 for (Cause cause : getRootCauses()) {
243 childrenBuilder.add(BuildEventId.fromCause(cause));
244 }
Klaus Aehlig6f978502016-11-30 12:12:56 +0000245 if (isTest) {
Klaus Aehlig1f452c32017-02-02 10:19:15 +0000246 // For tests, announce all the test actions that will minimally happen (except for
247 // interruption). If after the result of a test action another attempt is necessary,
248 // it will be announced with the action that made the new attempt necessary.
janakr5bd23652018-05-22 17:04:00 -0700249 Label label = getLabel();
250 for (int run = 0; run < Math.max(testParams.getRuns(), 1); run++) {
251 for (int shard = 0; shard < Math.max(testParams.getShards(), 1); shard++) {
252 childrenBuilder.add(BuildEventId.testResult(label, run, shard, configEventId));
Klaus Aehlig1f452c32017-02-02 10:19:15 +0000253 }
254 }
janakr5bd23652018-05-22 17:04:00 -0700255 childrenBuilder.add(BuildEventId.testSummary(label, configEventId));
Klaus Aehlig8d253622016-11-02 17:24:46 +0000256 }
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000257 return childrenBuilder.build();
258 }
259
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400260 // TODO(aehlig): remove as soon as we managed to get rid of the deprecated "important_output"
261 // field.
262 private static void addImportantOutputs(
263 BuildEventStreamProtos.TargetComplete.Builder builder,
ulfjack26e586d2018-05-17 08:42:13 -0700264 BuildEventContext converters,
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400265 Iterable<Artifact> artifacts) {
Googlerf592df92018-02-22 19:04:23 -0800266 addImportantOutputs(builder, Artifact::getRootRelativePathString, converters, artifacts);
267 }
268
269 private static void addImportantOutputs(
270 BuildEventStreamProtos.TargetComplete.Builder builder,
271 Function<Artifact, String> artifactNameFunction,
ulfjack26e586d2018-05-17 08:42:13 -0700272 BuildEventContext converters,
Googlerf592df92018-02-22 19:04:23 -0800273 Iterable<Artifact> artifacts) {
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400274 for (Artifact artifact : artifacts) {
Googlerf592df92018-02-22 19:04:23 -0800275 String name = artifactNameFunction.apply(artifact);
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400276 String uri = converters.pathConverter().apply(artifact.getPath());
tomlufb8332f2018-07-11 12:21:23 -0700277 if (uri != null) {
278 builder.addImportantOutput(File.newBuilder().setName(name).setUri(uri).build());
279 }
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400280 }
281 }
282
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000283 @Override
tomlu2348a752018-07-04 08:55:42 -0700284 public Collection<LocalFile> referencedLocalFiles() {
285 ImmutableList.Builder<LocalFile> builder = ImmutableList.builder();
ulfjack68aa4102018-06-15 01:40:02 -0700286 for (ArtifactsInOutputGroup group : outputs) {
287 if (group.areImportant()) {
288 for (Artifact artifact : group.getArtifacts()) {
tomlu2348a752018-07-04 08:55:42 -0700289 builder.add(
290 new LocalFile(
291 artifact.getPath(),
292 artifact.isSourceArtifact() ? LocalFileType.SOURCE : LocalFileType.OUTPUT));
ulfjack68aa4102018-06-15 01:40:02 -0700293 }
294 }
295 }
ulfjackf0009962018-07-23 01:19:20 -0700296 if (baselineCoverageArtifacts != null) {
297 for (Artifact artifact : baselineCoverageArtifacts) {
298 builder.add(
299 new LocalFile(
300 artifact.getPath(),
301 artifact.isSourceArtifact() ? LocalFileType.SOURCE : LocalFileType.OUTPUT));
302 }
303 }
ulfjack68aa4102018-06-15 01:40:02 -0700304 return builder.build();
305 }
306
307 @Override
ulfjack26e586d2018-05-17 08:42:13 -0700308 public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) {
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000309 BuildEventStreamProtos.TargetComplete.Builder builder =
310 BuildEventStreamProtos.TargetComplete.newBuilder();
311
312 builder.setSuccess(!failed());
313 builder.addAllTag(getTags());
Klaus Aehlig4901d8b2017-04-10 15:13:59 +0000314 builder.addAllOutputGroup(getOutputFilesByGroup(converters.artifactGroupNamer()));
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000315
mjhalupkad7071352018-02-10 08:34:41 -0800316 if (isTest) {
janakr5bd23652018-05-22 17:04:00 -0700317 builder.setTestTimeoutSeconds(testTimeoutSeconds);
mjhalupkad7071352018-02-10 08:34:41 -0800318 }
319
Klaus Aehlig0a6cd622017-04-21 17:09:40 +0200320 // TODO(aehlig): remove direct reporting of artifacts as soon as clients no longer
321 // need it.
ulfjackfbf27562018-05-18 12:46:54 -0700322 if (converters.getOptions().legacyImportantOutputs) {
323 addImportantOutputs(builder, converters, getLegacyFilteredImportantArtifacts());
324 if (baselineCoverageArtifacts != null) {
325 addImportantOutputs(
326 builder, (artifact -> BASELINE_COVERAGE), converters, baselineCoverageArtifacts);
327 }
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400328 }
Klaus Aehlig0a6cd622017-04-21 17:09:40 +0200329
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000330 BuildEventStreamProtos.TargetComplete complete = builder.build();
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +0000331 return GenericBuildEvent.protoChaining(this).setCompleted(complete).build();
332 }
Klaus Aehlig74d716b2016-11-23 12:38:24 +0000333
334 @Override
335 public Collection<BuildEventId> postedAfter() {
336 return postedAfter;
337 }
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000338
Klaus Aehlig4901d8b2017-04-10 15:13:59 +0000339 @Override
340 public Collection<NestedSet<Artifact>> reportedArtifacts() {
341 ImmutableSet.Builder<NestedSet<Artifact>> builder =
342 new ImmutableSet.Builder<NestedSet<Artifact>>();
343 for (ArtifactsInOutputGroup artifactsInGroup : outputs) {
344 builder.add(artifactsInGroup.getArtifacts());
345 }
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400346 if (baselineCoverageArtifacts != null) {
347 builder.add(baselineCoverageArtifacts);
348 }
Klaus Aehlig4901d8b2017-04-10 15:13:59 +0000349 return builder.build();
350 }
351
Klaus Aehlig71c993b2017-05-09 07:49:46 -0400352 @Override
Klaus Aehliga708a022017-07-11 12:54:40 +0200353 public Collection<BuildEvent> getConfigurations() {
janakr5bd23652018-05-22 17:04:00 -0700354 return configurationEvent != null ? ImmutableList.of(configurationEvent) : ImmutableList.of();
Klaus Aehlig71c993b2017-05-09 07:49:46 -0400355 }
356
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000357 private Iterable<String> getTags() {
janakr5bd23652018-05-22 17:04:00 -0700358 return tags;
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000359 }
360
Klaus Aehlig4901d8b2017-04-10 15:13:59 +0000361 private Iterable<OutputGroup> getOutputFilesByGroup(ArtifactGroupNamer namer) {
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000362 ImmutableList.Builder<OutputGroup> groups = ImmutableList.builder();
363 for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs) {
364 OutputGroup.Builder groupBuilder = OutputGroup.newBuilder();
365 groupBuilder.setName(artifactsInOutputGroup.getOutputGroup());
Klaus Aehlig4901d8b2017-04-10 15:13:59 +0000366 groupBuilder.addFileSets(
367 namer.apply(
368 (new NestedSetView<Artifact>(artifactsInOutputGroup.getArtifacts())).identifier()));
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000369 groups.add(groupBuilder.build());
370 }
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400371 if (baselineCoverageArtifacts != null) {
372 groups.add(
373 OutputGroup.newBuilder()
Googlerf592df92018-02-22 19:04:23 -0800374 .setName(BASELINE_COVERAGE)
Klaus Aehligcba24ab2017-09-27 05:14:11 -0400375 .addFileSets(
376 namer.apply(
377 (new NestedSetView<Artifact>(baselineCoverageArtifacts).identifier())))
378 .build());
379 }
Jakob Buchgraberfb646092017-02-27 18:53:25 +0000380 return groups.build();
381 }
Googlere3a0b092018-04-17 07:09:37 -0700382
383 /**
384 * Returns timeout value in seconds that should be used for all test actions under this configured
385 * target. We always use the "categorical timeouts" which are based on the --test_timeout flag. A
386 * rule picks its timeout but ends up with the same effective value as all other rules in that
387 * category and configuration.
388 */
janakr5bd23652018-05-22 17:04:00 -0700389 private static Long getTestTimeoutSeconds(ConfiguredTargetAndData targetAndData) {
Googlere3a0b092018-04-17 07:09:37 -0700390 BuildConfiguration configuration = targetAndData.getConfiguration();
391 Rule associatedRule = targetAndData.getTarget().getAssociatedRule();
392 TestTimeout categoricalTimeout = TestTimeout.getTestTimeout(associatedRule);
393 return configuration.getTestTimeout().get(categoricalTimeout).getSeconds();
394 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100395}