ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 1 | // Copyright 2018 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 | |
janakr | f15d08d | 2020-04-22 12:53:03 -0700 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableMap; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 20 | import com.google.devtools.build.lib.actions.ActionGraph; |
jhorvitz | cd477f2 | 2021-05-05 10:18:22 -0700 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.Artifact; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 22 | import com.google.devtools.build.lib.actions.PackageRoots; |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 23 | import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection; |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 24 | import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; |
leba | b52a190 | 2021-09-23 01:35:13 -0700 | [diff] [blame] | 25 | import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 26 | import java.util.Collection; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 27 | import javax.annotation.Nullable; |
| 28 | |
leba | 94b810f | 2021-09-29 01:47:53 -0700 | [diff] [blame] | 29 | /** Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner}. */ |
| 30 | public class AnalysisResult { |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 31 | private final BuildConfigurationCollection configurations; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 32 | private final ImmutableSet<ConfiguredTarget> targetsToBuild; |
leba | 1a47d99 | 2022-04-19 01:35:26 -0700 | [diff] [blame] | 33 | @Nullable private final ImmutableSet<ConfiguredTarget> targetsToTest; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 34 | private final ImmutableSet<ConfiguredTarget> targetsToSkip; |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 35 | @Nullable private final FailureDetail failureDetail; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 36 | private final ActionGraph actionGraph; |
jhorvitz | cd477f2 | 2021-05-05 10:18:22 -0700 | [diff] [blame] | 37 | private final ImmutableSet<Artifact> artifactsToBuild; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 38 | private final ImmutableSet<ConfiguredTarget> parallelTests; |
| 39 | private final ImmutableSet<ConfiguredTarget> exclusiveTests; |
| 40 | @Nullable private final TopLevelArtifactContext topLevelContext; |
janakr | f15d08d | 2020-04-22 12:53:03 -0700 | [diff] [blame] | 41 | private final ImmutableMap<AspectKey, ConfiguredAspect> aspects; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 42 | private final PackageRoots packageRoots; |
| 43 | private final String workspaceName; |
ulfjack | 36fbbde | 2018-08-02 05:16:00 -0700 | [diff] [blame] | 44 | private final Collection<TargetAndConfiguration> topLevelTargetsWithConfigs; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 45 | |
| 46 | AnalysisResult( |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 47 | BuildConfigurationCollection configurations, |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 48 | ImmutableSet<ConfiguredTarget> targetsToBuild, |
janakr | f15d08d | 2020-04-22 12:53:03 -0700 | [diff] [blame] | 49 | ImmutableMap<AspectKey, ConfiguredAspect> aspects, |
leba | 1a47d99 | 2022-04-19 01:35:26 -0700 | [diff] [blame] | 50 | @Nullable ImmutableSet<ConfiguredTarget> targetsToTest, |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 51 | ImmutableSet<ConfiguredTarget> targetsToSkip, |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 52 | @Nullable FailureDetail failureDetail, |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 53 | ActionGraph actionGraph, |
jhorvitz | cd477f2 | 2021-05-05 10:18:22 -0700 | [diff] [blame] | 54 | ImmutableSet<Artifact> artifactsToBuild, |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 55 | ImmutableSet<ConfiguredTarget> parallelTests, |
| 56 | ImmutableSet<ConfiguredTarget> exclusiveTests, |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 57 | TopLevelArtifactContext topLevelContext, |
| 58 | PackageRoots packageRoots, |
| 59 | String workspaceName, |
lberki | 2e008f7 | 2022-05-09 00:36:39 -0700 | [diff] [blame^] | 60 | Collection<TargetAndConfiguration> topLevelTargetsWithConfigs) { |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 61 | this.configurations = configurations; |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 62 | this.targetsToBuild = targetsToBuild; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 63 | this.aspects = aspects; |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 64 | this.targetsToTest = targetsToTest; |
| 65 | this.targetsToSkip = targetsToSkip; |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 66 | this.failureDetail = failureDetail; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 67 | this.actionGraph = actionGraph; |
jhorvitz | cd477f2 | 2021-05-05 10:18:22 -0700 | [diff] [blame] | 68 | this.artifactsToBuild = artifactsToBuild; |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 69 | this.parallelTests = parallelTests; |
| 70 | this.exclusiveTests = exclusiveTests; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 71 | this.topLevelContext = topLevelContext; |
| 72 | this.packageRoots = packageRoots; |
| 73 | this.workspaceName = workspaceName; |
| 74 | this.topLevelTargetsWithConfigs = topLevelTargetsWithConfigs; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 75 | } |
| 76 | |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 77 | public BuildConfigurationCollection getConfigurationCollection() { |
| 78 | return configurations; |
| 79 | } |
| 80 | |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Returns configured targets to build. |
| 83 | */ |
| 84 | public ImmutableSet<ConfiguredTarget> getTargetsToBuild() { |
| 85 | return targetsToBuild; |
| 86 | } |
| 87 | |
| 88 | /** @see PackageRoots */ |
| 89 | public PackageRoots getPackageRoots() { |
| 90 | return packageRoots; |
| 91 | } |
| 92 | |
janakr | f15d08d | 2020-04-22 12:53:03 -0700 | [diff] [blame] | 93 | /** Returns aspects to build. */ |
| 94 | public ImmutableMap<AspectKey, ConfiguredAspect> getAspectsMap() { |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 95 | return aspects; |
| 96 | } |
| 97 | |
| 98 | /** |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 99 | * Returns the configured targets to run as tests, or {@code null} if testing was not requested |
| 100 | * (e.g. "build" command rather than "test" command). |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 101 | */ |
| 102 | @Nullable |
leba | 1a47d99 | 2022-04-19 01:35:26 -0700 | [diff] [blame] | 103 | public ImmutableSet<ConfiguredTarget> getTargetsToTest() { |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 104 | return targetsToTest; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Returns the configured targets that should not be executed because they're not |
| 109 | * platform-compatible with the current build. |
| 110 | * |
| 111 | * <p>For example: tests that aren't intended for the designated CPU. |
| 112 | */ |
| 113 | public ImmutableSet<ConfiguredTarget> getTargetsToSkip() { |
| 114 | return targetsToSkip; |
| 115 | } |
| 116 | |
jhorvitz | cd477f2 | 2021-05-05 10:18:22 -0700 | [diff] [blame] | 117 | public ImmutableSet<Artifact> getArtifactsToBuild() { |
| 118 | return artifactsToBuild; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | public ImmutableSet<ConfiguredTarget> getExclusiveTests() { |
| 122 | return exclusiveTests; |
| 123 | } |
| 124 | |
| 125 | public ImmutableSet<ConfiguredTarget> getParallelTests() { |
| 126 | return parallelTests; |
| 127 | } |
| 128 | |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 129 | /** Returns a {@link FailureDetail}, if any failures occurred. */ |
| 130 | @Nullable |
| 131 | public FailureDetail getFailureDetail() { |
| 132 | return failureDetail; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | public boolean hasError() { |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 136 | return failureDetail != null; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Returns the action graph. |
| 141 | */ |
| 142 | public ActionGraph getActionGraph() { |
| 143 | return actionGraph; |
| 144 | } |
| 145 | |
| 146 | public TopLevelArtifactContext getTopLevelContext() { |
| 147 | return topLevelContext; |
| 148 | } |
| 149 | |
| 150 | public String getWorkspaceName() { |
| 151 | return workspaceName; |
| 152 | } |
| 153 | |
ulfjack | 36fbbde | 2018-08-02 05:16:00 -0700 | [diff] [blame] | 154 | public Collection<TargetAndConfiguration> getTopLevelTargetsWithConfigs() { |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 155 | return topLevelTargetsWithConfigs; |
| 156 | } |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 157 | |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 158 | /** |
| 159 | * Returns an equivalent {@link AnalysisResult}, except with exclusive tests treated as parallel |
| 160 | * tests. |
| 161 | */ |
| 162 | public AnalysisResult withExclusiveTestsAsParallelTests() { |
| 163 | return new AnalysisResult( |
| 164 | configurations, |
| 165 | targetsToBuild, |
| 166 | aspects, |
| 167 | targetsToTest, |
| 168 | targetsToSkip, |
mschaller | 75216c7 | 2020-06-25 16:04:29 -0700 | [diff] [blame] | 169 | failureDetail, |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 170 | actionGraph, |
jhorvitz | cd477f2 | 2021-05-05 10:18:22 -0700 | [diff] [blame] | 171 | artifactsToBuild, |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 172 | Sets.union(parallelTests, exclusiveTests).immutableCopy(), |
| 173 | /*exclusiveTests=*/ ImmutableSet.of(), |
| 174 | topLevelContext, |
| 175 | packageRoots, |
| 176 | workspaceName, |
lberki | 2e008f7 | 2022-05-09 00:36:39 -0700 | [diff] [blame^] | 177 | topLevelTargetsWithConfigs); |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 178 | } |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 179 | } |