Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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 | |
Googler | f592df9 | 2018-02-22 19:04:23 -0800 | [diff] [blame] | 17 | import static com.google.devtools.build.lib.buildeventstream.TestFileNameConstants.BASELINE_COVERAGE; |
| 18 | |
tomlu | a155b53 | 2017-11-08 20:12:47 +0100 | [diff] [blame] | 19 | import com.google.common.base.Preconditions; |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | import com.google.common.collect.Iterables; |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 23 | import com.google.devtools.build.lib.actions.Artifact; |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 24 | import com.google.devtools.build.lib.actions.EventReportingArtifacts; |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 25 | import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup; |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 26 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
gregce | 593f7f9 | 2017-09-19 02:02:21 +0200 | [diff] [blame] | 27 | import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget; |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 28 | import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; |
ulfjack | ab21d18 | 2017-08-10 15:36:14 +0200 | [diff] [blame] | 29 | import com.google.devtools.build.lib.analysis.test.TestProvider; |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 30 | import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; |
Klaus Aehlig | a708a02 | 2017-07-11 12:54:40 +0200 | [diff] [blame] | 31 | import com.google.devtools.build.lib.buildeventstream.BuildEvent; |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType; |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 33 | import com.google.devtools.build.lib.buildeventstream.BuildEventContext; |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 34 | import com.google.devtools.build.lib.buildeventstream.BuildEventId; |
| 35 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; |
Klaus Aehlig | 0a6cd62 | 2017-04-21 17:09:40 +0200 | [diff] [blame] | 36 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.File; |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 37 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.OutputGroup; |
Klaus Aehlig | a708a02 | 2017-07-11 12:54:40 +0200 | [diff] [blame] | 38 | import com.google.devtools.build.lib.buildeventstream.BuildEventWithConfiguration; |
Klaus Aehlig | 74d716b | 2016-11-23 12:38:24 +0000 | [diff] [blame] | 39 | import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 40 | import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; |
Klaus Aehlig | d1f4a16 | 2016-10-25 14:51:55 +0000 | [diff] [blame] | 41 | import com.google.devtools.build.lib.causes.Cause; |
Klaus Aehlig | 1f452c3 | 2017-02-02 10:19:15 +0000 | [diff] [blame] | 42 | import com.google.devtools.build.lib.cmdline.Label; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
| 44 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 45 | import com.google.devtools.build.lib.collect.nestedset.NestedSetView; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 46 | import com.google.devtools.build.lib.collect.nestedset.Order; |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 47 | import com.google.devtools.build.lib.packages.AttributeMap; |
mjhalupka | 14dbe13 | 2018-02-13 13:00:52 -0800 | [diff] [blame] | 48 | import com.google.devtools.build.lib.packages.ConfiguredAttributeMapper; |
| 49 | import com.google.devtools.build.lib.packages.Rule; |
Googler | e3a0b09 | 2018-04-17 07:09:37 -0700 | [diff] [blame] | 50 | import com.google.devtools.build.lib.packages.TestTimeout; |
Klaus Aehlig | ce12973 | 2017-09-29 07:04:24 -0400 | [diff] [blame] | 51 | import com.google.devtools.build.lib.rules.AliasConfiguredTarget; |
janakr | 60554e4 | 2018-03-27 10:26:36 -0700 | [diff] [blame] | 52 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 53 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 54 | import com.google.devtools.build.lib.syntax.Type; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 55 | import com.google.devtools.build.lib.vfs.Path; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 56 | import com.google.devtools.build.skyframe.SkyValue; |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 57 | import java.util.Collection; |
Googler | f592df9 | 2018-02-22 19:04:23 -0800 | [diff] [blame] | 58 | import java.util.function.Function; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 59 | import javax.annotation.Nullable; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 60 | |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 61 | /** This event is fired as soon as a target is either built or fails. */ |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 62 | public final class TargetCompleteEvent |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 63 | implements SkyValue, |
| 64 | BuildEventWithOrderConstraint, |
| 65 | EventReportingArtifacts, |
| 66 | BuildEventWithConfiguration { |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 67 | |
| 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 Aehlig | d1f4a16 | 2016-10-25 14:51:55 +0000 | [diff] [blame] | 102 | private final NestedSet<Cause> rootCauses; |
ulfjack | d8a9344 | 2017-12-22 00:59:05 -0800 | [diff] [blame] | 103 | private final ImmutableList<BuildEventId> postedAfter; |
ulfjack | b6eae77 | 2018-05-16 06:06:08 -0700 | [diff] [blame] | 104 | private final NestedSet<ArtifactsInOutputGroup> outputs; |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 105 | private final NestedSet<Artifact> baselineCoverageArtifacts; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 106 | private final Label aliasLabel; |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 107 | private final boolean isTest; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 108 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 114 | |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 115 | private TargetCompleteEvent( |
janakr | 60554e4 | 2018-03-27 10:26:36 -0700 | [diff] [blame] | 116 | ConfiguredTargetAndData targetAndData, |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 117 | NestedSet<Cause> rootCauses, |
ulfjack | b6eae77 | 2018-05-16 06:06:08 -0700 | [diff] [blame] | 118 | NestedSet<ArtifactsInOutputGroup> outputs, |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 119 | boolean isTest) { |
Klaus Aehlig | d1f4a16 | 2016-10-25 14:51:55 +0000 | [diff] [blame] | 120 | this.rootCauses = |
| 121 | (rootCauses == null) ? NestedSetBuilder.<Cause>emptySet(Order.STABLE_ORDER) : rootCauses; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 122 | this.executableTargetData = new ExecutableTargetData(targetAndData); |
ulfjack | d8a9344 | 2017-12-22 00:59:05 -0800 | [diff] [blame] | 123 | ImmutableList.Builder<BuildEventId> postedAfterBuilder = ImmutableList.builder(); |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 124 | this.label = targetAndData.getConfiguredTarget().getLabel(); |
janakr | 60554e4 | 2018-03-27 10:26:36 -0700 | [diff] [blame] | 125 | if (targetAndData.getConfiguredTarget() instanceof AliasConfiguredTarget) { |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 126 | this.aliasLabel = |
| 127 | ((AliasConfiguredTarget) targetAndData.getConfiguredTarget()).getOriginalLabel(); |
| 128 | } else { |
| 129 | this.aliasLabel = label; |
Klaus Aehlig | d9aa403 | 2018-02-12 01:22:31 -0800 | [diff] [blame] | 130 | } |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 131 | this.configuredTargetKey = |
| 132 | ConfiguredTargetKey.of( |
| 133 | targetAndData.getConfiguredTarget(), targetAndData.getConfiguration()); |
| 134 | postedAfterBuilder.add(BuildEventId.targetConfigured(aliasLabel)); |
Klaus Aehlig | 74d716b | 2016-11-23 12:38:24 +0000 | [diff] [blame] | 135 | for (Cause cause : getRootCauses()) { |
| 136 | postedAfterBuilder.add(BuildEventId.fromCause(cause)); |
| 137 | } |
| 138 | this.postedAfter = postedAfterBuilder.build(); |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 139 | this.outputs = outputs; |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 140 | this.isTest = isTest; |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 141 | 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 Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 150 | InstrumentedFilesProvider instrumentedFilesProvider = |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 151 | targetAndData.getConfiguredTarget().getProvider(InstrumentedFilesProvider.class); |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 152 | 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 | } |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 163 | // 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 176 | /** Construct a successful target completion event. */ |
ulfjack | d8a9344 | 2017-12-22 00:59:05 -0800 | [diff] [blame] | 177 | public static TargetCompleteEvent successfulBuild( |
janakr | 60554e4 | 2018-03-27 10:26:36 -0700 | [diff] [blame] | 178 | ConfiguredTargetAndData ct, NestedSet<ArtifactsInOutputGroup> outputs) { |
| 179 | return new TargetCompleteEvent(ct, null, outputs, false); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 182 | /** Construct a successful target completion event for a target that will be tested. */ |
mjhalupka | 14dbe13 | 2018-02-13 13:00:52 -0800 | [diff] [blame] | 183 | public static TargetCompleteEvent successfulBuildSchedulingTest( |
janakr | 60554e4 | 2018-03-27 10:26:36 -0700 | [diff] [blame] | 184 | ConfiguredTargetAndData ct, NestedSet<ArtifactsInOutputGroup> outputs) { |
| 185 | return new TargetCompleteEvent(ct, null, outputs, true); |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 188 | /** |
| 189 | * Construct a target completion event for a failed target, with the given non-empty root causes. |
| 190 | */ |
mjhalupka | 14dbe13 | 2018-02-13 13:00:52 -0800 | [diff] [blame] | 191 | public static TargetCompleteEvent createFailed( |
janakr | 60554e4 | 2018-03-27 10:26:36 -0700 | [diff] [blame] | 192 | ConfiguredTargetAndData ct, NestedSet<Cause> rootCauses) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 193 | Preconditions.checkArgument(!Iterables.isEmpty(rootCauses)); |
ulfjack | b6eae77 | 2018-05-16 06:06:08 -0700 | [diff] [blame] | 194 | return new TargetCompleteEvent( |
| 195 | ct, rootCauses, NestedSetBuilder.emptySet(Order.STABLE_ORDER), false); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 196 | } |
| 197 | |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 198 | /** 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 209 | } |
| 210 | |
mjhalupka | 14dbe13 | 2018-02-13 13:00:52 -0800 | [diff] [blame] | 211 | /** Determines whether the target has failed or succeeded. */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 212 | public boolean failed() { |
| 213 | return !rootCauses.isEmpty(); |
| 214 | } |
| 215 | |
Klaus Aehlig | d1f4a16 | 2016-10-25 14:51:55 +0000 | [diff] [blame] | 216 | /** Get the root causes of the target. May be empty. */ |
| 217 | public Iterable<Cause> getRootCauses() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 218 | return rootCauses; |
| 219 | } |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 220 | |
ulfjack | b6eae77 | 2018-05-16 06:06:08 -0700 | [diff] [blame] | 221 | 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 Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 234 | @Override |
| 235 | public BuildEventId getEventId() { |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 236 | return BuildEventId.targetCompleted(aliasLabel, configEventId); |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public Collection<BuildEventId> getChildrenEvents() { |
ulfjack | d8a9344 | 2017-12-22 00:59:05 -0800 | [diff] [blame] | 241 | ImmutableList.Builder<BuildEventId> childrenBuilder = ImmutableList.builder(); |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 242 | for (Cause cause : getRootCauses()) { |
| 243 | childrenBuilder.add(BuildEventId.fromCause(cause)); |
| 244 | } |
Klaus Aehlig | 6f97850 | 2016-11-30 12:12:56 +0000 | [diff] [blame] | 245 | if (isTest) { |
Klaus Aehlig | 1f452c3 | 2017-02-02 10:19:15 +0000 | [diff] [blame] | 246 | // 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. |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 249 | 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 Aehlig | 1f452c3 | 2017-02-02 10:19:15 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 255 | childrenBuilder.add(BuildEventId.testSummary(label, configEventId)); |
Klaus Aehlig | 8d25362 | 2016-11-02 17:24:46 +0000 | [diff] [blame] | 256 | } |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 257 | return childrenBuilder.build(); |
| 258 | } |
| 259 | |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 260 | // 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, |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 264 | BuildEventContext converters, |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 265 | Iterable<Artifact> artifacts) { |
Googler | f592df9 | 2018-02-22 19:04:23 -0800 | [diff] [blame] | 266 | addImportantOutputs(builder, Artifact::getRootRelativePathString, converters, artifacts); |
| 267 | } |
| 268 | |
| 269 | private static void addImportantOutputs( |
| 270 | BuildEventStreamProtos.TargetComplete.Builder builder, |
| 271 | Function<Artifact, String> artifactNameFunction, |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 272 | BuildEventContext converters, |
Googler | f592df9 | 2018-02-22 19:04:23 -0800 | [diff] [blame] | 273 | Iterable<Artifact> artifacts) { |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 274 | for (Artifact artifact : artifacts) { |
Googler | f592df9 | 2018-02-22 19:04:23 -0800 | [diff] [blame] | 275 | String name = artifactNameFunction.apply(artifact); |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 276 | String uri = converters.pathConverter().apply(artifact.getPath()); |
tomlu | fb8332f | 2018-07-11 12:21:23 -0700 | [diff] [blame] | 277 | if (uri != null) { |
| 278 | builder.addImportantOutput(File.newBuilder().setName(name).setUri(uri).build()); |
| 279 | } |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 283 | @Override |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 284 | public Collection<LocalFile> referencedLocalFiles() { |
| 285 | ImmutableList.Builder<LocalFile> builder = ImmutableList.builder(); |
ulfjack | 68aa410 | 2018-06-15 01:40:02 -0700 | [diff] [blame] | 286 | for (ArtifactsInOutputGroup group : outputs) { |
| 287 | if (group.areImportant()) { |
| 288 | for (Artifact artifact : group.getArtifacts()) { |
tomlu | 2348a75 | 2018-07-04 08:55:42 -0700 | [diff] [blame] | 289 | builder.add( |
| 290 | new LocalFile( |
| 291 | artifact.getPath(), |
| 292 | artifact.isSourceArtifact() ? LocalFileType.SOURCE : LocalFileType.OUTPUT)); |
ulfjack | 68aa410 | 2018-06-15 01:40:02 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
ulfjack | f000996 | 2018-07-23 01:19:20 -0700 | [diff] [blame] | 296 | 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 | } |
ulfjack | 68aa410 | 2018-06-15 01:40:02 -0700 | [diff] [blame] | 304 | return builder.build(); |
| 305 | } |
| 306 | |
| 307 | @Override |
ulfjack | 26e586d | 2018-05-17 08:42:13 -0700 | [diff] [blame] | 308 | public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) { |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 309 | BuildEventStreamProtos.TargetComplete.Builder builder = |
| 310 | BuildEventStreamProtos.TargetComplete.newBuilder(); |
| 311 | |
| 312 | builder.setSuccess(!failed()); |
| 313 | builder.addAllTag(getTags()); |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 314 | builder.addAllOutputGroup(getOutputFilesByGroup(converters.artifactGroupNamer())); |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 315 | |
mjhalupka | d707135 | 2018-02-10 08:34:41 -0800 | [diff] [blame] | 316 | if (isTest) { |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 317 | builder.setTestTimeoutSeconds(testTimeoutSeconds); |
mjhalupka | d707135 | 2018-02-10 08:34:41 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Klaus Aehlig | 0a6cd62 | 2017-04-21 17:09:40 +0200 | [diff] [blame] | 320 | // TODO(aehlig): remove direct reporting of artifacts as soon as clients no longer |
| 321 | // need it. |
ulfjack | fbf2756 | 2018-05-18 12:46:54 -0700 | [diff] [blame] | 322 | if (converters.getOptions().legacyImportantOutputs) { |
| 323 | addImportantOutputs(builder, converters, getLegacyFilteredImportantArtifacts()); |
| 324 | if (baselineCoverageArtifacts != null) { |
| 325 | addImportantOutputs( |
| 326 | builder, (artifact -> BASELINE_COVERAGE), converters, baselineCoverageArtifacts); |
| 327 | } |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 328 | } |
Klaus Aehlig | 0a6cd62 | 2017-04-21 17:09:40 +0200 | [diff] [blame] | 329 | |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 330 | BuildEventStreamProtos.TargetComplete complete = builder.build(); |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 331 | return GenericBuildEvent.protoChaining(this).setCompleted(complete).build(); |
| 332 | } |
Klaus Aehlig | 74d716b | 2016-11-23 12:38:24 +0000 | [diff] [blame] | 333 | |
| 334 | @Override |
| 335 | public Collection<BuildEventId> postedAfter() { |
| 336 | return postedAfter; |
| 337 | } |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 338 | |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 339 | @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 Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 346 | if (baselineCoverageArtifacts != null) { |
| 347 | builder.add(baselineCoverageArtifacts); |
| 348 | } |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 349 | return builder.build(); |
| 350 | } |
| 351 | |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 352 | @Override |
Klaus Aehlig | a708a02 | 2017-07-11 12:54:40 +0200 | [diff] [blame] | 353 | public Collection<BuildEvent> getConfigurations() { |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 354 | return configurationEvent != null ? ImmutableList.of(configurationEvent) : ImmutableList.of(); |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 357 | private Iterable<String> getTags() { |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 358 | return tags; |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 361 | private Iterable<OutputGroup> getOutputFilesByGroup(ArtifactGroupNamer namer) { |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 362 | ImmutableList.Builder<OutputGroup> groups = ImmutableList.builder(); |
| 363 | for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs) { |
| 364 | OutputGroup.Builder groupBuilder = OutputGroup.newBuilder(); |
| 365 | groupBuilder.setName(artifactsInOutputGroup.getOutputGroup()); |
Klaus Aehlig | 4901d8b | 2017-04-10 15:13:59 +0000 | [diff] [blame] | 366 | groupBuilder.addFileSets( |
| 367 | namer.apply( |
| 368 | (new NestedSetView<Artifact>(artifactsInOutputGroup.getArtifacts())).identifier())); |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 369 | groups.add(groupBuilder.build()); |
| 370 | } |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 371 | if (baselineCoverageArtifacts != null) { |
| 372 | groups.add( |
| 373 | OutputGroup.newBuilder() |
Googler | f592df9 | 2018-02-22 19:04:23 -0800 | [diff] [blame] | 374 | .setName(BASELINE_COVERAGE) |
Klaus Aehlig | cba24ab | 2017-09-27 05:14:11 -0400 | [diff] [blame] | 375 | .addFileSets( |
| 376 | namer.apply( |
| 377 | (new NestedSetView<Artifact>(baselineCoverageArtifacts).identifier()))) |
| 378 | .build()); |
| 379 | } |
Jakob Buchgraber | fb64609 | 2017-02-27 18:53:25 +0000 | [diff] [blame] | 380 | return groups.build(); |
| 381 | } |
Googler | e3a0b09 | 2018-04-17 07:09:37 -0700 | [diff] [blame] | 382 | |
| 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 | */ |
janakr | 5bd2365 | 2018-05-22 17:04:00 -0700 | [diff] [blame] | 389 | private static Long getTestTimeoutSeconds(ConfiguredTargetAndData targetAndData) { |
Googler | e3a0b09 | 2018-04-17 07:09:37 -0700 | [diff] [blame] | 390 | 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 395 | } |