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 | |
| 17 | import com.google.common.collect.ImmutableList; |
| 18 | import com.google.common.collect.ImmutableSet; |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSortedSet; |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Sets; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.ActionGraph; |
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; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 24 | import java.util.Collection; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 25 | import javax.annotation.Nullable; |
| 26 | |
| 27 | /** |
| 28 | * Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner}. |
| 29 | */ |
| 30 | public final 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; |
| 33 | @Nullable private final ImmutableList<ConfiguredTarget> targetsToTest; |
| 34 | private final ImmutableSet<ConfiguredTarget> targetsToSkip; |
| 35 | @Nullable private final String error; |
| 36 | private final ActionGraph actionGraph; |
janakr | ccb7456 | 2018-07-30 10:56:57 -0700 | [diff] [blame] | 37 | private final ArtifactsToOwnerLabels topLevelArtifactsToOwnerLabels; |
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; |
| 41 | private final ImmutableSet<AspectValue> aspects; |
| 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; |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 45 | private final ImmutableSortedSet<String> nonSymlinkedDirectoriesUnderExecRoot; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 46 | |
| 47 | AnalysisResult( |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 48 | BuildConfigurationCollection configurations, |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 49 | ImmutableSet<ConfiguredTarget> targetsToBuild, |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 50 | ImmutableSet<AspectValue> aspects, |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 51 | @Nullable ImmutableList<ConfiguredTarget> targetsToTest, |
| 52 | ImmutableSet<ConfiguredTarget> targetsToSkip, |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 53 | @Nullable String error, |
| 54 | ActionGraph actionGraph, |
janakr | ccb7456 | 2018-07-30 10:56:57 -0700 | [diff] [blame] | 55 | ArtifactsToOwnerLabels topLevelArtifactsToOwnerLabels, |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 56 | ImmutableSet<ConfiguredTarget> parallelTests, |
| 57 | ImmutableSet<ConfiguredTarget> exclusiveTests, |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 58 | TopLevelArtifactContext topLevelContext, |
| 59 | PackageRoots packageRoots, |
| 60 | String workspaceName, |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 61 | Collection<TargetAndConfiguration> topLevelTargetsWithConfigs, |
| 62 | ImmutableSortedSet<String> nonSymlinkedDirectoriesUnderExecRoot) { |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 63 | this.configurations = configurations; |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 64 | this.targetsToBuild = targetsToBuild; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 65 | this.aspects = aspects; |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 66 | this.targetsToTest = targetsToTest; |
| 67 | this.targetsToSkip = targetsToSkip; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 68 | this.error = error; |
| 69 | this.actionGraph = actionGraph; |
janakr | 75bc18a | 2018-07-13 00:52:17 -0700 | [diff] [blame] | 70 | this.topLevelArtifactsToOwnerLabels = topLevelArtifactsToOwnerLabels; |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 71 | this.parallelTests = parallelTests; |
| 72 | this.exclusiveTests = exclusiveTests; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 73 | this.topLevelContext = topLevelContext; |
| 74 | this.packageRoots = packageRoots; |
| 75 | this.workspaceName = workspaceName; |
| 76 | this.topLevelTargetsWithConfigs = topLevelTargetsWithConfigs; |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 77 | this.nonSymlinkedDirectoriesUnderExecRoot = nonSymlinkedDirectoriesUnderExecRoot; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 78 | } |
| 79 | |
ulfjack | 940fbd7 | 2018-06-15 03:23:58 -0700 | [diff] [blame] | 80 | public BuildConfigurationCollection getConfigurationCollection() { |
| 81 | return configurations; |
| 82 | } |
| 83 | |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 84 | /** |
| 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 | /** |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 107 | * 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). |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 109 | */ |
| 110 | @Nullable |
laszlocsomor | 3c8883d | 2019-12-19 05:19:28 -0800 | [diff] [blame] | 111 | public ImmutableList<ConfiguredTarget> getTargetsToTest() { |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 112 | 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 | |
janakr | ccb7456 | 2018-07-30 10:56:57 -0700 | [diff] [blame] | 125 | public ArtifactsToOwnerLabels getTopLevelArtifactsToOwnerLabels() { |
janakr | 75bc18a | 2018-07-13 00:52:17 -0700 | [diff] [blame] | 126 | return topLevelArtifactsToOwnerLabels; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 127 | } |
| 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 | |
ulfjack | 36fbbde | 2018-08-02 05:16:00 -0700 | [diff] [blame] | 163 | public Collection<TargetAndConfiguration> getTopLevelTargetsWithConfigs() { |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 164 | return topLevelTargetsWithConfigs; |
| 165 | } |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 166 | |
| 167 | public ImmutableSortedSet<String> getNonSymlinkedDirectoriesUnderExecRoot() { |
| 168 | return nonSymlinkedDirectoriesUnderExecRoot; |
| 169 | } |
Googler | 2af2aa3 | 2020-01-30 06:45:55 -0800 | [diff] [blame] | 170 | |
| 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 | } |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 193 | } |