blob: 5b3c0c0dce742a528164f23209cf35ac2ff2fda9 [file] [log] [blame]
ulfjackc23bdac2018-06-13 03:06:16 -07001// 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
15package com.google.devtools.build.lib.analysis;
16
janakrf15d08d2020-04-22 12:53:03 -070017import com.google.common.collect.ImmutableMap;
ulfjackc23bdac2018-06-13 03:06:16 -070018import com.google.common.collect.ImmutableSet;
Googler2af2aa32020-01-30 06:45:55 -080019import com.google.common.collect.Sets;
ulfjackc23bdac2018-06-13 03:06:16 -070020import com.google.devtools.build.lib.actions.ActionGraph;
jhorvitzcd477f22021-05-05 10:18:22 -070021import com.google.devtools.build.lib.actions.Artifact;
ulfjackc23bdac2018-06-13 03:06:16 -070022import com.google.devtools.build.lib.actions.PackageRoots;
ulfjack940fbd72018-06-15 03:23:58 -070023import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
mschaller75216c72020-06-25 16:04:29 -070024import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
lebab52a1902021-09-23 01:35:13 -070025import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey;
ulfjackc23bdac2018-06-13 03:06:16 -070026import java.util.Collection;
ulfjackc23bdac2018-06-13 03:06:16 -070027import javax.annotation.Nullable;
28
leba94b810f2021-09-29 01:47:53 -070029/** Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner}. */
30public class AnalysisResult {
ulfjack940fbd72018-06-15 03:23:58 -070031 private final BuildConfigurationCollection configurations;
ulfjackc23bdac2018-06-13 03:06:16 -070032 private final ImmutableSet<ConfiguredTarget> targetsToBuild;
leba1a47d992022-04-19 01:35:26 -070033 @Nullable private final ImmutableSet<ConfiguredTarget> targetsToTest;
ulfjackc23bdac2018-06-13 03:06:16 -070034 private final ImmutableSet<ConfiguredTarget> targetsToSkip;
mschaller75216c72020-06-25 16:04:29 -070035 @Nullable private final FailureDetail failureDetail;
ulfjackc23bdac2018-06-13 03:06:16 -070036 private final ActionGraph actionGraph;
jhorvitzcd477f22021-05-05 10:18:22 -070037 private final ImmutableSet<Artifact> artifactsToBuild;
ulfjackc23bdac2018-06-13 03:06:16 -070038 private final ImmutableSet<ConfiguredTarget> parallelTests;
39 private final ImmutableSet<ConfiguredTarget> exclusiveTests;
40 @Nullable private final TopLevelArtifactContext topLevelContext;
janakrf15d08d2020-04-22 12:53:03 -070041 private final ImmutableMap<AspectKey, ConfiguredAspect> aspects;
ulfjackc23bdac2018-06-13 03:06:16 -070042 private final PackageRoots packageRoots;
43 private final String workspaceName;
ulfjack36fbbde2018-08-02 05:16:00 -070044 private final Collection<TargetAndConfiguration> topLevelTargetsWithConfigs;
ulfjackc23bdac2018-06-13 03:06:16 -070045
46 AnalysisResult(
ulfjack940fbd72018-06-15 03:23:58 -070047 BuildConfigurationCollection configurations,
laszlocsomor3c8883d2019-12-19 05:19:28 -080048 ImmutableSet<ConfiguredTarget> targetsToBuild,
janakrf15d08d2020-04-22 12:53:03 -070049 ImmutableMap<AspectKey, ConfiguredAspect> aspects,
leba1a47d992022-04-19 01:35:26 -070050 @Nullable ImmutableSet<ConfiguredTarget> targetsToTest,
laszlocsomor3c8883d2019-12-19 05:19:28 -080051 ImmutableSet<ConfiguredTarget> targetsToSkip,
mschaller75216c72020-06-25 16:04:29 -070052 @Nullable FailureDetail failureDetail,
ulfjackc23bdac2018-06-13 03:06:16 -070053 ActionGraph actionGraph,
jhorvitzcd477f22021-05-05 10:18:22 -070054 ImmutableSet<Artifact> artifactsToBuild,
laszlocsomor3c8883d2019-12-19 05:19:28 -080055 ImmutableSet<ConfiguredTarget> parallelTests,
56 ImmutableSet<ConfiguredTarget> exclusiveTests,
ulfjackc23bdac2018-06-13 03:06:16 -070057 TopLevelArtifactContext topLevelContext,
58 PackageRoots packageRoots,
59 String workspaceName,
lberki2e008f72022-05-09 00:36:39 -070060 Collection<TargetAndConfiguration> topLevelTargetsWithConfigs) {
ulfjack940fbd72018-06-15 03:23:58 -070061 this.configurations = configurations;
laszlocsomor3c8883d2019-12-19 05:19:28 -080062 this.targetsToBuild = targetsToBuild;
ulfjackc23bdac2018-06-13 03:06:16 -070063 this.aspects = aspects;
laszlocsomor3c8883d2019-12-19 05:19:28 -080064 this.targetsToTest = targetsToTest;
65 this.targetsToSkip = targetsToSkip;
mschaller75216c72020-06-25 16:04:29 -070066 this.failureDetail = failureDetail;
ulfjackc23bdac2018-06-13 03:06:16 -070067 this.actionGraph = actionGraph;
jhorvitzcd477f22021-05-05 10:18:22 -070068 this.artifactsToBuild = artifactsToBuild;
laszlocsomor3c8883d2019-12-19 05:19:28 -080069 this.parallelTests = parallelTests;
70 this.exclusiveTests = exclusiveTests;
ulfjackc23bdac2018-06-13 03:06:16 -070071 this.topLevelContext = topLevelContext;
72 this.packageRoots = packageRoots;
73 this.workspaceName = workspaceName;
74 this.topLevelTargetsWithConfigs = topLevelTargetsWithConfigs;
ulfjackc23bdac2018-06-13 03:06:16 -070075 }
76
ulfjack940fbd72018-06-15 03:23:58 -070077 public BuildConfigurationCollection getConfigurationCollection() {
78 return configurations;
79 }
80
ulfjackc23bdac2018-06-13 03:06:16 -070081 /**
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
janakrf15d08d2020-04-22 12:53:03 -070093 /** Returns aspects to build. */
94 public ImmutableMap<AspectKey, ConfiguredAspect> getAspectsMap() {
ulfjackc23bdac2018-06-13 03:06:16 -070095 return aspects;
96 }
97
98 /**
laszlocsomor3c8883d2019-12-19 05:19:28 -080099 * 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).
ulfjackc23bdac2018-06-13 03:06:16 -0700101 */
102 @Nullable
leba1a47d992022-04-19 01:35:26 -0700103 public ImmutableSet<ConfiguredTarget> getTargetsToTest() {
ulfjackc23bdac2018-06-13 03:06:16 -0700104 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
jhorvitzcd477f22021-05-05 10:18:22 -0700117 public ImmutableSet<Artifact> getArtifactsToBuild() {
118 return artifactsToBuild;
ulfjackc23bdac2018-06-13 03:06:16 -0700119 }
120
121 public ImmutableSet<ConfiguredTarget> getExclusiveTests() {
122 return exclusiveTests;
123 }
124
125 public ImmutableSet<ConfiguredTarget> getParallelTests() {
126 return parallelTests;
127 }
128
mschaller75216c72020-06-25 16:04:29 -0700129 /** Returns a {@link FailureDetail}, if any failures occurred. */
130 @Nullable
131 public FailureDetail getFailureDetail() {
132 return failureDetail;
ulfjackc23bdac2018-06-13 03:06:16 -0700133 }
134
135 public boolean hasError() {
mschaller75216c72020-06-25 16:04:29 -0700136 return failureDetail != null;
ulfjackc23bdac2018-06-13 03:06:16 -0700137 }
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
ulfjack36fbbde2018-08-02 05:16:00 -0700154 public Collection<TargetAndConfiguration> getTopLevelTargetsWithConfigs() {
ulfjackc23bdac2018-06-13 03:06:16 -0700155 return topLevelTargetsWithConfigs;
156 }
ichern121933e2020-01-27 02:08:19 -0800157
Googler2af2aa32020-01-30 06:45:55 -0800158 /**
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,
mschaller75216c72020-06-25 16:04:29 -0700169 failureDetail,
Googler2af2aa32020-01-30 06:45:55 -0800170 actionGraph,
jhorvitzcd477f22021-05-05 10:18:22 -0700171 artifactsToBuild,
Googler2af2aa32020-01-30 06:45:55 -0800172 Sets.union(parallelTests, exclusiveTests).immutableCopy(),
173 /*exclusiveTests=*/ ImmutableSet.of(),
174 topLevelContext,
175 packageRoots,
176 workspaceName,
lberki2e008f72022-05-09 00:36:39 -0700177 topLevelTargetsWithConfigs);
Googler2af2aa32020-01-30 06:45:55 -0800178 }
ulfjackc23bdac2018-06-13 03:06:16 -0700179}