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 | |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 17 | import static com.google.common.collect.Iterables.concat; |
| 18 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 19 | import com.google.common.annotations.VisibleForTesting; |
| 20 | import com.google.common.base.Function; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 21 | import com.google.common.base.Predicate; |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 22 | import com.google.common.collect.ArrayListMultimap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.common.collect.ImmutableList; |
| 24 | import com.google.common.collect.ImmutableMap; |
Greg Estren | 0db9b11 | 2016-12-05 21:55:54 +0000 | [diff] [blame] | 25 | import com.google.common.collect.ImmutableMultimap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 26 | import com.google.common.collect.ImmutableSet; |
| 27 | import com.google.common.collect.Iterables; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.common.collect.Lists; |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 29 | import com.google.common.collect.Multimap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | import com.google.common.collect.Sets; |
| 31 | import com.google.common.eventbus.EventBus; |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 32 | import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | import com.google.devtools.build.lib.actions.ActionGraph; |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 34 | import com.google.devtools.build.lib.actions.ActionLookupValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 35 | import com.google.devtools.build.lib.actions.Artifact; |
| 36 | import com.google.devtools.build.lib.actions.ArtifactFactory; |
Eric Fellheimer | 9c1e12f | 2015-08-06 20:23:55 +0000 | [diff] [blame] | 37 | import com.google.devtools.build.lib.actions.ArtifactOwner; |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 38 | import com.google.devtools.build.lib.actions.PackageRoots; |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 39 | import com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 40 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
| 41 | import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection; |
Greg Estren | 373e3e2 | 2016-08-09 22:36:51 +0000 | [diff] [blame] | 42 | import com.google.devtools.build.lib.analysis.config.BuildOptions; |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 43 | import com.google.devtools.build.lib.analysis.config.ComposingSplitTransition; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 44 | import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider; |
gregce | 692f763f | 2017-07-06 22:51:30 -0400 | [diff] [blame] | 45 | import com.google.devtools.build.lib.analysis.config.DynamicTransitionMapper; |
Greg Estren | 373e3e2 | 2016-08-09 22:36:51 +0000 | [diff] [blame] | 46 | import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; |
gregce | 692f763f | 2017-07-06 22:51:30 -0400 | [diff] [blame] | 47 | import com.google.devtools.build.lib.analysis.config.PatchTransition; |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 48 | import com.google.devtools.build.lib.analysis.constraints.TopLevelConstraintSemantics; |
ulfjack | ab21d18 | 2017-08-10 15:36:14 +0200 | [diff] [blame] | 49 | import com.google.devtools.build.lib.analysis.test.CoverageReportActionFactory; |
| 50 | import com.google.devtools.build.lib.analysis.test.CoverageReportActionFactory.CoverageReportActionsWrapper; |
| 51 | import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 52 | import com.google.devtools.build.lib.cmdline.Label; |
Lukacs Berki | 6916be2 | 2015-02-19 13:36:06 +0000 | [diff] [blame] | 53 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 55 | import com.google.devtools.build.lib.collect.nestedset.Order; |
| 56 | import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 57 | import com.google.devtools.build.lib.events.Event; |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 58 | import com.google.devtools.build.lib.events.ExtendedEventHandler; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 59 | import com.google.devtools.build.lib.events.StoredEventHandler; |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 60 | import com.google.devtools.build.lib.packages.AspectClass; |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 61 | import com.google.devtools.build.lib.packages.AspectDescriptor; |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 62 | import com.google.devtools.build.lib.packages.AspectParameters; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | import com.google.devtools.build.lib.packages.Attribute; |
Cal Peyser | 8a638d5 | 2017-03-24 15:44:24 +0000 | [diff] [blame] | 64 | import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition; |
| 65 | import com.google.devtools.build.lib.packages.Attribute.Transition; |
Lukacs Berki | ffa73ad | 2015-09-18 11:40:12 +0000 | [diff] [blame] | 66 | import com.google.devtools.build.lib.packages.BuildType; |
Dmitry Lomov | 8ff0645 | 2015-10-21 19:16:30 +0000 | [diff] [blame] | 67 | import com.google.devtools.build.lib.packages.NativeAspectClass; |
Cal Peyser | 8a638d5 | 2017-03-24 15:44:24 +0000 | [diff] [blame] | 68 | import com.google.devtools.build.lib.packages.NoSuchPackageException; |
| 69 | import com.google.devtools.build.lib.packages.NoSuchTargetException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 70 | import com.google.devtools.build.lib.packages.NoSuchThingException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 71 | import com.google.devtools.build.lib.packages.PackageSpecification; |
| 72 | import com.google.devtools.build.lib.packages.RawAttributeMapper; |
| 73 | import com.google.devtools.build.lib.packages.Rule; |
Michael Staib | 2a67520 | 2017-03-20 18:06:48 +0000 | [diff] [blame] | 74 | import com.google.devtools.build.lib.packages.RuleTransitionFactory; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 75 | import com.google.devtools.build.lib.packages.Target; |
| 76 | import com.google.devtools.build.lib.packages.TargetUtils; |
Ulf Adams | d809936 | 2015-11-02 14:56:46 +0000 | [diff] [blame] | 77 | import com.google.devtools.build.lib.pkgcache.LoadingResult; |
nharmata | c4335cf | 2017-07-18 21:39:13 +0200 | [diff] [blame] | 78 | import com.google.devtools.build.lib.pkgcache.PackageManager.PackageManagerStatistics; |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 79 | import com.google.devtools.build.lib.skyframe.AspectValue; |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 80 | import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey; |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 81 | import com.google.devtools.build.lib.skyframe.AspectValue.AspectValueKey; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 82 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 83 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 84 | import com.google.devtools.build.lib.skyframe.CoverageReportValue; |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 85 | import com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 86 | import com.google.devtools.build.lib.skyframe.SkyframeBuildView; |
| 87 | import com.google.devtools.build.lib.skyframe.SkyframeExecutor; |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 88 | import com.google.devtools.build.lib.skyframe.ToolchainUtil.ToolchainContextException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 89 | import com.google.devtools.build.lib.syntax.EvalException; |
Dmitry Lomov | 51aafc1 | 2016-11-18 14:02:54 +0000 | [diff] [blame] | 90 | import com.google.devtools.build.lib.syntax.SkylarkImport; |
| 91 | import com.google.devtools.build.lib.syntax.SkylarkImports; |
| 92 | import com.google.devtools.build.lib.syntax.SkylarkImports.SkylarkImportSyntaxException; |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 93 | import com.google.devtools.build.lib.util.OrderedSetMultimap; |
Klaus Aehlig | c27b4da | 2017-09-01 10:33:22 +0200 | [diff] [blame] | 94 | import com.google.devtools.build.lib.util.Pair; |
Mark Schaller | 6df8179 | 2015-12-10 18:47:47 +0000 | [diff] [blame] | 95 | import com.google.devtools.build.lib.util.Preconditions; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 96 | import com.google.devtools.build.lib.util.RegexFilter; |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 97 | import com.google.devtools.build.lib.vfs.PathFragment; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 98 | import com.google.devtools.build.skyframe.SkyKey; |
Eric Fellheimer | 9c1e12f | 2015-08-06 20:23:55 +0000 | [diff] [blame] | 99 | import com.google.devtools.build.skyframe.WalkableGraph; |
Janak Ramakrishnan | bede7b4 | 2016-11-17 18:34:08 +0000 | [diff] [blame] | 100 | import com.google.devtools.common.options.Converter; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 101 | import com.google.devtools.common.options.Option; |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 102 | import com.google.devtools.common.options.OptionDocumentationCategory; |
ccalvarin | c82a197 | 2017-07-17 21:13:39 +0200 | [diff] [blame] | 103 | import com.google.devtools.common.options.OptionEffectTag; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 104 | import com.google.devtools.common.options.OptionsBase; |
Janak Ramakrishnan | bede7b4 | 2016-11-17 18:34:08 +0000 | [diff] [blame] | 105 | import com.google.devtools.common.options.OptionsParsingException; |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 106 | import java.util.ArrayList; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 107 | import java.util.Collection; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 108 | import java.util.HashSet; |
Lukacs Berki | 53e0391 | 2016-05-19 16:26:09 +0000 | [diff] [blame] | 109 | import java.util.LinkedHashMap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 110 | import java.util.LinkedHashSet; |
| 111 | import java.util.List; |
| 112 | import java.util.Map; |
| 113 | import java.util.Set; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 114 | import java.util.logging.Logger; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 115 | import javax.annotation.Nullable; |
| 116 | |
| 117 | /** |
| 118 | * <p>The BuildView presents a semantically-consistent and transitively-closed |
| 119 | * dependency graph for some set of packages. |
| 120 | * |
| 121 | * <h2>Package design</h2> |
| 122 | * |
| 123 | * <p>This package contains the Blaze dependency analysis framework (aka |
| 124 | * "analysis phase"). The goal of this code is to perform semantic analysis of |
| 125 | * all of the build targets required for a given build, to report |
| 126 | * errors/warnings for any problems in the input, and to construct an "action |
| 127 | * graph" (see {@code lib.actions} package) correctly representing the work to |
| 128 | * be done during the execution phase of the build. |
| 129 | * |
| 130 | * <p><b>Configurations</b> the inputs to a build come from two sources: the |
| 131 | * intrinsic inputs, specified in the BUILD file, are called <em>targets</em>. |
| 132 | * The environmental inputs, coming from the build tool, the command-line, or |
| 133 | * configuration files, are called the <em>configuration</em>. Only when a |
| 134 | * target and a configuration are combined is there sufficient information to |
| 135 | * perform a build. </p> |
| 136 | * |
| 137 | * <p>Targets are implemented by the {@link Target} hierarchy in the {@code |
| 138 | * lib.packages} code. Configurations are implemented by {@link |
| 139 | * BuildConfiguration}. The pair of these together is represented by an |
| 140 | * instance of class {@link ConfiguredTarget}; this is the root of a hierarchy |
| 141 | * with different implementations for each kind of target: source file, derived |
| 142 | * file, rules, etc. |
| 143 | * |
| 144 | * <p>The framework code in this package (as opposed to its subpackages) is |
| 145 | * responsible for constructing the {@code ConfiguredTarget} graph for a given |
| 146 | * target and configuration, taking care of such issues as: |
| 147 | * <ul> |
| 148 | * <li>caching common subgraphs. |
| 149 | * <li>detecting and reporting cycles. |
| 150 | * <li>correct propagation of errors through the graph. |
| 151 | * <li>reporting universal errors, such as dependencies from production code |
| 152 | * to tests, or to experimental branches. |
| 153 | * <li>capturing and replaying errors. |
| 154 | * <li>maintaining the graph from one build to the next to |
| 155 | * avoid unnecessary recomputation. |
| 156 | * <li>checking software licenses. |
| 157 | * </ul> |
| 158 | * |
| 159 | * <p>See also {@link ConfiguredTarget} which documents some important |
| 160 | * invariants. |
| 161 | */ |
| 162 | public class BuildView { |
| 163 | |
| 164 | /** |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 165 | * Options that affect the <i>mechanism</i> of analysis. These are distinct from {@link |
| 166 | * com.google.devtools.build.lib.analysis.config.BuildOptions}, which affect the <i>value</i> of a |
| 167 | * BuildConfiguration. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 168 | */ |
| 169 | public static class Options extends OptionsBase { |
Janak Ramakrishnan | bede7b4 | 2016-11-17 18:34:08 +0000 | [diff] [blame] | 170 | @Option( |
| 171 | name = "loading_phase_threads", |
| 172 | defaultValue = "-1", |
| 173 | category = "what", |
| 174 | converter = LoadingPhaseThreadCountConverter.class, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 175 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 176 | effectTags = {OptionEffectTag.UNKNOWN}, |
Janak Ramakrishnan | bede7b4 | 2016-11-17 18:34:08 +0000 | [diff] [blame] | 177 | help = "Number of parallel threads to use for the loading/analysis phase." |
| 178 | ) |
| 179 | public int loadingPhaseThreads; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 180 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 181 | @Option( |
| 182 | name = "keep_going", |
| 183 | abbrev = 'k', |
| 184 | defaultValue = "false", |
| 185 | category = "strategy", |
ccalvarin | 2573540 | 2017-09-19 19:09:26 +0200 | [diff] [blame] | 186 | documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY, |
| 187 | effectTags = {OptionEffectTag.EAGERNESS_TO_EXIT}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 188 | help = |
| 189 | "Continue as much as possible after an error. While the target that failed, and those " |
| 190 | + "that depend on it, cannot be analyzed (or built), the other prerequisites of " |
| 191 | + "these targets can be analyzed (or built) all the same." |
| 192 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 193 | public boolean keepGoing; |
| 194 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 195 | @Option( |
| 196 | name = "analysis_warnings_as_errors", |
| 197 | deprecationWarning = |
| 198 | "analysis_warnings_as_errors is now a no-op and will be removed in" |
| 199 | + " an upcoming Blaze release", |
| 200 | defaultValue = "false", |
| 201 | category = "strategy", |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 202 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 203 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 204 | help = "Treat visible analysis warnings as errors." |
| 205 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 206 | public boolean analysisWarningsAsErrors; |
| 207 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 208 | @Option( |
| 209 | name = "discard_analysis_cache", |
| 210 | defaultValue = "false", |
| 211 | category = "strategy", |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 212 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 213 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 214 | help = |
| 215 | "Discard the analysis cache immediately after the analysis phase completes." |
| 216 | + " Reduces memory usage by ~10%, but makes further incremental builds slower." |
| 217 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 218 | public boolean discardAnalysisCache; |
| 219 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 220 | @Option( |
| 221 | name = "experimental_extra_action_filter", |
| 222 | defaultValue = "", |
| 223 | category = "experimental", |
| 224 | converter = RegexFilter.RegexFilterConverter.class, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 225 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 226 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 227 | help = "Filters set of targets to schedule extra_actions for." |
| 228 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 229 | public RegexFilter extraActionFilter; |
| 230 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 231 | @Option( |
| 232 | name = "experimental_extra_action_top_level_only", |
| 233 | defaultValue = "false", |
| 234 | category = "experimental", |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 235 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 236 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 237 | help = "Only schedules extra_actions for top level targets." |
| 238 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 239 | public boolean extraActionTopLevelOnly; |
| 240 | |
Carmi Grushko | 9a796de | 2016-11-13 12:22:30 +0000 | [diff] [blame] | 241 | @Option( |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 242 | name = "version_window_for_dirty_node_gc", |
| 243 | defaultValue = "0", |
ccalvarin | 456adb2 | 2017-07-11 14:23:46 +0200 | [diff] [blame] | 244 | documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 245 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 246 | help = |
| 247 | "Nodes that have been dirty for more than this many versions will be deleted" |
| 248 | + " from the graph upon the next update. Values must be non-negative long integers," |
| 249 | + " or -1 indicating the maximum possible window." |
| 250 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 251 | public long versionWindowForDirtyNodeGc; |
Ulf Adams | ab64e59 | 2016-09-05 09:40:13 +0000 | [diff] [blame] | 252 | |
| 253 | @Deprecated |
| 254 | @Option( |
| 255 | name = "experimental_interleave_loading_and_analysis", |
| 256 | defaultValue = "true", |
| 257 | category = "experimental", |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 258 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 259 | effectTags = {OptionEffectTag.UNKNOWN}, |
Ulf Adams | ab64e59 | 2016-09-05 09:40:13 +0000 | [diff] [blame] | 260 | help = "No-op." |
| 261 | ) |
| 262 | public boolean interleaveLoadingAndAnalysis; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 263 | } |
| 264 | |
lberki | 998ec92 | 2017-09-05 10:08:25 +0200 | [diff] [blame] | 265 | private static final Logger logger = Logger.getLogger(BuildView.class.getName()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 266 | |
| 267 | private final BlazeDirectories directories; |
| 268 | |
| 269 | private final SkyframeExecutor skyframeExecutor; |
| 270 | private final SkyframeBuildView skyframeBuildView; |
| 271 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 272 | private final ConfiguredRuleClassProvider ruleClassProvider; |
| 273 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 274 | /** |
| 275 | * A factory class to create the coverage report action. May be null. |
| 276 | */ |
| 277 | @Nullable private final CoverageReportActionFactory coverageReportActionFactory; |
| 278 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 279 | @VisibleForTesting |
| 280 | public Set<SkyKey> getSkyframeEvaluatedTargetKeysForTesting() { |
| 281 | return skyframeBuildView.getEvaluatedTargetKeys(); |
| 282 | } |
| 283 | |
| 284 | /** The number of targets freshly evaluated in the last analysis run. */ |
| 285 | public int getTargetsVisited() { |
| 286 | return skyframeBuildView.getEvaluatedTargetKeys().size(); |
| 287 | } |
| 288 | |
nharmata | c4335cf | 2017-07-18 21:39:13 +0200 | [diff] [blame] | 289 | public PackageManagerStatistics getAndClearPkgManagerStatistics() { |
| 290 | return skyframeExecutor.getPackageManager().getAndClearStatistics(); |
| 291 | } |
| 292 | |
Ulf Adams | 59dbf68 | 2015-09-17 11:36:43 +0000 | [diff] [blame] | 293 | public BuildView(BlazeDirectories directories, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 294 | ConfiguredRuleClassProvider ruleClassProvider, |
| 295 | SkyframeExecutor skyframeExecutor, |
Ulf Adams | 5a96d53 | 2015-09-26 09:00:57 +0000 | [diff] [blame] | 296 | CoverageReportActionFactory coverageReportActionFactory) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 297 | this.directories = directories; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 298 | this.coverageReportActionFactory = coverageReportActionFactory; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 299 | this.ruleClassProvider = ruleClassProvider; |
| 300 | this.skyframeExecutor = Preconditions.checkNotNull(skyframeExecutor); |
Ulf Adams | 89eefd7 | 2015-09-23 08:00:43 +0000 | [diff] [blame] | 301 | this.skyframeBuildView = skyframeExecutor.getSkyframeBuildView(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 302 | } |
| 303 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 304 | /** |
| 305 | * Returns whether the given configured target has errors. |
| 306 | */ |
| 307 | @VisibleForTesting |
| 308 | public boolean hasErrors(ConfiguredTarget configuredTarget) { |
| 309 | return configuredTarget == null; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Sets the configurations. Not thread-safe. DO NOT CALL except from tests! |
| 314 | */ |
| 315 | @VisibleForTesting |
Ulf Adams | 79f0521 | 2015-02-27 16:40:00 +0000 | [diff] [blame] | 316 | public void setConfigurationsForTesting(BuildConfigurationCollection configurations) { |
Ulf Adams | 003fe96 | 2015-09-26 09:51:39 +0000 | [diff] [blame] | 317 | skyframeBuildView.setConfigurations(configurations); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 320 | public ArtifactFactory getArtifactFactory() { |
Ulf Adams | 89eefd7 | 2015-09-23 08:00:43 +0000 | [diff] [blame] | 321 | return skyframeBuildView.getArtifactFactory(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @VisibleForTesting |
janakr | 1cde872 | 2017-10-10 03:22:21 +0200 | [diff] [blame^] | 325 | WorkspaceStatusAction getLastWorkspaceBuildInfoActionForTesting() throws InterruptedException { |
janakr | c8dce99 | 2017-09-25 21:48:27 +0200 | [diff] [blame] | 326 | return skyframeExecutor.getLastWorkspaceStatusAction(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 329 | @Override |
| 330 | public int hashCode() { |
| 331 | throw new UnsupportedOperationException(); // avoid nondeterminism |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Return value for {@link BuildView#update} and {@code BuildTool.prepareToBuild}. |
| 336 | */ |
| 337 | public static final class AnalysisResult { |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 338 | private final ImmutableSet<ConfiguredTarget> targetsToBuild; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 339 | @Nullable private final ImmutableList<ConfiguredTarget> targetsToTest; |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 340 | private final ImmutableSet<ConfiguredTarget> targetsToSkip; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 341 | @Nullable private final String error; |
| 342 | private final ActionGraph actionGraph; |
| 343 | private final ImmutableSet<Artifact> artifactsToBuild; |
| 344 | private final ImmutableSet<ConfiguredTarget> parallelTests; |
| 345 | private final ImmutableSet<ConfiguredTarget> exclusiveTests; |
| 346 | @Nullable private final TopLevelArtifactContext topLevelContext; |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 347 | private final ImmutableList<AspectValue> aspects; |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 348 | private final PackageRoots packageRoots; |
Kristina Chodorow | 36a6c17 | 2016-07-22 15:18:07 +0000 | [diff] [blame] | 349 | private final String workspaceName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 350 | |
| 351 | private AnalysisResult( |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 352 | Collection<ConfiguredTarget> targetsToBuild, |
| 353 | Collection<AspectValue> aspects, |
| 354 | Collection<ConfiguredTarget> targetsToTest, |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 355 | Collection<ConfiguredTarget> targetsToSkip, |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 356 | @Nullable String error, |
| 357 | ActionGraph actionGraph, |
| 358 | Collection<Artifact> artifactsToBuild, |
| 359 | Collection<ConfiguredTarget> parallelTests, |
| 360 | Collection<ConfiguredTarget> exclusiveTests, |
Marian Lobur | 86bd4fd | 2015-09-16 10:01:38 +0000 | [diff] [blame] | 361 | TopLevelArtifactContext topLevelContext, |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 362 | PackageRoots packageRoots, |
Kristina Chodorow | 36a6c17 | 2016-07-22 15:18:07 +0000 | [diff] [blame] | 363 | String workspaceName) { |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 364 | this.targetsToBuild = ImmutableSet.copyOf(targetsToBuild); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 365 | this.aspects = ImmutableList.copyOf(aspects); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 366 | this.targetsToTest = targetsToTest == null ? null : ImmutableList.copyOf(targetsToTest); |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 367 | this.targetsToSkip = ImmutableSet.copyOf(targetsToSkip); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 368 | this.error = error; |
| 369 | this.actionGraph = actionGraph; |
| 370 | this.artifactsToBuild = ImmutableSet.copyOf(artifactsToBuild); |
| 371 | this.parallelTests = ImmutableSet.copyOf(parallelTests); |
| 372 | this.exclusiveTests = ImmutableSet.copyOf(exclusiveTests); |
| 373 | this.topLevelContext = topLevelContext; |
Marian Lobur | 86bd4fd | 2015-09-16 10:01:38 +0000 | [diff] [blame] | 374 | this.packageRoots = packageRoots; |
Kristina Chodorow | 36a6c17 | 2016-07-22 15:18:07 +0000 | [diff] [blame] | 375 | this.workspaceName = workspaceName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Returns configured targets to build. |
| 380 | */ |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 381 | public ImmutableSet<ConfiguredTarget> getTargetsToBuild() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 382 | return targetsToBuild; |
| 383 | } |
| 384 | |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 385 | /** @see PackageRoots */ |
| 386 | public PackageRoots getPackageRoots() { |
Marian Lobur | 86bd4fd | 2015-09-16 10:01:38 +0000 | [diff] [blame] | 387 | return packageRoots; |
| 388 | } |
| 389 | |
| 390 | /** |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 391 | * Returns aspects of configured targets to build. |
| 392 | * |
| 393 | * <p>If this list is empty, build the targets returned by {@code getTargetsToBuild()}. |
| 394 | * Otherwise, only build these aspects of the targets returned by {@code getTargetsToBuild()}. |
| 395 | */ |
| 396 | public Collection<AspectValue> getAspects() { |
| 397 | return aspects; |
| 398 | } |
| 399 | |
| 400 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 401 | * Returns the configured targets to run as tests, or {@code null} if testing was not |
| 402 | * requested (e.g. "build" command rather than "test" command). |
| 403 | */ |
| 404 | @Nullable |
| 405 | public Collection<ConfiguredTarget> getTargetsToTest() { |
| 406 | return targetsToTest; |
| 407 | } |
| 408 | |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 409 | /** |
| 410 | * Returns the configured targets that should not be executed because they're not |
| 411 | * platform-compatible with the current build. |
| 412 | * |
| 413 | * <p>For example: tests that aren't intended for the designated CPU. |
| 414 | */ |
| 415 | public ImmutableSet<ConfiguredTarget> getTargetsToSkip() { |
| 416 | return targetsToSkip; |
| 417 | } |
| 418 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 419 | public ImmutableSet<Artifact> getAdditionalArtifactsToBuild() { |
| 420 | return artifactsToBuild; |
| 421 | } |
| 422 | |
| 423 | public ImmutableSet<ConfiguredTarget> getExclusiveTests() { |
| 424 | return exclusiveTests; |
| 425 | } |
| 426 | |
| 427 | public ImmutableSet<ConfiguredTarget> getParallelTests() { |
| 428 | return parallelTests; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Returns an error description (if any). |
| 433 | */ |
| 434 | @Nullable public String getError() { |
| 435 | return error; |
| 436 | } |
| 437 | |
Ulf Adams | 988bb21 | 2015-08-25 12:51:48 +0000 | [diff] [blame] | 438 | public boolean hasError() { |
| 439 | return error != null; |
| 440 | } |
| 441 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 442 | /** |
| 443 | * Returns the action graph. |
| 444 | */ |
| 445 | public ActionGraph getActionGraph() { |
| 446 | return actionGraph; |
| 447 | } |
| 448 | |
| 449 | public TopLevelArtifactContext getTopLevelContext() { |
| 450 | return topLevelContext; |
| 451 | } |
Kristina Chodorow | 36a6c17 | 2016-07-22 15:18:07 +0000 | [diff] [blame] | 452 | |
| 453 | public String getWorkspaceName() { |
| 454 | return workspaceName; |
| 455 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
| 459 | /** |
| 460 | * Returns the collection of configured targets corresponding to any of the provided targets. |
| 461 | */ |
| 462 | @VisibleForTesting |
| 463 | static Iterable<? extends ConfiguredTarget> filterTestsByTargets( |
| 464 | Collection<? extends ConfiguredTarget> targets, |
| 465 | final Set<? extends Target> allowedTargets) { |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 466 | return Iterables.filter( |
| 467 | targets, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 468 | new Predicate<ConfiguredTarget>() { |
| 469 | @Override |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 470 | public boolean apply(ConfiguredTarget rule) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 471 | return allowedTargets.contains(rule.getTarget()); |
| 472 | } |
| 473 | }); |
| 474 | } |
| 475 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 476 | @ThreadCompatible |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 477 | public AnalysisResult update( |
| 478 | LoadingResult loadingResult, |
| 479 | BuildConfigurationCollection configurations, |
| 480 | List<String> aspects, |
| 481 | Options viewOptions, |
| 482 | TopLevelArtifactContext topLevelOptions, |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 483 | ExtendedEventHandler eventHandler, |
Ulf Adams | 8c4ae67 | 2016-03-30 11:20:41 +0000 | [diff] [blame] | 484 | EventBus eventBus) |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 485 | throws ViewCreationFailedException, InterruptedException { |
lberki | 998ec92 | 2017-09-05 10:08:25 +0200 | [diff] [blame] | 486 | logger.info("Starting analysis"); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 487 | pollInterruptedStatus(); |
| 488 | |
| 489 | skyframeBuildView.resetEvaluatedConfiguredTargetKeysSet(); |
| 490 | |
| 491 | Collection<Target> targets = loadingResult.getTargets(); |
| 492 | eventBus.post(new AnalysisPhaseStartedEvent(targets)); |
| 493 | |
Ulf Adams | 003fe96 | 2015-09-26 09:51:39 +0000 | [diff] [blame] | 494 | skyframeBuildView.setConfigurations(configurations); |
Marian Lobur | 86bd4fd | 2015-09-16 10:01:38 +0000 | [diff] [blame] | 495 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 496 | // Determine the configurations. |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 497 | List<TargetAndConfiguration> topLevelTargetsWithConfigs = |
| 498 | nodesForTopLevelTargets(configurations, targets, eventHandler); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 499 | |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 500 | // Report the generated association of targets to configurations |
| 501 | Multimap<Label, BuildConfiguration> byLabel = |
| 502 | ArrayListMultimap.<Label, BuildConfiguration>create(); |
| 503 | for (TargetAndConfiguration pair : topLevelTargetsWithConfigs) { |
| 504 | byLabel.put(pair.getLabel(), pair.getConfiguration()); |
| 505 | } |
Klaus Aehlig | 2a92c90 | 2017-08-11 14:03:31 +0200 | [diff] [blame] | 506 | for (Target target : targets) { |
| 507 | eventBus.post(new TargetConfiguredEvent(target, byLabel.get(target.getLabel()))); |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 508 | } |
| 509 | |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 510 | List<ConfiguredTargetKey> topLevelCtKeys = Lists.transform(topLevelTargetsWithConfigs, |
| 511 | new Function<TargetAndConfiguration, ConfiguredTargetKey>() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 512 | @Override |
| 513 | public ConfiguredTargetKey apply(TargetAndConfiguration node) { |
| 514 | return new ConfiguredTargetKey(node.getLabel(), node.getConfiguration()); |
| 515 | } |
| 516 | }); |
| 517 | |
Klaus Aehlig | c27b4da | 2017-09-01 10:33:22 +0200 | [diff] [blame] | 518 | Multimap<Pair<Label, String>, BuildConfiguration> aspectConfigurations = |
| 519 | ArrayListMultimap.create(); |
Klaus Aehlig | 71c993b | 2017-05-09 07:49:46 -0400 | [diff] [blame] | 520 | |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 521 | List<AspectValueKey> aspectKeys = new ArrayList<>(); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 522 | for (String aspect : aspects) { |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 523 | // Syntax: label%aspect |
| 524 | int delimiterPosition = aspect.indexOf('%'); |
| 525 | if (delimiterPosition >= 0) { |
John Field | a97e17f | 2015-11-13 02:19:52 +0000 | [diff] [blame] | 526 | // TODO(jfield): For consistency with Skylark loads, the aspect should be specified |
| 527 | // as an absolute path. Also, we probably need to do at least basic validation of |
| 528 | // path well-formedness here. |
Dmitry Lomov | 51aafc1 | 2016-11-18 14:02:54 +0000 | [diff] [blame] | 529 | String bzlFileLoadLikeString = aspect.substring(0, delimiterPosition); |
| 530 | if (!bzlFileLoadLikeString.startsWith("//") && !bzlFileLoadLikeString.startsWith("@")) { |
| 531 | // "Legacy" behavior of '--aspects' parameter. |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 532 | bzlFileLoadLikeString = PathFragment.create("/" + bzlFileLoadLikeString).toString(); |
Dmitry Lomov | 51aafc1 | 2016-11-18 14:02:54 +0000 | [diff] [blame] | 533 | if (bzlFileLoadLikeString.endsWith(".bzl")) { |
| 534 | bzlFileLoadLikeString = bzlFileLoadLikeString.substring(0, |
| 535 | bzlFileLoadLikeString.length() - ".bzl".length()); |
| 536 | } |
| 537 | } |
| 538 | SkylarkImport skylarkImport; |
| 539 | try { |
| 540 | skylarkImport = SkylarkImports.create(bzlFileLoadLikeString); |
| 541 | } catch (SkylarkImportSyntaxException e) { |
| 542 | throw new ViewCreationFailedException( |
| 543 | String.format("Invalid aspect '%s': %s", aspect, e.getMessage()), e); |
| 544 | } |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 545 | |
| 546 | String skylarkFunctionName = aspect.substring(delimiterPosition + 1); |
Dmitry Lomov | 01f85c0 | 2016-06-29 06:37:50 +0000 | [diff] [blame] | 547 | for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) { |
Klaus Aehlig | c27b4da | 2017-09-01 10:33:22 +0200 | [diff] [blame] | 548 | aspectConfigurations.put( |
| 549 | Pair.of(targetSpec.getLabel(), aspect), targetSpec.getConfiguration()); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 550 | aspectKeys.add( |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 551 | AspectValue.createSkylarkAspectKey( |
| 552 | targetSpec.getLabel(), |
Michael Staib | 04f6f24 | 2016-03-01 15:40:29 +0000 | [diff] [blame] | 553 | // For invoking top-level aspects, use the top-level configuration for both the |
| 554 | // aspect and the base target while the top-level configuration is untrimmed. |
| 555 | targetSpec.getConfiguration(), |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 556 | targetSpec.getConfiguration(), |
Dmitry Lomov | 51aafc1 | 2016-11-18 14:02:54 +0000 | [diff] [blame] | 557 | skylarkImport, |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 558 | skylarkFunctionName)); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 559 | } |
| 560 | } else { |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 561 | final NativeAspectClass aspectFactoryClass = |
| 562 | ruleClassProvider.getNativeAspectClassMap().get(aspect); |
dslomov | 99ea6b4 | 2017-04-25 17:46:17 +0200 | [diff] [blame] | 563 | |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 564 | if (aspectFactoryClass != null) { |
Dmitry Lomov | 01f85c0 | 2016-06-29 06:37:50 +0000 | [diff] [blame] | 565 | for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) { |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 566 | // For invoking top-level aspects, use the top-level configuration for both the |
| 567 | // aspect and the base target while the top-level configuration is untrimmed. |
| 568 | BuildConfiguration configuration = targetSpec.getConfiguration(); |
Klaus Aehlig | c27b4da | 2017-09-01 10:33:22 +0200 | [diff] [blame] | 569 | aspectConfigurations.put(Pair.of(targetSpec.getLabel(), aspect), configuration); |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 570 | aspectKeys.add( |
| 571 | AspectValue.createAspectKey( |
Dmitry Lomov | 8ff0645 | 2015-10-21 19:16:30 +0000 | [diff] [blame] | 572 | targetSpec.getLabel(), |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 573 | configuration, |
dslomov | fa50c3d | 2017-05-08 08:47:44 -0400 | [diff] [blame] | 574 | new AspectDescriptor(aspectFactoryClass, AspectParameters.EMPTY), |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 575 | configuration |
| 576 | )); |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 577 | } |
| 578 | } else { |
| 579 | throw new ViewCreationFailedException("Aspect '" + aspect + "' is unknown"); |
| 580 | } |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
Klaus Aehlig | c27b4da | 2017-09-01 10:33:22 +0200 | [diff] [blame] | 584 | for (Pair<Label, String> target : aspectConfigurations.keys()) { |
| 585 | eventBus.post( |
| 586 | new AspectConfiguredEvent( |
| 587 | target.getFirst(), target.getSecond(), aspectConfigurations.get(target))); |
| 588 | } |
| 589 | |
janakr | c8dce99 | 2017-09-25 21:48:27 +0200 | [diff] [blame] | 590 | skyframeExecutor.maybeInvalidateWorkspaceStatusValue(loadingResult.getWorkspaceName()); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 591 | SkyframeAnalysisResult skyframeAnalysisResult; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 592 | try { |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 593 | skyframeAnalysisResult = |
| 594 | skyframeBuildView.configureTargets( |
Janak Ramakrishnan | bede7b4 | 2016-11-17 18:34:08 +0000 | [diff] [blame] | 595 | eventHandler, |
| 596 | topLevelCtKeys, |
| 597 | aspectKeys, |
| 598 | eventBus, |
| 599 | viewOptions.keepGoing, |
| 600 | viewOptions.loadingPhaseThreads); |
Kristina Chodorow | 94e2742 | 2016-08-25 14:17:30 +0000 | [diff] [blame] | 601 | setArtifactRoots(skyframeAnalysisResult.getPackageRoots()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 602 | } finally { |
| 603 | skyframeBuildView.clearInvalidatedConfiguredTargets(); |
| 604 | } |
| 605 | |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 606 | int numTargetsToAnalyze = topLevelTargetsWithConfigs.size(); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 607 | int numSuccessful = skyframeAnalysisResult.getConfiguredTargets().size(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 608 | if (0 < numSuccessful && numSuccessful < numTargetsToAnalyze) { |
| 609 | String msg = String.format("Analysis succeeded for only %d of %d top-level targets", |
| 610 | numSuccessful, numTargetsToAnalyze); |
| 611 | eventHandler.handle(Event.info(msg)); |
lberki | 998ec92 | 2017-09-05 10:08:25 +0200 | [diff] [blame] | 612 | logger.info(msg); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 613 | } |
| 614 | |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 615 | Set<ConfiguredTarget> targetsToSkip = |
| 616 | TopLevelConstraintSemantics.checkTargetEnvironmentRestrictions( |
| 617 | skyframeAnalysisResult.getConfiguredTargets(), |
| 618 | skyframeExecutor.getPackageManager(), |
| 619 | eventHandler); |
| 620 | |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 621 | AnalysisResult result = |
| 622 | createResult( |
Ulf Adams | 5b9009b | 2015-09-24 09:52:53 +0000 | [diff] [blame] | 623 | eventHandler, |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 624 | loadingResult, |
| 625 | topLevelOptions, |
| 626 | viewOptions, |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 627 | skyframeAnalysisResult, |
| 628 | targetsToSkip); |
lberki | 998ec92 | 2017-09-05 10:08:25 +0200 | [diff] [blame] | 629 | logger.info("Finished analysis"); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 630 | return result; |
| 631 | } |
| 632 | |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 633 | private AnalysisResult createResult( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 634 | ExtendedEventHandler eventHandler, |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 635 | LoadingResult loadingResult, |
| 636 | TopLevelArtifactContext topLevelOptions, |
| 637 | BuildView.Options viewOptions, |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 638 | SkyframeAnalysisResult skyframeAnalysisResult, |
| 639 | Set<ConfiguredTarget> targetsToSkip) |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 640 | throws InterruptedException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 641 | Collection<Target> testsToRun = loadingResult.getTestsToRun(); |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 642 | Set<ConfiguredTarget> configuredTargets = |
| 643 | Sets.newLinkedHashSet(skyframeAnalysisResult.getConfiguredTargets()); |
Dmitry Lomov | cf6021a | 2016-08-09 16:49:32 +0000 | [diff] [blame] | 644 | Collection<AspectValue> aspects = skyframeAnalysisResult.getAspects(); |
| 645 | |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 646 | Set<ConfiguredTarget> allTargetsToTest = null; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 647 | if (testsToRun != null) { |
| 648 | // Determine the subset of configured targets that are meant to be run as tests. |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 649 | allTargetsToTest = Sets.newLinkedHashSet( |
| 650 | filterTestsByTargets(configuredTargets, Sets.newHashSet(testsToRun))); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 651 | } |
| 652 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 653 | Set<Artifact> artifactsToBuild = new HashSet<>(); |
| 654 | Set<ConfiguredTarget> parallelTests = new HashSet<>(); |
| 655 | Set<ConfiguredTarget> exclusiveTests = new HashSet<>(); |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 656 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 657 | // build-info and build-changelist. |
Ulf Adams | 5b9009b | 2015-09-24 09:52:53 +0000 | [diff] [blame] | 658 | Collection<Artifact> buildInfoArtifacts = |
| 659 | skyframeExecutor.getWorkspaceStatusArtifacts(eventHandler); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 660 | Preconditions.checkState(buildInfoArtifacts.size() == 2, buildInfoArtifacts); |
| 661 | artifactsToBuild.addAll(buildInfoArtifacts); |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 662 | |
| 663 | // Extra actions |
Dmitry Lomov | cf6021a | 2016-08-09 16:49:32 +0000 | [diff] [blame] | 664 | addExtraActionsIfRequested(viewOptions, configuredTargets, aspects, artifactsToBuild); |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 665 | |
| 666 | // Coverage |
| 667 | NestedSet<Artifact> baselineCoverageArtifacts = getBaselineCoverageArtifacts(configuredTargets); |
| 668 | Iterables.addAll(artifactsToBuild, baselineCoverageArtifacts); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 669 | if (coverageReportActionFactory != null) { |
Googler | cdc90e9 | 2015-02-11 00:18:07 +0000 | [diff] [blame] | 670 | CoverageReportActionsWrapper actionsWrapper; |
| 671 | actionsWrapper = coverageReportActionFactory.createCoverageReportActionsWrapper( |
Ulf Adams | 5834e2b | 2016-04-18 12:03:51 +0000 | [diff] [blame] | 672 | eventHandler, |
| 673 | directories, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 674 | allTargetsToTest, |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 675 | baselineCoverageArtifacts, |
Ulf Adams | 89eefd7 | 2015-09-23 08:00:43 +0000 | [diff] [blame] | 676 | getArtifactFactory(), |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 677 | CoverageReportValue.ARTIFACT_OWNER); |
Googler | cdc90e9 | 2015-02-11 00:18:07 +0000 | [diff] [blame] | 678 | if (actionsWrapper != null) { |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 679 | ImmutableList<ActionAnalysisMetadata> actions = actionsWrapper.getActions(); |
Googler | cdc90e9 | 2015-02-11 00:18:07 +0000 | [diff] [blame] | 680 | skyframeExecutor.injectCoverageReportData(actions); |
| 681 | artifactsToBuild.addAll(actionsWrapper.getCoverageOutputs()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 685 | // Tests. This must come last, so that the exclusive tests are scheduled after everything else. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 686 | scheduleTestsIfRequested(parallelTests, exclusiveTests, topLevelOptions, allTargetsToTest); |
| 687 | |
Janak Ramakrishnan | 6f9d7d1 | 2016-08-09 08:45:34 +0000 | [diff] [blame] | 688 | String error = createErrorMessage(loadingResult, skyframeAnalysisResult); |
Eric Fellheimer | 9c1e12f | 2015-08-06 20:23:55 +0000 | [diff] [blame] | 689 | |
Ulf Adams | 53abece | 2016-02-03 08:30:07 +0000 | [diff] [blame] | 690 | final WalkableGraph graph = skyframeAnalysisResult.getWalkableGraph(); |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 691 | final ActionGraph actionGraph = |
| 692 | new ActionGraph() { |
| 693 | @Nullable |
| 694 | @Override |
| 695 | public ActionAnalysisMetadata getGeneratingAction(Artifact artifact) { |
| 696 | ArtifactOwner artifactOwner = artifact.getArtifactOwner(); |
| 697 | if (artifactOwner instanceof ActionLookupValue.ActionLookupKey) { |
| 698 | SkyKey key = ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner); |
| 699 | ActionLookupValue val; |
| 700 | try { |
| 701 | val = (ActionLookupValue) graph.getValue(key); |
| 702 | } catch (InterruptedException e) { |
| 703 | throw new IllegalStateException( |
| 704 | "Interruption not expected from this graph: " + key, e); |
| 705 | } |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 706 | return val == null ? null : val.getGeneratingActionDangerousReadJavadoc(artifact); |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 707 | } |
| 708 | return null; |
| 709 | } |
| 710 | }; |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 711 | return new AnalysisResult( |
| 712 | configuredTargets, |
Dmitry Lomov | cf6021a | 2016-08-09 16:49:32 +0000 | [diff] [blame] | 713 | aspects, |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 714 | allTargetsToTest, |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 715 | targetsToSkip, |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 716 | error, |
| 717 | actionGraph, |
| 718 | artifactsToBuild, |
| 719 | parallelTests, |
| 720 | exclusiveTests, |
Marian Lobur | 86bd4fd | 2015-09-16 10:01:38 +0000 | [diff] [blame] | 721 | topLevelOptions, |
Kristina Chodorow | 36a6c17 | 2016-07-22 15:18:07 +0000 | [diff] [blame] | 722 | skyframeAnalysisResult.getPackageRoots(), |
| 723 | loadingResult.getWorkspaceName()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 724 | } |
| 725 | |
Janak Ramakrishnan | 6f9d7d1 | 2016-08-09 08:45:34 +0000 | [diff] [blame] | 726 | @Nullable |
| 727 | public static String createErrorMessage( |
| 728 | LoadingResult loadingResult, @Nullable SkyframeAnalysisResult skyframeAnalysisResult) { |
| 729 | return loadingResult.hasTargetPatternError() |
| 730 | ? "command succeeded, but there were errors parsing the target pattern" |
| 731 | : loadingResult.hasLoadingError() |
| 732 | || (skyframeAnalysisResult != null && skyframeAnalysisResult.hasLoadingError()) |
| 733 | ? "command succeeded, but there were loading phase errors" |
| 734 | : (skyframeAnalysisResult != null && skyframeAnalysisResult.hasAnalysisError()) |
| 735 | ? "command succeeded, but not all targets were analyzed" |
| 736 | : null; |
| 737 | } |
| 738 | |
Lukacs Berki | 6916be2 | 2015-02-19 13:36:06 +0000 | [diff] [blame] | 739 | private static NestedSet<Artifact> getBaselineCoverageArtifacts( |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 740 | Collection<ConfiguredTarget> configuredTargets) { |
Lukacs Berki | 6916be2 | 2015-02-19 13:36:06 +0000 | [diff] [blame] | 741 | NestedSetBuilder<Artifact> baselineCoverageArtifacts = NestedSetBuilder.stableOrder(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 742 | for (ConfiguredTarget target : configuredTargets) { |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 743 | InstrumentedFilesProvider provider = target.getProvider(InstrumentedFilesProvider.class); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 744 | if (provider != null) { |
Ulf Adams | fc154ae | 2015-08-31 12:32:14 +0000 | [diff] [blame] | 745 | baselineCoverageArtifacts.addTransitive(provider.getBaselineCoverageArtifacts()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 746 | } |
| 747 | } |
Lukacs Berki | 6916be2 | 2015-02-19 13:36:06 +0000 | [diff] [blame] | 748 | return baselineCoverageArtifacts.build(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 749 | } |
| 750 | |
Dmitry Lomov | cf6021a | 2016-08-09 16:49:32 +0000 | [diff] [blame] | 751 | private void addExtraActionsIfRequested(Options viewOptions, |
| 752 | Collection<ConfiguredTarget> configuredTargets, |
| 753 | Collection<AspectValue> aspects, |
| 754 | Set<Artifact> artifactsToBuild) { |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 755 | Iterable<Artifact> extraActionArtifacts = |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 756 | concat( |
| 757 | addExtraActionsFromTargets(viewOptions, configuredTargets), |
| 758 | addExtraActionsFromAspects(viewOptions, aspects)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 759 | |
| 760 | RegexFilter filter = viewOptions.extraActionFilter; |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 761 | for (Artifact artifact : extraActionArtifacts) { |
| 762 | boolean filterMatches = |
| 763 | filter == null || filter.isIncluded(artifact.getOwnerLabel().toString()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 764 | if (filterMatches) { |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 765 | artifactsToBuild.add(artifact); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 770 | private NestedSet<Artifact> addExtraActionsFromTargets( |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 771 | BuildView.Options viewOptions, Collection<ConfiguredTarget> configuredTargets) { |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 772 | NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder(); |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 773 | for (ConfiguredTarget target : configuredTargets) { |
| 774 | ExtraActionArtifactsProvider provider = |
| 775 | target.getProvider(ExtraActionArtifactsProvider.class); |
| 776 | if (provider != null) { |
| 777 | if (viewOptions.extraActionTopLevelOnly) { |
lberki | 9137a75 | 2017-06-09 12:49:10 +0200 | [diff] [blame] | 778 | // Collect all aspect-classes that topLevel might inject. |
| 779 | Set<AspectClass> aspectClasses = new HashSet<>(); |
| 780 | for (Attribute attr : target.getTarget().getAssociatedRule().getAttributes()) { |
| 781 | aspectClasses.addAll(attr.getAspectClasses()); |
| 782 | } |
Carmi Grushko | 9a796de | 2016-11-13 12:22:30 +0000 | [diff] [blame] | 783 | |
lberki | 9137a75 | 2017-06-09 12:49:10 +0200 | [diff] [blame] | 784 | builder.addTransitive(provider.getExtraActionArtifacts()); |
| 785 | if (!aspectClasses.isEmpty()) { |
| 786 | builder.addAll(filterTransitiveExtraActions(provider, aspectClasses)); |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 787 | } |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 788 | } else { |
| 789 | builder.addTransitive(provider.getTransitiveExtraActionArtifacts()); |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | return builder.build(); |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * Returns a list of actions from 'provider' that were registered by an aspect from |
| 798 | * 'aspectClasses'. All actions in 'provider' are considered - both direct and transitive. |
| 799 | */ |
| 800 | private ImmutableList<Artifact> filterTransitiveExtraActions( |
| 801 | ExtraActionArtifactsProvider provider, Set<AspectClass> aspectClasses) { |
| 802 | ImmutableList.Builder<Artifact> artifacts = ImmutableList.builder(); |
| 803 | // Add to 'artifacts' all extra-actions which were registered by aspects which 'topLevel' |
| 804 | // might have injected. |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 805 | for (Artifact artifact : provider.getTransitiveExtraActionArtifacts()) { |
| 806 | ArtifactOwner owner = artifact.getArtifactOwner(); |
| 807 | if (owner instanceof AspectKey) { |
| 808 | if (aspectClasses.contains(((AspectKey) owner).getAspectClass())) { |
| 809 | artifacts.add(artifact); |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | } |
| 813 | return artifacts.build(); |
| 814 | } |
| 815 | |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 816 | private NestedSet<Artifact> addExtraActionsFromAspects( |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 817 | BuildView.Options viewOptions, Collection<AspectValue> aspects) { |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 818 | NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder(); |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 819 | for (AspectValue aspect : aspects) { |
| 820 | ExtraActionArtifactsProvider provider = |
| 821 | aspect.getConfiguredAspect().getProvider(ExtraActionArtifactsProvider.class); |
| 822 | if (provider != null) { |
| 823 | if (viewOptions.extraActionTopLevelOnly) { |
Carmi Grushko | babd485 | 2016-11-18 17:58:09 +0000 | [diff] [blame] | 824 | builder.addTransitive(provider.getExtraActionArtifacts()); |
Carmi Grushko | df9e5e1 | 2016-11-08 23:07:57 +0000 | [diff] [blame] | 825 | } else { |
| 826 | builder.addTransitive(provider.getTransitiveExtraActionArtifacts()); |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | return builder.build(); |
| 831 | } |
| 832 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 833 | private static void scheduleTestsIfRequested(Collection<ConfiguredTarget> targetsToTest, |
| 834 | Collection<ConfiguredTarget> targetsToTestExclusive, TopLevelArtifactContext topLevelOptions, |
| 835 | Collection<ConfiguredTarget> allTestTargets) { |
Lukacs Berki | 3f4d4e9 | 2015-02-24 10:28:26 +0000 | [diff] [blame] | 836 | Set<String> outputGroups = topLevelOptions.outputGroups(); |
Lukacs Berki | 1e79b96 | 2015-03-03 10:59:21 +0000 | [diff] [blame] | 837 | if (!outputGroups.contains(OutputGroupProvider.FILES_TO_COMPILE) |
| 838 | && !outputGroups.contains(OutputGroupProvider.COMPILATION_PREREQUISITES) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 839 | && allTestTargets != null) { |
| 840 | scheduleTests(targetsToTest, targetsToTestExclusive, allTestTargets, |
| 841 | topLevelOptions.runTestsExclusively()); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | |
| 846 | /** |
| 847 | * Returns set of artifacts representing test results, writing into targetsToTest and |
| 848 | * targetsToTestExclusive. |
| 849 | */ |
| 850 | private static void scheduleTests(Collection<ConfiguredTarget> targetsToTest, |
| 851 | Collection<ConfiguredTarget> targetsToTestExclusive, |
| 852 | Collection<ConfiguredTarget> allTestTargets, |
| 853 | boolean isExclusive) { |
| 854 | for (ConfiguredTarget target : allTestTargets) { |
| 855 | if (target.getTarget() instanceof Rule) { |
| 856 | boolean exclusive = |
| 857 | isExclusive || TargetUtils.isExclusiveTestRule((Rule) target.getTarget()); |
| 858 | Collection<ConfiguredTarget> testCollection = exclusive |
| 859 | ? targetsToTestExclusive |
| 860 | : targetsToTest; |
| 861 | testCollection.add(target); |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 866 | /** |
| 867 | * Given a set of top-level targets and a configuration collection, returns the appropriate |
| 868 | * <Target, Configuration> pair for each target. |
| 869 | * |
| 870 | * <p>Preserves the original input ordering. |
| 871 | */ |
| 872 | private List<TargetAndConfiguration> nodesForTopLevelTargets( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 873 | BuildConfigurationCollection configurations, |
| 874 | Collection<Target> targets, |
| 875 | ExtendedEventHandler eventHandler) |
| 876 | throws InterruptedException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 877 | // We use a hash set here to remove duplicate nodes; this can happen for input files and package |
| 878 | // groups. |
| 879 | LinkedHashSet<TargetAndConfiguration> nodes = new LinkedHashSet<>(targets.size()); |
| 880 | for (BuildConfiguration config : configurations.getTargetConfigurations()) { |
| 881 | for (Target target : targets) { |
gregce | 8b4f9f5 | 2017-08-17 20:50:22 +0200 | [diff] [blame] | 882 | nodes.add(new TargetAndConfiguration(target, target.isConfigurable() ? config : null)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 883 | } |
| 884 | } |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 885 | return ImmutableList.copyOf(getConfigurations(nodes, eventHandler)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 886 | } |
| 887 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 888 | /** |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 889 | * If {@link BuildConfiguration.Options#trimConfigurations()} is true, transforms a collection of |
| 890 | * <Target, Configuration> pairs by trimming each target's configuration to only the fragments the |
| 891 | * target and its transitive dependencies need. |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 892 | * |
Greg Estren | 1d8ba90 | 2016-09-21 21:18:19 +0000 | [diff] [blame] | 893 | * <p>Else returns configurations that unconditionally include all fragments. |
| 894 | * |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 895 | * <p>Preserves the original input order (but merges duplicate nodes that might occur due to |
| 896 | * top-level configuration transitions) . Uses original (untrimmed) configurations for targets |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 897 | * that can't be evaluated (e.g. due to loading phase errors). |
| 898 | * |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 899 | * <p>This is suitable for feeding {@link ConfiguredTargetValue} keys: as general principle {@link |
| 900 | * ConfiguredTarget}s should have exactly as much information in their configurations as they need |
| 901 | * to evaluate and no more (e.g. there's no need for Android settings in a C++ configured target). |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 902 | */ |
| 903 | // TODO(bazel-team): error out early for targets that fail - untrimmed configurations should |
| 904 | // never make it through analysis (and especially not seed ConfiguredTargetValues) |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 905 | private LinkedHashSet<TargetAndConfiguration> getConfigurations( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 906 | Iterable<TargetAndConfiguration> inputs, ExtendedEventHandler eventHandler) |
Greg Estren | 1d8ba90 | 2016-09-21 21:18:19 +0000 | [diff] [blame] | 907 | throws InterruptedException { |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 908 | Map<Label, Target> labelsToTargets = new LinkedHashMap<>(); |
| 909 | // We'll get the configs from SkyframeExecutor#getConfigurations, which gets configurations |
| 910 | // for deps including transitions. So to satisfy its API we repackage each target as a |
| 911 | // Dependency with a NONE transition. |
| 912 | Multimap<BuildConfiguration, Dependency> asDeps = |
| 913 | ArrayListMultimap.<BuildConfiguration, Dependency>create(); |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 914 | |
| 915 | for (TargetAndConfiguration targetAndConfig : inputs) { |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 916 | labelsToTargets.put(targetAndConfig.getLabel(), targetAndConfig.getTarget()); |
| 917 | if (targetAndConfig.getConfiguration() != null) { |
| 918 | asDeps.put(targetAndConfig.getConfiguration(), |
| 919 | Dependency.withTransitionAndAspects( |
gregce | 692f763f | 2017-07-06 22:51:30 -0400 | [diff] [blame] | 920 | targetAndConfig.getLabel(), |
| 921 | getTopLevelTransition(targetAndConfig, |
| 922 | ruleClassProvider.getDynamicTransitionMapper()), |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 923 | // TODO(bazel-team): support top-level aspects |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 924 | AspectCollection.EMPTY)); |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 928 | // Maps <target, originalConfig> pairs to <target, finalConfig> pairs for targets that |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 929 | // could be successfully Skyframe-evaluated. |
| 930 | Map<TargetAndConfiguration, TargetAndConfiguration> successfullyEvaluatedTargets = |
| 931 | new LinkedHashMap<>(); |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 932 | if (!asDeps.isEmpty()) { |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 933 | for (BuildConfiguration fromConfig : asDeps.keySet()) { |
Greg Estren | 0db9b11 | 2016-12-05 21:55:54 +0000 | [diff] [blame] | 934 | Multimap<Dependency, BuildConfiguration> trimmedTargets = |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 935 | skyframeExecutor.getConfigurations(eventHandler, fromConfig.getOptions(), |
| 936 | asDeps.get(fromConfig)); |
Greg Estren | 0db9b11 | 2016-12-05 21:55:54 +0000 | [diff] [blame] | 937 | for (Map.Entry<Dependency, BuildConfiguration> trimmedTarget : trimmedTargets.entries()) { |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 938 | Target target = labelsToTargets.get(trimmedTarget.getKey().getLabel()); |
| 939 | successfullyEvaluatedTargets.put( |
| 940 | new TargetAndConfiguration(target, fromConfig), |
| 941 | new TargetAndConfiguration(target, trimmedTarget.getValue())); |
| 942 | } |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 946 | LinkedHashSet<TargetAndConfiguration> result = new LinkedHashSet<>(); |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 947 | for (TargetAndConfiguration originalInput : inputs) { |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 948 | if (successfullyEvaluatedTargets.containsKey(originalInput)) { |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 949 | // The configuration was successfully trimmed. |
Greg Estren | 7883bf1 | 2016-11-18 20:03:43 +0000 | [diff] [blame] | 950 | result.add(successfullyEvaluatedTargets.get(originalInput)); |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 951 | } else { |
| 952 | // Either the configuration couldn't be determined (e.g. loading phase error) or it's null. |
| 953 | result.add(originalInput); |
| 954 | } |
| 955 | } |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 956 | return result; |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Greg Estren | 01a78e7 | 2016-06-17 16:16:16 +0000 | [diff] [blame] | 959 | /** |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 960 | * Returns the transition to apply to the top-level configuration before applying it to this |
| 961 | * target. This enables support for rule-triggered top-level configuration hooks. |
| 962 | */ |
gregce | 692f763f | 2017-07-06 22:51:30 -0400 | [diff] [blame] | 963 | private static Attribute.Transition getTopLevelTransition(TargetAndConfiguration targetAndConfig, |
| 964 | DynamicTransitionMapper dynamicTransitionMapper) { |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 965 | Target target = targetAndConfig.getTarget(); |
| 966 | BuildConfiguration fromConfig = targetAndConfig.getConfiguration(); |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 967 | |
| 968 | // Top-level transitions (chosen by configuration fragments): |
| 969 | Transition topLevelTransition = fromConfig.topLevelConfigurationHook(target); |
| 970 | if (topLevelTransition == null) { |
| 971 | topLevelTransition = ConfigurationTransition.NONE; |
| 972 | } |
| 973 | |
| 974 | // Rule class transitions (chosen by rule class definitions): |
| 975 | if (target.getAssociatedRule() == null) { |
| 976 | return topLevelTransition; |
| 977 | } |
| 978 | Rule associatedRule = target.getAssociatedRule(); |
| 979 | RuleTransitionFactory transitionFactory = |
| 980 | associatedRule.getRuleClassObject().getTransitionFactory(); |
| 981 | if (transitionFactory == null) { |
| 982 | return topLevelTransition; |
| 983 | } |
gregce | 692f763f | 2017-07-06 22:51:30 -0400 | [diff] [blame] | 984 | // dynamicTransitionMapper is only needed because of Attribute.ConfigurationTransition.DATA: |
| 985 | // this is C++-specific but non-C++ rules declare it. So they can't directly provide the |
| 986 | // C++-specific patch transition that implements it. |
| 987 | PatchTransition ruleClassTransition = (PatchTransition) |
| 988 | dynamicTransitionMapper.map(transitionFactory.buildTransitionFor(associatedRule)); |
gregce | 3b8ffd1 | 2017-05-05 20:53:32 +0200 | [diff] [blame] | 989 | if (ruleClassTransition == null) { |
| 990 | return topLevelTransition; |
| 991 | } else if (topLevelTransition == ConfigurationTransition.NONE) { |
| 992 | return ruleClassTransition; |
| 993 | } else { |
| 994 | return new ComposingSplitTransition(topLevelTransition, ruleClassTransition); |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | |
| 999 | /** |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 1000 | * Gets a configuration for the given target. |
Greg Estren | 1d8ba90 | 2016-09-21 21:18:19 +0000 | [diff] [blame] | 1001 | * |
| 1002 | * <p>If {@link BuildConfiguration.Options#trimConfigurations()} is true, the configuration only |
| 1003 | * includes the fragments needed by the fragment and its transitive closure. Else unconditionally |
| 1004 | * includes all fragments. |
Greg Estren | 01a78e7 | 2016-06-17 16:16:16 +0000 | [diff] [blame] | 1005 | */ |
| 1006 | @VisibleForTesting |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 1007 | public BuildConfiguration getConfigurationForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1008 | Target target, BuildConfiguration config, ExtendedEventHandler eventHandler) |
| 1009 | throws InterruptedException { |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 1010 | return Iterables.getOnlyElement(getConfigurations( |
Greg Estren | 01a78e7 | 2016-06-17 16:16:16 +0000 | [diff] [blame] | 1011 | ImmutableList.<TargetAndConfiguration>of(new TargetAndConfiguration(target, config)), |
| 1012 | eventHandler)).getConfiguration(); |
| 1013 | } |
Greg Estren | 7971e67 | 2016-06-01 23:22:48 +0000 | [diff] [blame] | 1014 | |
| 1015 | /** |
Ulf Adams | a385d3e | 2015-09-28 13:21:45 +0000 | [diff] [blame] | 1016 | * Sets the possible artifact roots in the artifact factory. This allows the factory to resolve |
| 1017 | * paths with unknown roots to artifacts. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1018 | */ |
| 1019 | @VisibleForTesting // for BuildViewTestCase |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 1020 | public void setArtifactRoots(PackageRoots packageRoots) { |
| 1021 | getArtifactFactory().setPackageRoots(packageRoots.getPackageRootLookup()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1025 | * Tests and clears the current thread's pending "interrupted" status, and |
| 1026 | * throws InterruptedException iff it was set. |
| 1027 | */ |
| 1028 | protected final void pollInterruptedStatus() throws InterruptedException { |
| 1029 | if (Thread.interrupted()) { |
| 1030 | throw new InterruptedException(); |
| 1031 | } |
| 1032 | } |
| 1033 | |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1034 | // For testing |
| 1035 | @VisibleForTesting |
| 1036 | public Iterable<ConfiguredTarget> getDirectPrerequisitesForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1037 | ExtendedEventHandler eventHandler, ConfiguredTarget ct, |
| 1038 | BuildConfigurationCollection configurations) |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 1039 | throws EvalException, InvalidConfigurationException, |
| 1040 | InterruptedException, InconsistentAspectOrderException { |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1041 | return skyframeExecutor.getConfiguredTargets( |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1042 | eventHandler, |
| 1043 | ct.getConfiguration(), |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1044 | ImmutableSet.copyOf( |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1045 | getDirectPrerequisiteDependenciesForTesting( |
| 1046 | eventHandler, ct, configurations, /*toolchainContext=*/ null) |
gregce | 5303cc0 | 2017-09-13 22:08:14 +0200 | [diff] [blame] | 1047 | .values())); |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | @VisibleForTesting |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 1051 | public OrderedSetMultimap<Attribute, Dependency> getDirectPrerequisiteDependenciesForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1052 | final ExtendedEventHandler eventHandler, |
| 1053 | final ConfiguredTarget ct, |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1054 | BuildConfigurationCollection configurations, |
| 1055 | ToolchainContext toolchainContext) |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 1056 | throws EvalException, InvalidConfigurationException, InterruptedException, |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1057 | InconsistentAspectOrderException { |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1058 | if (!(ct.getTarget() instanceof Rule)) { |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 1059 | return OrderedSetMultimap.create(); |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | class SilentDependencyResolver extends DependencyResolver { |
gregce | 8529746 | 2017-08-18 21:20:29 +0200 | [diff] [blame] | 1063 | private SilentDependencyResolver() { |
| 1064 | super(ruleClassProvider.getDynamicTransitionMapper()); |
| 1065 | } |
| 1066 | |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1067 | @Override |
| 1068 | protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) { |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 1069 | throw new RuntimeException("bad visibility on " + label + " during testing unexpected"); |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | @Override |
| 1073 | protected void invalidPackageGroupReferenceHook(TargetAndConfiguration node, Label label) { |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 1074 | throw new RuntimeException("bad package group on " + label + " during testing unexpected"); |
| 1075 | } |
| 1076 | |
| 1077 | @Override |
| 1078 | protected void missingEdgeHook(Target from, Label to, NoSuchThingException e) { |
| 1079 | throw new RuntimeException( |
| 1080 | "missing dependency from " + from.getLabel() + " to " + to + ": " + e.getMessage(), |
| 1081 | e); |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | @Override |
Janak Ramakrishnan | 03e4f9c | 2016-08-16 18:59:56 +0000 | [diff] [blame] | 1085 | protected Target getTarget(Target from, Label label, NestedSetBuilder<Label> rootCauses) |
| 1086 | throws InterruptedException { |
Ulf Adams | 2ac2096 | 2016-02-01 13:04:54 +0000 | [diff] [blame] | 1087 | try { |
Janak Ramakrishnan | 03e4f9c | 2016-08-16 18:59:56 +0000 | [diff] [blame] | 1088 | return skyframeExecutor.getPackageManager().getTarget(eventHandler, label); |
Ulf Adams | 2ac2096 | 2016-02-01 13:04:54 +0000 | [diff] [blame] | 1089 | } catch (NoSuchThingException e) { |
| 1090 | throw new IllegalStateException(e); |
| 1091 | } |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1092 | } |
Greg Estren | 373e3e2 | 2016-08-09 22:36:51 +0000 | [diff] [blame] | 1093 | |
| 1094 | @Override |
| 1095 | protected List<BuildConfiguration> getConfigurations( |
| 1096 | Set<Class<? extends BuildConfiguration.Fragment>> fragments, |
| 1097 | Iterable<BuildOptions> buildOptions) { |
| 1098 | Preconditions.checkArgument(ct.getConfiguration().fragmentClasses().equals(fragments)); |
| 1099 | Dependency asDep = Dependency.withTransitionAndAspects(ct.getLabel(), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 1100 | Attribute.ConfigurationTransition.NONE, AspectCollection.EMPTY); |
Greg Estren | 373e3e2 | 2016-08-09 22:36:51 +0000 | [diff] [blame] | 1101 | ImmutableList.Builder<BuildConfiguration> builder = ImmutableList.builder(); |
| 1102 | for (BuildOptions options : buildOptions) { |
| 1103 | builder.add(Iterables.getOnlyElement( |
| 1104 | skyframeExecutor |
| 1105 | .getConfigurations(eventHandler, options, ImmutableList.<Dependency>of(asDep)) |
| 1106 | .values() |
| 1107 | )); |
| 1108 | } |
| 1109 | return builder.build(); |
| 1110 | } |
Ulf Adams | a4ca637 | 2016-01-11 14:20:28 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | DependencyResolver dependencyResolver = new SilentDependencyResolver(); |
| 1114 | TargetAndConfiguration ctgNode = |
| 1115 | new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration()); |
| 1116 | return dependencyResolver.dependentNodeMap( |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1117 | ctgNode, |
| 1118 | configurations.getHostConfiguration(), |
| 1119 | /*aspect=*/ null, |
| 1120 | getConfigurableAttributeKeysForTesting(eventHandler, ctgNode), |
| 1121 | toolchainContext); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * Returns ConfigMatchingProvider instances corresponding to the configurable attribute keys |
| 1126 | * present in this rule's attributes. |
| 1127 | */ |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 1128 | private ImmutableMap<Label, ConfigMatchingProvider> getConfigurableAttributeKeysForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1129 | ExtendedEventHandler eventHandler, TargetAndConfiguration ctg) { |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1130 | if (!(ctg.getTarget() instanceof Rule)) { |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 1131 | return ImmutableMap.of(); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1132 | } |
| 1133 | Rule rule = (Rule) ctg.getTarget(); |
Lukacs Berki | 53e0391 | 2016-05-19 16:26:09 +0000 | [diff] [blame] | 1134 | Map<Label, ConfigMatchingProvider> keys = new LinkedHashMap<>(); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1135 | RawAttributeMapper mapper = RawAttributeMapper.of(rule); |
| 1136 | for (Attribute attribute : rule.getAttributes()) { |
| 1137 | for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) { |
| 1138 | if (BuildType.Selector.isReservedLabel(label)) { |
| 1139 | continue; |
| 1140 | } |
| 1141 | ConfiguredTarget ct = getConfiguredTargetForTesting( |
| 1142 | eventHandler, label, ctg.getConfiguration()); |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 1143 | keys.put(label, Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class))); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1144 | } |
| 1145 | } |
Lukacs Berki | 53e0391 | 2016-05-19 16:26:09 +0000 | [diff] [blame] | 1146 | return ImmutableMap.copyOf(keys); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 1149 | private OrderedSetMultimap<Attribute, ConfiguredTarget> getPrerequisiteMapForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1150 | final ExtendedEventHandler eventHandler, |
| 1151 | ConfiguredTarget target, |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1152 | BuildConfigurationCollection configurations, |
| 1153 | ToolchainContext toolchainContext) |
| 1154 | throws EvalException, InvalidConfigurationException, InterruptedException, |
| 1155 | InconsistentAspectOrderException { |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 1156 | OrderedSetMultimap<Attribute, Dependency> depNodeNames = |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1157 | getDirectPrerequisiteDependenciesForTesting( |
| 1158 | eventHandler, target, configurations, toolchainContext); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1159 | |
Greg Estren | 0db9b11 | 2016-12-05 21:55:54 +0000 | [diff] [blame] | 1160 | ImmutableMultimap<Dependency, ConfiguredTarget> cts = skyframeExecutor.getConfiguredTargetMap( |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1161 | eventHandler, |
gregce | 5303cc0 | 2017-09-13 22:08:14 +0200 | [diff] [blame] | 1162 | target.getConfiguration(), ImmutableSet.copyOf(depNodeNames.values())); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1163 | |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 1164 | OrderedSetMultimap<Attribute, ConfiguredTarget> result = OrderedSetMultimap.create(); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1165 | for (Map.Entry<Attribute, Dependency> entry : depNodeNames.entries()) { |
Greg Estren | 0db9b11 | 2016-12-05 21:55:54 +0000 | [diff] [blame] | 1166 | result.putAll(entry.getKey(), cts.get(entry.getValue())); |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1167 | } |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 1168 | return result; |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Cal Peyser | 8a638d5 | 2017-03-24 15:44:24 +0000 | [diff] [blame] | 1171 | private Transition getTopLevelTransitionForTarget(Label label, ExtendedEventHandler handler) { |
| 1172 | Rule rule; |
| 1173 | try { |
| 1174 | rule = skyframeExecutor |
| 1175 | .getPackageManager() |
| 1176 | .getTarget(handler, label) |
| 1177 | .getAssociatedRule(); |
| 1178 | } catch (NoSuchPackageException | NoSuchTargetException e) { |
| 1179 | return ConfigurationTransition.NONE; |
| 1180 | } catch (InterruptedException e) { |
| 1181 | Thread.currentThread().interrupt(); |
| 1182 | throw new AssertionError("Configuration of " + label + " interrupted"); |
| 1183 | } |
| 1184 | if (rule == null) { |
| 1185 | return ConfigurationTransition.NONE; |
| 1186 | } |
| 1187 | RuleTransitionFactory factory = rule |
| 1188 | .getRuleClassObject() |
| 1189 | .getTransitionFactory(); |
mstaib | 274cb26 | 2017-03-29 20:12:19 +0000 | [diff] [blame] | 1190 | if (factory == null) { |
| 1191 | return ConfigurationTransition.NONE; |
| 1192 | } |
gregce | 692f763f | 2017-07-06 22:51:30 -0400 | [diff] [blame] | 1193 | |
| 1194 | // dynamicTransitionMapper is only needed because of Attribute.ConfigurationTransition.DATA: |
| 1195 | // this is C++-specific but non-C++ rules declare it. So they can't directly provide the |
| 1196 | // C++-specific patch transition that implements it. |
| 1197 | PatchTransition transition = (PatchTransition) |
| 1198 | ruleClassProvider.getDynamicTransitionMapper().map(factory.buildTransitionFor(rule)); |
mstaib | 274cb26 | 2017-03-29 20:12:19 +0000 | [diff] [blame] | 1199 | return (transition == null) ? ConfigurationTransition.NONE : transition; |
Cal Peyser | 8a638d5 | 2017-03-24 15:44:24 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Ulf Adams | 9c505cb | 2015-09-28 13:38:14 +0000 | [diff] [blame] | 1202 | /** |
gregce | 408bfe47 | 2017-09-14 00:47:27 +0200 | [diff] [blame] | 1203 | * Returns a configured target for the specified target and configuration. If the target in |
| 1204 | * question has a top-level rule class transition, that transition is applied in the returned |
| 1205 | * ConfiguredTarget. |
| 1206 | * |
| 1207 | * <p>Returns {@code null} if something goes wrong. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1208 | */ |
| 1209 | @VisibleForTesting |
Ulf Adams | a385d3e | 2015-09-28 13:21:45 +0000 | [diff] [blame] | 1210 | public ConfiguredTarget getConfiguredTargetForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1211 | ExtendedEventHandler eventHandler, Label label, BuildConfiguration config) { |
Cal Peyser | 8a638d5 | 2017-03-24 15:44:24 +0000 | [diff] [blame] | 1212 | return skyframeExecutor.getConfiguredTargetForTesting(eventHandler, label, config, |
| 1213 | getTopLevelTransitionForTarget(label, eventHandler)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Returns a RuleContext which is the same as the original RuleContext of the target parameter. |
| 1218 | */ |
| 1219 | @VisibleForTesting |
Florian Weikert | 4b67d4f | 2015-09-14 13:35:34 +0000 | [diff] [blame] | 1220 | public RuleContext getRuleContextForTesting( |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1221 | ConfiguredTarget target, |
| 1222 | StoredEventHandler eventHandler, |
Lukacs Berki | 76cb02e | 2017-02-17 14:06:11 +0000 | [diff] [blame] | 1223 | BuildConfigurationCollection configurations) |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 1224 | throws EvalException, InvalidConfigurationException, InterruptedException, |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1225 | InconsistentAspectOrderException, ToolchainContextException { |
Ulf Adams | a385d3e | 2015-09-28 13:21:45 +0000 | [diff] [blame] | 1226 | BuildConfiguration targetConfig = target.getConfiguration(); |
| 1227 | CachingAnalysisEnvironment env = |
Ulf Adams | 89eefd7 | 2015-09-23 08:00:43 +0000 | [diff] [blame] | 1228 | new CachingAnalysisEnvironment(getArtifactFactory(), |
Ulf Adams | a385d3e | 2015-09-28 13:21:45 +0000 | [diff] [blame] | 1229 | new ConfiguredTargetKey(target.getLabel(), targetConfig), |
| 1230 | /*isSystemEnv=*/false, targetConfig.extendedSanityChecks(), eventHandler, |
cushon | e1d2e39 | 2017-09-29 13:54:04 -0400 | [diff] [blame] | 1231 | /*env=*/null, targetConfig.isActionsEnabled()); |
Ulf Adams | a385d3e | 2015-09-28 13:21:45 +0000 | [diff] [blame] | 1232 | return getRuleContextForTesting(eventHandler, target, env, configurations); |
Ulf Adams | 79f0521 | 2015-02-27 16:40:00 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * Creates and returns a rule context that is equivalent to the one that was used to create the |
| 1237 | * given configured target. |
| 1238 | */ |
| 1239 | @VisibleForTesting |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1240 | public RuleContext getRuleContextForTesting( |
| 1241 | ExtendedEventHandler eventHandler, |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1242 | ConfiguredTarget target, |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1243 | AnalysisEnvironment env, |
| 1244 | BuildConfigurationCollection configurations) |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 1245 | throws EvalException, InvalidConfigurationException, InterruptedException, |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1246 | InconsistentAspectOrderException, ToolchainContextException { |
Greg Estren | 9eb1cf0 | 2015-06-26 22:18:35 +0000 | [diff] [blame] | 1247 | BuildConfiguration targetConfig = target.getConfiguration(); |
cpeyser | fb82999 | 2017-09-07 17:17:03 +0200 | [diff] [blame] | 1248 | Set<Label> requiredToolchains = |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1249 | target.getTarget().getAssociatedRule().getRuleClassObject().getRequiredToolchains(); |
| 1250 | ToolchainContext toolchainContext = |
| 1251 | skyframeExecutor.getToolchainContextForTesting( |
| 1252 | requiredToolchains, targetConfig, eventHandler); |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1253 | OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap = |
| 1254 | getPrerequisiteMapForTesting(eventHandler, target, configurations, toolchainContext); |
| 1255 | toolchainContext.resolveToolchains(prerequisiteMap); |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1256 | |
Ulf Adams | 79f0521 | 2015-02-27 16:40:00 +0000 | [diff] [blame] | 1257 | return new RuleContext.Builder( |
Mark Schaller | 0312f91 | 2016-07-22 18:45:02 +0000 | [diff] [blame] | 1258 | env, |
| 1259 | (Rule) target.getTarget(), |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 1260 | ImmutableList.<AspectDescriptor>of(), |
Mark Schaller | 0312f91 | 2016-07-22 18:45:02 +0000 | [diff] [blame] | 1261 | targetConfig, |
| 1262 | configurations.getHostConfiguration(), |
| 1263 | ruleClassProvider.getPrerequisiteValidator(), |
| 1264 | ((Rule) target.getTarget()).getRuleClassObject().getConfigurationFragmentPolicy()) |
| 1265 | .setVisibility( |
| 1266 | NestedSetBuilder.<PackageSpecification>create( |
| 1267 | Order.STABLE_ORDER, PackageSpecification.everything())) |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1268 | .setPrerequisites( |
| 1269 | getPrerequisiteMapForTesting(eventHandler, target, configurations, toolchainContext)) |
Mark Schaller | 0312f91 | 2016-07-22 18:45:02 +0000 | [diff] [blame] | 1270 | .setConfigConditions(ImmutableMap.<Label, ConfigMatchingProvider>of()) |
| 1271 | .setUniversalFragment(ruleClassProvider.getUniversalFragment()) |
cpeyser | 1099b54 | 2017-09-06 18:19:20 +0200 | [diff] [blame] | 1272 | .setToolchainContext(toolchainContext) |
Mark Schaller | 0312f91 | 2016-07-22 18:45:02 +0000 | [diff] [blame] | 1273 | .build(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | /** |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1277 | * For a configured target dependentTarget, returns the desired configured target that is depended |
| 1278 | * upon. Useful for obtaining the a target with aspects required by the dependent. |
Googler | 9263b46 | 2015-05-13 19:22:24 +0000 | [diff] [blame] | 1279 | */ |
| 1280 | @VisibleForTesting |
| 1281 | public ConfiguredTarget getPrerequisiteConfiguredTargetForTesting( |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 1282 | ExtendedEventHandler eventHandler, |
| 1283 | ConfiguredTarget dependentTarget, |
| 1284 | Label desiredTarget, |
Ulf Adams | e770467 | 2015-09-21 14:37:41 +0000 | [diff] [blame] | 1285 | BuildConfigurationCollection configurations) |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 1286 | throws EvalException, InvalidConfigurationException, InterruptedException, |
| 1287 | InconsistentAspectOrderException { |
Googler | 9263b46 | 2015-05-13 19:22:24 +0000 | [diff] [blame] | 1288 | Collection<ConfiguredTarget> configuredTargets = |
cpeyser | b38e3af | 2017-09-11 16:58:58 +0200 | [diff] [blame] | 1289 | getPrerequisiteMapForTesting( |
| 1290 | eventHandler, dependentTarget, configurations, /*toolchainContext=*/ null) |
| 1291 | .values(); |
Googler | 9263b46 | 2015-05-13 19:22:24 +0000 | [diff] [blame] | 1292 | for (ConfiguredTarget ct : configuredTargets) { |
Ulf Adams | a385d3e | 2015-09-28 13:21:45 +0000 | [diff] [blame] | 1293 | if (ct.getLabel().equals(desiredTarget)) { |
Googler | 9263b46 | 2015-05-13 19:22:24 +0000 | [diff] [blame] | 1294 | return ct; |
| 1295 | } |
| 1296 | } |
| 1297 | return null; |
| 1298 | } |
Janak Ramakrishnan | bede7b4 | 2016-11-17 18:34:08 +0000 | [diff] [blame] | 1299 | |
| 1300 | /** |
| 1301 | * A converter for loading phase thread count. Since the default is not a true constant, we create |
| 1302 | * a converter here to implement the default logic. |
| 1303 | */ |
| 1304 | public static final class LoadingPhaseThreadCountConverter implements Converter<Integer> { |
| 1305 | @Override |
| 1306 | public Integer convert(String input) throws OptionsParsingException { |
| 1307 | if ("-1".equals(input)) { |
| 1308 | // Reduce thread count while running tests. Test cases are typically small, and large thread |
| 1309 | // pools vying for a relatively small number of CPU cores may induce non-optimal |
| 1310 | // performance. |
| 1311 | return System.getenv("TEST_TMPDIR") == null ? 200 : 5; |
| 1312 | } |
| 1313 | |
| 1314 | try { |
| 1315 | int result = Integer.decode(input); |
| 1316 | if (result < 0) { |
| 1317 | throw new OptionsParsingException("'" + input + "' must be at least -1"); |
| 1318 | } |
| 1319 | return result; |
| 1320 | } catch (NumberFormatException e) { |
| 1321 | throw new OptionsParsingException("'" + input + "' is not an int"); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | @Override |
| 1326 | public String getTypeDescription() { |
| 1327 | return "an integer"; |
| 1328 | } |
| 1329 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1330 | } |