blob: 60edd8f600d07b59a096c08c8e3e2dfeda5946d1 [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
17import com.google.common.collect.ImmutableList;
18import com.google.common.collect.ImmutableSet;
ichern121933e2020-01-27 02:08:19 -080019import com.google.common.collect.ImmutableSortedSet;
Googler2af2aa32020-01-30 06:45:55 -080020import com.google.common.collect.Sets;
ulfjackc23bdac2018-06-13 03:06:16 -070021import com.google.devtools.build.lib.actions.ActionGraph;
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;
ulfjackc23bdac2018-06-13 03:06:16 -070024import java.util.Collection;
ulfjackc23bdac2018-06-13 03:06:16 -070025import javax.annotation.Nullable;
26
27/**
28 * Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner}.
29 */
30public final 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;
33 @Nullable private final ImmutableList<ConfiguredTarget> targetsToTest;
34 private final ImmutableSet<ConfiguredTarget> targetsToSkip;
35 @Nullable private final String error;
36 private final ActionGraph actionGraph;
janakrccb74562018-07-30 10:56:57 -070037 private final ArtifactsToOwnerLabels topLevelArtifactsToOwnerLabels;
ulfjackc23bdac2018-06-13 03:06:16 -070038 private final ImmutableSet<ConfiguredTarget> parallelTests;
39 private final ImmutableSet<ConfiguredTarget> exclusiveTests;
40 @Nullable private final TopLevelArtifactContext topLevelContext;
41 private final ImmutableSet<AspectValue> aspects;
42 private final PackageRoots packageRoots;
43 private final String workspaceName;
ulfjack36fbbde2018-08-02 05:16:00 -070044 private final Collection<TargetAndConfiguration> topLevelTargetsWithConfigs;
ichern121933e2020-01-27 02:08:19 -080045 private final ImmutableSortedSet<String> nonSymlinkedDirectoriesUnderExecRoot;
ulfjackc23bdac2018-06-13 03:06:16 -070046
47 AnalysisResult(
ulfjack940fbd72018-06-15 03:23:58 -070048 BuildConfigurationCollection configurations,
laszlocsomor3c8883d2019-12-19 05:19:28 -080049 ImmutableSet<ConfiguredTarget> targetsToBuild,
ulfjackc23bdac2018-06-13 03:06:16 -070050 ImmutableSet<AspectValue> aspects,
laszlocsomor3c8883d2019-12-19 05:19:28 -080051 @Nullable ImmutableList<ConfiguredTarget> targetsToTest,
52 ImmutableSet<ConfiguredTarget> targetsToSkip,
ulfjackc23bdac2018-06-13 03:06:16 -070053 @Nullable String error,
54 ActionGraph actionGraph,
janakrccb74562018-07-30 10:56:57 -070055 ArtifactsToOwnerLabels topLevelArtifactsToOwnerLabels,
laszlocsomor3c8883d2019-12-19 05:19:28 -080056 ImmutableSet<ConfiguredTarget> parallelTests,
57 ImmutableSet<ConfiguredTarget> exclusiveTests,
ulfjackc23bdac2018-06-13 03:06:16 -070058 TopLevelArtifactContext topLevelContext,
59 PackageRoots packageRoots,
60 String workspaceName,
ichern121933e2020-01-27 02:08:19 -080061 Collection<TargetAndConfiguration> topLevelTargetsWithConfigs,
62 ImmutableSortedSet<String> nonSymlinkedDirectoriesUnderExecRoot) {
ulfjack940fbd72018-06-15 03:23:58 -070063 this.configurations = configurations;
laszlocsomor3c8883d2019-12-19 05:19:28 -080064 this.targetsToBuild = targetsToBuild;
ulfjackc23bdac2018-06-13 03:06:16 -070065 this.aspects = aspects;
laszlocsomor3c8883d2019-12-19 05:19:28 -080066 this.targetsToTest = targetsToTest;
67 this.targetsToSkip = targetsToSkip;
ulfjackc23bdac2018-06-13 03:06:16 -070068 this.error = error;
69 this.actionGraph = actionGraph;
janakr75bc18a2018-07-13 00:52:17 -070070 this.topLevelArtifactsToOwnerLabels = topLevelArtifactsToOwnerLabels;
laszlocsomor3c8883d2019-12-19 05:19:28 -080071 this.parallelTests = parallelTests;
72 this.exclusiveTests = exclusiveTests;
ulfjackc23bdac2018-06-13 03:06:16 -070073 this.topLevelContext = topLevelContext;
74 this.packageRoots = packageRoots;
75 this.workspaceName = workspaceName;
76 this.topLevelTargetsWithConfigs = topLevelTargetsWithConfigs;
ichern121933e2020-01-27 02:08:19 -080077 this.nonSymlinkedDirectoriesUnderExecRoot = nonSymlinkedDirectoriesUnderExecRoot;
ulfjackc23bdac2018-06-13 03:06:16 -070078 }
79
ulfjack940fbd72018-06-15 03:23:58 -070080 public BuildConfigurationCollection getConfigurationCollection() {
81 return configurations;
82 }
83
ulfjackc23bdac2018-06-13 03:06:16 -070084 /**
85 * Returns configured targets to build.
86 */
87 public ImmutableSet<ConfiguredTarget> getTargetsToBuild() {
88 return targetsToBuild;
89 }
90
91 /** @see PackageRoots */
92 public PackageRoots getPackageRoots() {
93 return packageRoots;
94 }
95
96 /**
97 * Returns aspects of configured targets to build.
98 *
99 * <p>If this list is empty, build the targets returned by {@code getTargetsToBuild()}.
100 * Otherwise, only build these aspects of the targets returned by {@code getTargetsToBuild()}.
101 */
102 public ImmutableSet<AspectValue> getAspects() {
103 return aspects;
104 }
105
106 /**
laszlocsomor3c8883d2019-12-19 05:19:28 -0800107 * Returns the configured targets to run as tests, or {@code null} if testing was not requested
108 * (e.g. "build" command rather than "test" command).
ulfjackc23bdac2018-06-13 03:06:16 -0700109 */
110 @Nullable
laszlocsomor3c8883d2019-12-19 05:19:28 -0800111 public ImmutableList<ConfiguredTarget> getTargetsToTest() {
ulfjackc23bdac2018-06-13 03:06:16 -0700112 return targetsToTest;
113 }
114
115 /**
116 * Returns the configured targets that should not be executed because they're not
117 * platform-compatible with the current build.
118 *
119 * <p>For example: tests that aren't intended for the designated CPU.
120 */
121 public ImmutableSet<ConfiguredTarget> getTargetsToSkip() {
122 return targetsToSkip;
123 }
124
janakrccb74562018-07-30 10:56:57 -0700125 public ArtifactsToOwnerLabels getTopLevelArtifactsToOwnerLabels() {
janakr75bc18a2018-07-13 00:52:17 -0700126 return topLevelArtifactsToOwnerLabels;
ulfjackc23bdac2018-06-13 03:06:16 -0700127 }
128
129 public ImmutableSet<ConfiguredTarget> getExclusiveTests() {
130 return exclusiveTests;
131 }
132
133 public ImmutableSet<ConfiguredTarget> getParallelTests() {
134 return parallelTests;
135 }
136
137 /**
138 * Returns an error description (if any).
139 */
140 @Nullable public String getError() {
141 return error;
142 }
143
144 public boolean hasError() {
145 return error != null;
146 }
147
148 /**
149 * Returns the action graph.
150 */
151 public ActionGraph getActionGraph() {
152 return actionGraph;
153 }
154
155 public TopLevelArtifactContext getTopLevelContext() {
156 return topLevelContext;
157 }
158
159 public String getWorkspaceName() {
160 return workspaceName;
161 }
162
ulfjack36fbbde2018-08-02 05:16:00 -0700163 public Collection<TargetAndConfiguration> getTopLevelTargetsWithConfigs() {
ulfjackc23bdac2018-06-13 03:06:16 -0700164 return topLevelTargetsWithConfigs;
165 }
ichern121933e2020-01-27 02:08:19 -0800166
167 public ImmutableSortedSet<String> getNonSymlinkedDirectoriesUnderExecRoot() {
168 return nonSymlinkedDirectoriesUnderExecRoot;
169 }
Googler2af2aa32020-01-30 06:45:55 -0800170
171 /**
172 * Returns an equivalent {@link AnalysisResult}, except with exclusive tests treated as parallel
173 * tests.
174 */
175 public AnalysisResult withExclusiveTestsAsParallelTests() {
176 return new AnalysisResult(
177 configurations,
178 targetsToBuild,
179 aspects,
180 targetsToTest,
181 targetsToSkip,
182 error,
183 actionGraph,
184 topLevelArtifactsToOwnerLabels,
185 Sets.union(parallelTests, exclusiveTests).immutableCopy(),
186 /*exclusiveTests=*/ ImmutableSet.of(),
187 topLevelContext,
188 packageRoots,
189 workspaceName,
190 topLevelTargetsWithConfigs,
191 nonSymlinkedDirectoriesUnderExecRoot);
192 }
ulfjackc23bdac2018-06-13 03:06:16 -0700193}