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.skyframe; |
| 16 | |
tomlu | a155b53 | 2017-11-08 20:12:47 +0100 | [diff] [blame] | 17 | import com.google.common.base.Preconditions; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
cpeyser | fb82999 | 2017-09-07 17:17:03 +0200 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; |
ulfjack | 90e2e98 | 2017-08-07 11:27:32 +0200 | [diff] [blame] | 22 | import com.google.devtools.build.lib.analysis.AliasProvider; |
gregce | 4c3ef11 | 2017-09-20 23:43:14 +0200 | [diff] [blame] | 23 | import com.google.devtools.build.lib.analysis.AspectResolver; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | import com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment; |
ulfjack | 3740768 | 2019-09-17 06:30:49 -0700 | [diff] [blame] | 25 | import com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment.MissingDepException; |
Dmitry Lomov | b487ac6 | 2015-11-09 13:09:12 +0000 | [diff] [blame] | 26 | import com.google.devtools.build.lib.analysis.ConfiguredAspect; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 27 | import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory; |
| 28 | import com.google.devtools.build.lib.analysis.ConfiguredTarget; |
lberki | 102256f | 2019-02-08 01:34:23 -0800 | [diff] [blame] | 29 | import com.google.devtools.build.lib.analysis.DependencyResolver; |
| 30 | import com.google.devtools.build.lib.analysis.DependencyResolver.DependencyKind; |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 31 | import com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException; |
jcater | 84ca556 | 2020-04-06 14:35:46 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.analysis.DuplicateException; |
John Cater | cdfa9ca | 2019-04-05 12:32:09 -0700 | [diff] [blame] | 33 | import com.google.devtools.build.lib.analysis.ResolvedToolchainContext; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | import com.google.devtools.build.lib.analysis.TargetAndConfiguration; |
| 35 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
mjhalupka | 5d7fa7b | 2018-03-22 13:37:38 -0700 | [diff] [blame] | 36 | import com.google.devtools.build.lib.analysis.config.BuildOptions; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 37 | import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider; |
jcater | 6718191 | 2020-04-08 10:46:29 -0700 | [diff] [blame^] | 38 | import com.google.devtools.build.lib.analysis.config.DependencyEvaluationException; |
Ulf Adams | 25f03d8 | 2016-01-25 10:31:46 +0000 | [diff] [blame] | 39 | import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; |
gregce | 2aee44b | 2017-09-16 07:16:44 +0200 | [diff] [blame] | 40 | import com.google.devtools.build.lib.analysis.configuredtargets.MergedConfiguredTarget; |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 41 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId.ConfigurationId; |
| 42 | import com.google.devtools.build.lib.causes.AnalysisFailedCause; |
| 43 | import com.google.devtools.build.lib.causes.Cause; |
| 44 | import com.google.devtools.build.lib.causes.LabelCause; |
John Field | a97e17f | 2015-11-13 02:19:52 +0000 | [diff] [blame] | 45 | import com.google.devtools.build.lib.cmdline.Label; |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 46 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
Marian Lobur | c62faba | 2015-09-09 10:08:06 +0000 | [diff] [blame] | 47 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
Ulf Adams | 9e16f0a | 2016-01-25 12:43:32 +0000 | [diff] [blame] | 48 | import com.google.devtools.build.lib.events.Event; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 49 | import com.google.devtools.build.lib.events.StoredEventHandler; |
Dmitry Lomov | 2eb8bdd | 2016-04-06 08:47:30 +0000 | [diff] [blame] | 50 | import com.google.devtools.build.lib.packages.Aspect; |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 51 | import com.google.devtools.build.lib.packages.AspectDescriptor; |
Janak Ramakrishnan | 0a4c6e4 | 2015-09-17 00:37:58 +0000 | [diff] [blame] | 52 | import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 53 | import com.google.devtools.build.lib.packages.NativeAspectClass; |
janakr | f3e6f25 | 2018-01-18 07:45:12 -0800 | [diff] [blame] | 54 | import com.google.devtools.build.lib.packages.NoSuchTargetException; |
Ulf Adams | d55d7af | 2016-01-19 11:03:22 +0000 | [diff] [blame] | 55 | import com.google.devtools.build.lib.packages.NoSuchThingException; |
cparsons | 089148b | 2019-09-17 08:14:41 -0700 | [diff] [blame] | 56 | import com.google.devtools.build.lib.packages.OutputFile; |
Marian Lobur | c62faba | 2015-09-09 10:08:06 +0000 | [diff] [blame] | 57 | import com.google.devtools.build.lib.packages.Package; |
Greg Estren | 0004943 | 2015-08-25 16:43:47 +0000 | [diff] [blame] | 58 | import com.google.devtools.build.lib.packages.RuleClassProvider; |
Googler | 74558fc | 2016-05-06 21:47:42 +0000 | [diff] [blame] | 59 | import com.google.devtools.build.lib.packages.SkylarkAspect; |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 60 | import com.google.devtools.build.lib.packages.SkylarkAspectClass; |
cparsons | 0d55f4c | 2017-12-20 14:49:13 -0800 | [diff] [blame] | 61 | import com.google.devtools.build.lib.packages.SkylarkDefinedAspect; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 62 | import com.google.devtools.build.lib.packages.Target; |
Googler | c5fcc86 | 2019-09-06 16:17:47 -0700 | [diff] [blame] | 63 | import com.google.devtools.build.lib.packages.Type.ConversionException; |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 64 | import com.google.devtools.build.lib.profiler.memory.CurrentRuleTracker; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 65 | import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey; |
Dmitry Lomov | 9b2fc5c | 2016-11-11 11:18:48 +0000 | [diff] [blame] | 66 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredTargetFunctionException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 67 | import com.google.devtools.build.lib.skyframe.SkyframeExecutor.BuildViewProvider; |
Ulf Adams | a47ca01 | 2016-01-20 10:35:19 +0000 | [diff] [blame] | 68 | import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException; |
Greg Estren | d535325 | 2016-08-11 22:13:31 +0000 | [diff] [blame] | 69 | import com.google.devtools.build.lib.util.OrderedSetMultimap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 70 | import com.google.devtools.build.skyframe.SkyFunction; |
| 71 | import com.google.devtools.build.skyframe.SkyFunctionException; |
| 72 | import com.google.devtools.build.skyframe.SkyKey; |
| 73 | import com.google.devtools.build.skyframe.SkyValue; |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 74 | import com.google.devtools.build.skyframe.ValueOrException; |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 75 | import java.util.ArrayList; |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 76 | import java.util.HashMap; |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 77 | import java.util.Map; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 78 | import javax.annotation.Nullable; |
| 79 | |
| 80 | /** |
| 81 | * The Skyframe function that generates aspects. |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 82 | * |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 83 | * This class, together with {@link ConfiguredTargetFunction} drives the analysis phase. For more |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 84 | * information, see {@link com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory}. |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 85 | * |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 86 | * {@link AspectFunction} takes a SkyKey containing an {@link AspectKey} [a tuple of |
| 87 | * (target label, configurations, aspect class and aspect parameters)], |
| 88 | * loads an {@link Aspect} from aspect class and aspect parameters, |
| 89 | * gets a {@link ConfiguredTarget} for label and configurations, and then creates |
| 90 | * a {@link ConfiguredAspect} for a given {@link AspectKey}. |
| 91 | * |
| 92 | * See {@link com.google.devtools.build.lib.packages.AspectClass} documentation |
| 93 | * for an overview of aspect-related classes |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 94 | * |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 95 | * @see com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 96 | * @see com.google.devtools.build.lib.packages.AspectClass |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 97 | */ |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 98 | public final class AspectFunction implements SkyFunction { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 99 | private final BuildViewProvider buildViewProvider; |
Greg Estren | 0004943 | 2015-08-25 16:43:47 +0000 | [diff] [blame] | 100 | private final RuleClassProvider ruleClassProvider; |
mjhalupka | 5d7fa7b | 2018-03-22 13:37:38 -0700 | [diff] [blame] | 101 | private final BuildOptions defaultBuildOptions; |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 102 | /** |
| 103 | * Indicates whether the set of packages transitively loaded for a given {@link AspectValue} will |
| 104 | * be needed for package root resolution later in the build. If not, they are not collected and |
| 105 | * stored. |
| 106 | */ |
| 107 | private final boolean storeTransitivePackagesForPackageRootResolution; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 108 | |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 109 | AspectFunction( |
| 110 | BuildViewProvider buildViewProvider, |
| 111 | RuleClassProvider ruleClassProvider, |
mjhalupka | 5d7fa7b | 2018-03-22 13:37:38 -0700 | [diff] [blame] | 112 | boolean storeTransitivePackagesForPackageRootResolution, |
Googler | ce6ad29 | 2019-12-20 10:29:21 -0800 | [diff] [blame] | 113 | BuildOptions defaultBuildOptions) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 114 | this.buildViewProvider = buildViewProvider; |
Greg Estren | 0004943 | 2015-08-25 16:43:47 +0000 | [diff] [blame] | 115 | this.ruleClassProvider = ruleClassProvider; |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 116 | this.storeTransitivePackagesForPackageRootResolution = |
| 117 | storeTransitivePackagesForPackageRootResolution; |
mjhalupka | 5d7fa7b | 2018-03-22 13:37:38 -0700 | [diff] [blame] | 118 | this.defaultBuildOptions = defaultBuildOptions; |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
cparsons | 0d55f4c | 2017-12-20 14:49:13 -0800 | [diff] [blame] | 122 | * Load Skylark-defined aspect from an extension file. Is to be called from a SkyFunction. |
| 123 | * |
| 124 | * @return {@code null} if dependencies cannot be satisfied. |
| 125 | * @throws AspectCreationException if the value loaded is not a {@link SkylarkDefinedAspect}. |
| 126 | */ |
| 127 | @Nullable |
| 128 | static SkylarkDefinedAspect loadSkylarkDefinedAspect( |
nharmata | dd21a93 | 2020-04-06 15:10:26 -0700 | [diff] [blame] | 129 | Environment env, SkylarkAspectClass skylarkAspectClass) |
cparsons | 0d55f4c | 2017-12-20 14:49:13 -0800 | [diff] [blame] | 130 | throws AspectCreationException, InterruptedException { |
| 131 | Label extensionLabel = skylarkAspectClass.getExtensionLabel(); |
| 132 | String skylarkValueName = skylarkAspectClass.getExportedName(); |
| 133 | |
nharmata | dd21a93 | 2020-04-06 15:10:26 -0700 | [diff] [blame] | 134 | SkylarkAspect skylarkAspect = loadSkylarkAspect(env, extensionLabel, skylarkValueName); |
cpeyser | 1079809 | 2018-03-23 12:10:25 -0700 | [diff] [blame] | 135 | if (skylarkAspect == null) { |
| 136 | return null; |
| 137 | } |
cparsons | 0d55f4c | 2017-12-20 14:49:13 -0800 | [diff] [blame] | 138 | if (!(skylarkAspect instanceof SkylarkDefinedAspect)) { |
| 139 | throw new AspectCreationException( |
| 140 | String.format( |
laurentlb | 7dcad73 | 2018-10-25 05:17:20 -0700 | [diff] [blame] | 141 | "%s from %s is not a Starlark-defined aspect", skylarkValueName, extensionLabel), |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 142 | extensionLabel); |
cparsons | 0d55f4c | 2017-12-20 14:49:13 -0800 | [diff] [blame] | 143 | } else { |
| 144 | return (SkylarkDefinedAspect) skylarkAspect; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 149 | * Load Skylark aspect from an extension file. Is to be called from a SkyFunction. |
| 150 | * |
| 151 | * @return {@code null} if dependencies cannot be satisfied. |
| 152 | */ |
| 153 | @Nullable |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 154 | static SkylarkAspect loadSkylarkAspect( |
nharmata | dd21a93 | 2020-04-06 15:10:26 -0700 | [diff] [blame] | 155 | Environment env, Label extensionLabel, String skylarkValueName) |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 156 | throws AspectCreationException, InterruptedException { |
dannark | 4e42c32 | 2018-11-08 19:32:04 -0800 | [diff] [blame] | 157 | SkyKey importFileKey = SkylarkImportLookupValue.key(extensionLabel); |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 158 | try { |
nharmata | dd21a93 | 2020-04-06 15:10:26 -0700 | [diff] [blame] | 159 | SkylarkImportLookupValue skylarkImportLookupValue = |
| 160 | (SkylarkImportLookupValue) |
| 161 | env.getValueOrThrow(importFileKey, SkylarkImportFailedException.class); |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 162 | if (skylarkImportLookupValue == null) { |
cpeyser | 1079809 | 2018-03-23 12:10:25 -0700 | [diff] [blame] | 163 | Preconditions.checkState( |
laurentlb | 7dcad73 | 2018-10-25 05:17:20 -0700 | [diff] [blame] | 164 | env.valuesMissing(), "no Starlark import value for %s", importFileKey); |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 165 | return null; |
| 166 | } |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 167 | |
brandjon | 357ed7a | 2017-05-09 11:37:22 -0400 | [diff] [blame] | 168 | Object skylarkValue = skylarkImportLookupValue.getEnvironmentExtension().getBindings() |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 169 | .get(skylarkValueName); |
Dmitry Lomov | 1920dd9 | 2017-07-21 12:57:18 +0200 | [diff] [blame] | 170 | if (skylarkValue == null) { |
| 171 | throw new ConversionException( |
| 172 | String.format( |
| 173 | "%s is not exported from %s", skylarkValueName, extensionLabel.toString())); |
| 174 | } |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 175 | if (!(skylarkValue instanceof SkylarkAspect)) { |
| 176 | throw new ConversionException( |
Dmitry Lomov | 1920dd9 | 2017-07-21 12:57:18 +0200 | [diff] [blame] | 177 | String.format( |
| 178 | "%s from %s is not an aspect", skylarkValueName, extensionLabel.toString())); |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 179 | } |
| 180 | return (SkylarkAspect) skylarkValue; |
nharmata | dd21a93 | 2020-04-06 15:10:26 -0700 | [diff] [blame] | 181 | } catch (SkylarkImportFailedException | ConversionException e) { |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 182 | env.getListener().handle(Event.error(e.getMessage())); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 183 | throw new AspectCreationException(e.getMessage(), extensionLabel); |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 184 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Nullable |
| 188 | @Override |
| 189 | public SkyValue compute(SkyKey skyKey, Environment env) |
Florian Weikert | 4b67d4f | 2015-09-14 13:35:34 +0000 | [diff] [blame] | 190 | throws AspectFunctionException, InterruptedException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 191 | SkyframeBuildView view = buildViewProvider.getSkyframeBuildView(); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 192 | NestedSetBuilder<Cause> transitiveRootCauses = NestedSetBuilder.stableOrder(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 193 | AspectKey key = (AspectKey) skyKey.argument(); |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 194 | ConfiguredAspectFactory aspectFactory; |
Dmitry Lomov | 2eb8bdd | 2016-04-06 08:47:30 +0000 | [diff] [blame] | 195 | Aspect aspect; |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 196 | if (key.getAspectClass() instanceof NativeAspectClass) { |
| 197 | NativeAspectClass nativeAspectClass = (NativeAspectClass) key.getAspectClass(); |
| 198 | aspectFactory = (ConfiguredAspectFactory) nativeAspectClass; |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 199 | aspect = Aspect.forNative(nativeAspectClass, key.getParameters()); |
Dmitry Lomov | b487ac6 | 2015-11-09 13:09:12 +0000 | [diff] [blame] | 200 | } else if (key.getAspectClass() instanceof SkylarkAspectClass) { |
| 201 | SkylarkAspectClass skylarkAspectClass = (SkylarkAspectClass) key.getAspectClass(); |
cparsons | 0d55f4c | 2017-12-20 14:49:13 -0800 | [diff] [blame] | 202 | SkylarkDefinedAspect skylarkAspect; |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 203 | try { |
nharmata | dd21a93 | 2020-04-06 15:10:26 -0700 | [diff] [blame] | 204 | skylarkAspect = loadSkylarkDefinedAspect(env, skylarkAspectClass); |
Ulf Adams | 0678e79 | 2016-01-25 15:30:45 +0000 | [diff] [blame] | 205 | } catch (AspectCreationException e) { |
| 206 | throw new AspectFunctionException(e); |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 207 | } |
| 208 | if (skylarkAspect == null) { |
| 209 | return null; |
| 210 | } |
| 211 | |
Dmitry Lomov | 777845c | 2016-04-06 15:24:36 +0000 | [diff] [blame] | 212 | aspectFactory = new SkylarkAspectFactory(skylarkAspect); |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 213 | aspect = Aspect.forSkylark( |
| 214 | skylarkAspect.getAspectClass(), |
Googler | 74558fc | 2016-05-06 21:47:42 +0000 | [diff] [blame] | 215 | skylarkAspect.getDefinition(key.getParameters()), |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 216 | key.getParameters()); |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 217 | } else { |
| 218 | throw new IllegalStateException(); |
| 219 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 220 | |
Ulf Adams | 9e16f0a | 2016-01-25 12:43:32 +0000 | [diff] [blame] | 221 | // Keep this in sync with the same code in ConfiguredTargetFunction. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 222 | PackageValue packageValue = |
| 223 | (PackageValue) env.getValue(PackageValue.key(key.getLabel().getPackageIdentifier())); |
| 224 | if (packageValue == null) { |
| 225 | return null; |
| 226 | } |
Janak Ramakrishnan | 0a4c6e4 | 2015-09-17 00:37:58 +0000 | [diff] [blame] | 227 | Package pkg = packageValue.getPackage(); |
| 228 | if (pkg.containsErrors()) { |
| 229 | throw new AspectFunctionException( |
Ulf Adams | 9e16f0a | 2016-01-25 12:43:32 +0000 | [diff] [blame] | 230 | new BuildFileContainsErrorsException(key.getLabel().getPackageIdentifier())); |
Janak Ramakrishnan | 0a4c6e4 | 2015-09-17 00:37:58 +0000 | [diff] [blame] | 231 | } |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 232 | |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 233 | boolean aspectHasConfiguration = key.getAspectConfigurationKey() != null; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 234 | |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 235 | ImmutableSet<SkyKey> keys = |
| 236 | aspectHasConfiguration |
| 237 | ? ImmutableSet.of(key.getBaseConfiguredTargetKey(), key.getAspectConfigurationKey()) |
| 238 | : ImmutableSet.of(key.getBaseConfiguredTargetKey()); |
| 239 | |
| 240 | Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> baseAndAspectValues = |
| 241 | env.getValuesOrThrow(keys, ConfiguredValueCreationException.class); |
| 242 | if (env.valuesMissing()) { |
| 243 | return null; |
| 244 | } |
| 245 | |
| 246 | ConfiguredTargetValue baseConfiguredTargetValue; |
| 247 | BuildConfiguration aspectConfiguration = null; |
| 248 | |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 249 | try { |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 250 | baseConfiguredTargetValue = |
| 251 | (ConfiguredTargetValue) baseAndAspectValues.get(key.getBaseConfiguredTargetKey()).get(); |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 252 | } catch (ConfiguredValueCreationException e) { |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 253 | throw new AspectFunctionException( |
| 254 | new AspectCreationException(e.getMessage(), e.getRootCauses())); |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 255 | } |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 256 | |
| 257 | if (aspectHasConfiguration) { |
| 258 | try { |
| 259 | aspectConfiguration = |
| 260 | ((BuildConfigurationValue) |
| 261 | baseAndAspectValues.get(key.getAspectConfigurationKey()).get()) |
| 262 | .getConfiguration(); |
| 263 | } catch (ConfiguredValueCreationException e) { |
| 264 | throw new IllegalStateException("Unexpected exception from BuildConfigurationFunction when " |
| 265 | + "computing " + key.getAspectConfigurationKey(), e); |
| 266 | } |
mstaib | 7c7a701 | 2019-04-23 16:19:09 -0700 | [diff] [blame] | 267 | if (aspectConfiguration.trimConfigurationsRetroactively()) { |
| 268 | throw new AssertionError("Aspects should NEVER be evaluated in retroactive trimming mode."); |
| 269 | } |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 270 | } |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 271 | |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 272 | ConfiguredTarget associatedTarget = baseConfiguredTargetValue.getConfiguredTarget(); |
dslomov | 99ea6b4 | 2017-04-25 17:46:17 +0200 | [diff] [blame] | 273 | |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 274 | ConfiguredTargetAndData associatedConfiguredTargetAndData; |
janakr | 171a7eb | 2018-03-26 09:26:53 -0700 | [diff] [blame] | 275 | Package targetPkg; |
| 276 | BuildConfiguration configuration = null; |
| 277 | PackageValue.Key packageKey = |
| 278 | PackageValue.key(associatedTarget.getLabel().getPackageIdentifier()); |
| 279 | if (associatedTarget.getConfigurationKey() == null) { |
| 280 | PackageValue val = ((PackageValue) env.getValue(packageKey)); |
| 281 | if (val == null) { |
| 282 | // Unexpected in Bazel logic, but Skyframe makes no guarantees that this package is |
| 283 | // actually present. |
| 284 | return null; |
| 285 | } |
| 286 | targetPkg = val.getPackage(); |
| 287 | } else { |
| 288 | Map<SkyKey, SkyValue> result = |
| 289 | env.getValues(ImmutableSet.of(packageKey, associatedTarget.getConfigurationKey())); |
| 290 | if (env.valuesMissing()) { |
| 291 | // Unexpected in Bazel logic, but Skyframe makes no guarantees that this package and |
| 292 | // configuration are actually present. |
| 293 | return null; |
| 294 | } |
| 295 | targetPkg = ((PackageValue) result.get(packageKey)).getPackage(); |
| 296 | configuration = |
| 297 | ((BuildConfigurationValue) result.get(associatedTarget.getConfigurationKey())) |
| 298 | .getConfiguration(); |
mstaib | 7c7a701 | 2019-04-23 16:19:09 -0700 | [diff] [blame] | 299 | if (configuration.trimConfigurationsRetroactively()) { |
| 300 | throw new AssertionError("Aspects should NEVER be evaluated in retroactive trimming mode."); |
| 301 | } |
janakr | 171a7eb | 2018-03-26 09:26:53 -0700 | [diff] [blame] | 302 | } |
janakr | f3e6f25 | 2018-01-18 07:45:12 -0800 | [diff] [blame] | 303 | try { |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 304 | associatedConfiguredTargetAndData = |
| 305 | new ConfiguredTargetAndData( |
| 306 | associatedTarget, |
| 307 | targetPkg.getTarget(associatedTarget.getLabel().getName()), |
Googler | 46b285a | 2020-03-06 13:33:24 -0800 | [diff] [blame] | 308 | configuration, |
| 309 | null); |
janakr | f3e6f25 | 2018-01-18 07:45:12 -0800 | [diff] [blame] | 310 | } catch (NoSuchTargetException e) { |
| 311 | throw new IllegalStateException("Name already verified", e); |
| 312 | } |
dslomov | 99ea6b4 | 2017-04-25 17:46:17 +0200 | [diff] [blame] | 313 | |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 314 | if (baseConfiguredTargetValue.getConfiguredTarget().getProvider(AliasProvider.class) != null) { |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 315 | return createAliasAspect( |
| 316 | env, |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 317 | associatedConfiguredTargetAndData.getTarget(), |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 318 | aspect, |
| 319 | key, |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 320 | baseConfiguredTargetValue.getConfiguredTarget()); |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 323 | |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 324 | ImmutableList.Builder<Aspect> aspectPathBuilder = ImmutableList.builder(); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 325 | |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 326 | if (!key.getBaseKeys().isEmpty()) { |
| 327 | // We transitively collect all required aspects to reduce the number of restarts. |
| 328 | // Semantically it is enough to just request key.getBaseKeys(). |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 329 | ImmutableList.Builder<SkyKey> aspectPathSkyKeysBuilder = ImmutableList.builder(); |
| 330 | ImmutableMap<AspectDescriptor, SkyKey> aspectKeys = |
| 331 | getSkyKeysForAspectsAndCollectAspectPath(key.getBaseKeys(), aspectPathSkyKeysBuilder); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 332 | |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 333 | Map<SkyKey, SkyValue> values = env.getValues(aspectKeys.values()); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 334 | if (env.valuesMissing()) { |
| 335 | return null; |
| 336 | } |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 337 | ImmutableList<SkyKey> aspectPathSkyKeys = aspectPathSkyKeysBuilder.build(); |
| 338 | for (SkyKey aspectPathSkyKey : aspectPathSkyKeys) { |
| 339 | aspectPathBuilder.add(((AspectValue) values.get(aspectPathSkyKey)).getAspect()); |
| 340 | } |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 341 | try { |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 342 | associatedTarget = getBaseTarget( |
| 343 | associatedTarget, key.getBaseKeys(), values); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 344 | } catch (DuplicateException e) { |
mjhalupka | 30bf44c | 2018-01-25 08:22:34 -0800 | [diff] [blame] | 345 | env.getListener() |
| 346 | .handle( |
| 347 | Event.error( |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 348 | associatedConfiguredTargetAndData.getTarget().getLocation(), e.getMessage())); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 349 | |
| 350 | throw new AspectFunctionException( |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 351 | new AspectCreationException( |
| 352 | e.getMessage(), associatedTarget.getLabel(), aspectConfiguration)); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 355 | associatedConfiguredTargetAndData = |
| 356 | associatedConfiguredTargetAndData.fromConfiguredTarget(associatedTarget); |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 357 | aspectPathBuilder.add(aspect); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 358 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 359 | SkyframeDependencyResolver resolver = view.createDependencyResolver(env); |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 360 | NestedSetBuilder<Package> transitivePackagesForPackageRootResolution = |
| 361 | storeTransitivePackagesForPackageRootResolution ? NestedSetBuilder.stableOrder() : null; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 362 | |
Michael Staib | 04f6f24 | 2016-03-01 15:40:29 +0000 | [diff] [blame] | 363 | // When getting the dependencies of this hybrid aspect+base target, use the aspect's |
| 364 | // configuration. The configuration of the aspect will always be a superset of the target's |
gregce | e0bbe75 | 2017-09-12 23:58:34 +0200 | [diff] [blame] | 365 | // (trimmed configuration mode: target is part of the aspect's config fragment requirements; |
| 366 | // untrimmed mode: target is the same configuration as the aspect), so the fragments |
Michael Staib | 04f6f24 | 2016-03-01 15:40:29 +0000 | [diff] [blame] | 367 | // required by all dependencies (both those of the aspect and those of the base target) |
| 368 | // will be present this way. |
| 369 | TargetAndConfiguration originalTargetAndAspectConfiguration = |
janakr | f3e6f25 | 2018-01-18 07:45:12 -0800 | [diff] [blame] | 370 | new TargetAndConfiguration( |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 371 | associatedConfiguredTargetAndData.getTarget(), aspectConfiguration); |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 372 | ImmutableList<Aspect> aspectPath = aspectPathBuilder.build(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 373 | try { |
| 374 | // Get the configuration targets that trigger this rule's configurable attributes. |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 375 | ImmutableMap<Label, ConfigMatchingProvider> configConditions = |
| 376 | ConfiguredTargetFunction.getConfigConditions( |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 377 | associatedConfiguredTargetAndData.getTarget(), |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 378 | env, |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 379 | originalTargetAndAspectConfiguration, |
| 380 | transitivePackagesForPackageRootResolution, |
lberki | c67dcec | 2019-01-17 11:24:01 -0800 | [diff] [blame] | 381 | transitiveRootCauses); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 382 | if (configConditions == null) { |
| 383 | // Those targets haven't yet been resolved. |
| 384 | return null; |
| 385 | } |
| 386 | |
John Cater | 2e56f06 | 2017-07-20 19:43:20 +0200 | [diff] [blame] | 387 | // Determine what toolchains are needed by this target. |
jcater | 1f72416 | 2018-08-27 09:16:01 -0700 | [diff] [blame] | 388 | UnloadedToolchainContext unloadedToolchainContext = null; |
| 389 | if (configuration != null) { |
| 390 | // Configuration can be null in the case of aspects applied to input files. In this case, |
| 391 | // there are no chances of toolchains being used, so skip it. |
| 392 | try { |
| 393 | ImmutableSet<Label> requiredToolchains = aspect.getDefinition().getRequiredToolchains(); |
| 394 | unloadedToolchainContext = |
John Cater | e39e5c9 | 2019-04-23 10:28:02 -0700 | [diff] [blame] | 395 | (UnloadedToolchainContext) |
| 396 | env.getValueOrThrow( |
| 397 | UnloadedToolchainContext.key() |
| 398 | .configurationKey(BuildConfigurationValue.key(configuration)) |
| 399 | .requiredToolchainTypeLabels(requiredToolchains) |
| 400 | .shouldSanityCheckConfiguration( |
| 401 | configuration.trimConfigurationsRetroactively()) |
| 402 | .build(), |
| 403 | ToolchainException.class); |
jcater | 1f72416 | 2018-08-27 09:16:01 -0700 | [diff] [blame] | 404 | } catch (ToolchainException e) { |
| 405 | // TODO(katre): better error handling |
| 406 | throw new AspectCreationException( |
| 407 | e.getMessage(), new LabelCause(key.getLabel(), e.getMessage())); |
| 408 | } |
| 409 | if (env.valuesMissing()) { |
| 410 | return null; |
| 411 | } |
John Cater | 2e56f06 | 2017-07-20 19:43:20 +0200 | [diff] [blame] | 412 | } |
| 413 | |
lberki | 102256f | 2019-02-08 01:34:23 -0800 | [diff] [blame] | 414 | OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> depValueMap; |
Dmitry Lomov | 9b2fc5c | 2016-11-11 11:18:48 +0000 | [diff] [blame] | 415 | try { |
John Cater | 2e56f06 | 2017-07-20 19:43:20 +0200 | [diff] [blame] | 416 | depValueMap = |
| 417 | ConfiguredTargetFunction.computeDependencies( |
| 418 | env, |
| 419 | resolver, |
| 420 | originalTargetAndAspectConfiguration, |
| 421 | aspectPath, |
| 422 | configConditions, |
John Cater | 115ff57 | 2019-04-26 09:20:25 -0700 | [diff] [blame] | 423 | unloadedToolchainContext, |
John Cater | 2e56f06 | 2017-07-20 19:43:20 +0200 | [diff] [blame] | 424 | ruleClassProvider, |
| 425 | view.getHostConfiguration(originalTargetAndAspectConfiguration.getConfiguration()), |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 426 | transitivePackagesForPackageRootResolution, |
mjhalupka | 5d7fa7b | 2018-03-22 13:37:38 -0700 | [diff] [blame] | 427 | transitiveRootCauses, |
| 428 | defaultBuildOptions); |
Dmitry Lomov | 9b2fc5c | 2016-11-11 11:18:48 +0000 | [diff] [blame] | 429 | } catch (ConfiguredTargetFunctionException e) { |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 430 | throw new AspectCreationException(e.getMessage(), key.getLabel(), aspectConfiguration); |
Dmitry Lomov | 9b2fc5c | 2016-11-11 11:18:48 +0000 | [diff] [blame] | 431 | } |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 432 | if (depValueMap == null) { |
| 433 | return null; |
| 434 | } |
| 435 | if (!transitiveRootCauses.isEmpty()) { |
| 436 | throw new AspectFunctionException( |
| 437 | new AspectCreationException("Loading failed", transitiveRootCauses.build())); |
| 438 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 439 | |
John Cater | ae4e785 | 2018-07-09 15:02:42 -0700 | [diff] [blame] | 440 | // Load the requested toolchains into the ToolchainContext, now that we have dependencies. |
John Cater | cdfa9ca | 2019-04-05 12:32:09 -0700 | [diff] [blame] | 441 | ResolvedToolchainContext toolchainContext = null; |
jcater | 1f72416 | 2018-08-27 09:16:01 -0700 | [diff] [blame] | 442 | if (unloadedToolchainContext != null) { |
John Cater | 5074514 | 2019-04-16 07:41:24 -0700 | [diff] [blame] | 443 | String targetDescription = |
| 444 | String.format( |
| 445 | "aspect %s applied to %s", |
| 446 | aspect.getDescriptor().getDescription(), |
| 447 | associatedConfiguredTargetAndData.getTarget()); |
lberki | 102256f | 2019-02-08 01:34:23 -0800 | [diff] [blame] | 448 | toolchainContext = |
John Cater | 5074514 | 2019-04-16 07:41:24 -0700 | [diff] [blame] | 449 | ResolvedToolchainContext.load( |
Googler | 4ff2912 | 2019-09-04 21:14:38 -0700 | [diff] [blame] | 450 | targetPkg.getRepositoryMapping(), |
John Cater | 5074514 | 2019-04-16 07:41:24 -0700 | [diff] [blame] | 451 | unloadedToolchainContext, |
| 452 | targetDescription, |
| 453 | depValueMap.get(DependencyResolver.TOOLCHAIN_DEPENDENCY)); |
John Cater | ae4e785 | 2018-07-09 15:02:42 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 456 | return createAspect( |
| 457 | env, |
| 458 | key, |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 459 | aspectPath, |
Dmitry Lomov | 2eb8bdd | 2016-04-06 08:47:30 +0000 | [diff] [blame] | 460 | aspect, |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 461 | aspectFactory, |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 462 | associatedConfiguredTargetAndData, |
cpeyser | a8a61ee | 2018-01-26 09:20:37 -0800 | [diff] [blame] | 463 | aspectConfiguration, |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 464 | configConditions, |
John Cater | 2e56f06 | 2017-07-20 19:43:20 +0200 | [diff] [blame] | 465 | toolchainContext, |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 466 | depValueMap, |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 467 | transitivePackagesForPackageRootResolution); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 468 | } catch (DependencyEvaluationException e) { |
Ulf Adams | 25f03d8 | 2016-01-25 10:31:46 +0000 | [diff] [blame] | 469 | if (e.getCause() instanceof ConfiguredValueCreationException) { |
| 470 | ConfiguredValueCreationException cause = (ConfiguredValueCreationException) e.getCause(); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 471 | throw new AspectFunctionException( |
| 472 | new AspectCreationException(cause.getMessage(), cause.getRootCauses())); |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 473 | } else if (e.getCause() instanceof InconsistentAspectOrderException) { |
| 474 | InconsistentAspectOrderException cause = (InconsistentAspectOrderException) e.getCause(); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 475 | throw new AspectFunctionException( |
| 476 | new AspectCreationException(cause.getMessage(), key.getLabel(), aspectConfiguration)); |
Ulf Adams | 25f03d8 | 2016-01-25 10:31:46 +0000 | [diff] [blame] | 477 | } else { |
| 478 | // Cast to InvalidConfigurationException as a consistency check. If you add any |
| 479 | // DependencyEvaluationException constructors, you may need to change this code, too. |
| 480 | InvalidConfigurationException cause = (InvalidConfigurationException) e.getCause(); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 481 | throw new AspectFunctionException( |
| 482 | new AspectCreationException(cause.getMessage(), key.getLabel(), aspectConfiguration)); |
Ulf Adams | 25f03d8 | 2016-01-25 10:31:46 +0000 | [diff] [blame] | 483 | } |
Marian Lobur | fc567b3 | 2015-09-14 08:44:25 +0000 | [diff] [blame] | 484 | } catch (AspectCreationException e) { |
| 485 | throw new AspectFunctionException(e); |
jcater | 3fed869 | 2019-04-01 13:36:36 -0700 | [diff] [blame] | 486 | } catch (ToolchainException e) { |
| 487 | throw new AspectFunctionException( |
| 488 | new AspectCreationException( |
| 489 | e.getMessage(), new LabelCause(key.getLabel(), e.getMessage()))); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 493 | /** |
| 494 | * Merges aspects defined by {@code aspectKeys} into the {@code target} using |
| 495 | * previously computed {@code values}. |
| 496 | * |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 497 | * @return A {@link ConfiguredTarget} that is a result of a merge. |
| 498 | * @throws DuplicateException if there is a duplicate provider provided by aspects. |
| 499 | */ |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 500 | private ConfiguredTarget getBaseTarget(ConfiguredTarget target, |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 501 | ImmutableList<AspectKey> aspectKeys, |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 502 | Map<SkyKey, SkyValue> values) |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 503 | throws DuplicateException { |
| 504 | ArrayList<ConfiguredAspect> aspectValues = new ArrayList<>(); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 505 | for (AspectKey aspectKey : aspectKeys) { |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 506 | AspectValue aspectValue = (AspectValue) values.get(aspectKey); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 507 | ConfiguredAspect configuredAspect = aspectValue.getConfiguredAspect(); |
| 508 | aspectValues.add(configuredAspect); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 509 | } |
| 510 | return MergedConfiguredTarget.of(target, aspectValues); |
| 511 | } |
| 512 | |
| 513 | /** |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 514 | * Collect all SkyKeys that are needed for a given list of AspectKeys, |
| 515 | * including transitive dependencies. |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 516 | * |
| 517 | * Also collects all propagating aspects in correct order. |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 518 | */ |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 519 | private ImmutableMap<AspectDescriptor, SkyKey> getSkyKeysForAspectsAndCollectAspectPath( |
| 520 | ImmutableList<AspectKey> keys, |
| 521 | ImmutableList.Builder<SkyKey> aspectPathBuilder) { |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 522 | HashMap<AspectDescriptor, SkyKey> result = new HashMap<>(); |
| 523 | for (AspectKey key : keys) { |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 524 | buildSkyKeys(key, result, aspectPathBuilder); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 525 | } |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 526 | return ImmutableMap.copyOf(result); |
Dmitry Lomov | ca9bfa4 | 2016-11-15 13:22:36 +0000 | [diff] [blame] | 527 | } |
| 528 | |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 529 | private void buildSkyKeys(AspectKey key, HashMap<AspectDescriptor, SkyKey> result, |
| 530 | ImmutableList.Builder<SkyKey> aspectPathBuilder) { |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 531 | if (result.containsKey(key.getAspectDescriptor())) { |
| 532 | return; |
| 533 | } |
| 534 | ImmutableList<AspectKey> baseKeys = key.getBaseKeys(); |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 535 | result.put(key.getAspectDescriptor(), key); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 536 | for (AspectKey baseKey : baseKeys) { |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 537 | buildSkyKeys(baseKey, result, aspectPathBuilder); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 538 | } |
dslomov | 039b9ee | 2017-04-11 08:51:30 +0000 | [diff] [blame] | 539 | // Post-order list of aspect SkyKeys gives the order of propagating aspects: |
| 540 | // the aspect comes after all aspects it transitively sees. |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 541 | aspectPathBuilder.add(key); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 542 | } |
dslomov | fa50c3d | 2017-05-08 08:47:44 -0400 | [diff] [blame] | 543 | |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 544 | private SkyValue createAliasAspect( |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 545 | Environment env, |
| 546 | Target originalTarget, |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 547 | Aspect aspect, |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 548 | AspectKey originalKey, |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 549 | ConfiguredTarget configuredTarget) |
| 550 | throws InterruptedException { |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 551 | ImmutableList<Label> aliasChain = configuredTarget.getProvider(AliasProvider.class) |
| 552 | .getAliasChain(); |
| 553 | // Find the next alias in the chain: either the next alias (if there are two) or the name of |
| 554 | // the real configured target. |
| 555 | Label aliasLabel = aliasChain.size() > 1 ? aliasChain.get(1) : configuredTarget.getLabel(); |
| 556 | |
cparsons | 089148b | 2019-09-17 08:14:41 -0700 | [diff] [blame] | 557 | return createAliasAspect(env, originalTarget, aspect, originalKey, aliasLabel); |
| 558 | } |
| 559 | |
| 560 | private AspectValue createAliasAspect( |
| 561 | Environment env, |
| 562 | Target originalTarget, |
| 563 | Aspect aspect, |
| 564 | AspectKey originalKey, |
| 565 | Label aliasLabel) |
| 566 | throws InterruptedException { |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 567 | SkyKey depKey = originalKey.withLabel(aliasLabel); |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 568 | |
| 569 | // Compute the AspectValue of the target the alias refers to (which can itself be either an |
| 570 | // alias or a real target) |
Lukacs Berki | 549bfce | 2016-04-22 15:29:12 +0000 | [diff] [blame] | 571 | AspectValue real = (AspectValue) env.getValue(depKey); |
| 572 | if (env.valuesMissing()) { |
| 573 | return null; |
| 574 | } |
| 575 | |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 576 | NestedSet<Package> transitivePackagesForPackageRootResolution = |
| 577 | storeTransitivePackagesForPackageRootResolution |
| 578 | ? NestedSetBuilder.<Package>stableOrder() |
| 579 | .addTransitive(real.getTransitivePackagesForPackageRootResolution()) |
| 580 | .add(originalTarget.getPackage()) |
| 581 | .build() |
| 582 | : null; |
Lukacs Berki | ea988b6 | 2016-08-30 12:26:18 +0000 | [diff] [blame] | 583 | |
Lukacs Berki | 549bfce | 2016-04-22 15:29:12 +0000 | [diff] [blame] | 584 | return new AspectValue( |
| 585 | originalKey, |
| 586 | aspect, |
| 587 | originalTarget.getLabel(), |
| 588 | originalTarget.getLocation(), |
| 589 | ConfiguredAspect.forAlias(real.getConfiguredAspect()), |
Googler | ce6ad29 | 2019-12-20 10:29:21 -0800 | [diff] [blame] | 590 | transitivePackagesForPackageRootResolution); |
Lukacs Berki | 549bfce | 2016-04-22 15:29:12 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 593 | @Nullable |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 594 | private AspectValue createAspect( |
| 595 | Environment env, |
| 596 | AspectKey key, |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 597 | ImmutableList<Aspect> aspectPath, |
Dmitry Lomov | 2eb8bdd | 2016-04-06 08:47:30 +0000 | [diff] [blame] | 598 | Aspect aspect, |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 599 | ConfiguredAspectFactory aspectFactory, |
janakr | 9c10140 | 2018-03-10 06:48:59 -0800 | [diff] [blame] | 600 | ConfiguredTargetAndData associatedTarget, |
Michael Staib | 04f6f24 | 2016-03-01 15:40:29 +0000 | [diff] [blame] | 601 | BuildConfiguration aspectConfiguration, |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 602 | ImmutableMap<Label, ConfigMatchingProvider> configConditions, |
John Cater | cdfa9ca | 2019-04-05 12:32:09 -0700 | [diff] [blame] | 603 | ResolvedToolchainContext toolchainContext, |
lberki | 102256f | 2019-02-08 01:34:23 -0800 | [diff] [blame] | 604 | OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> directDeps, |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 605 | @Nullable NestedSetBuilder<Package> transitivePackagesForPackageRootResolution) |
Dmitry Lomov | 0b832ce | 2015-10-20 10:03:14 +0000 | [diff] [blame] | 606 | throws AspectFunctionException, InterruptedException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 607 | SkyframeBuildView view = buildViewProvider.getSkyframeBuildView(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 608 | |
| 609 | StoredEventHandler events = new StoredEventHandler(); |
| 610 | CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment( |
Michael Staib | 04f6f24 | 2016-03-01 15:40:29 +0000 | [diff] [blame] | 611 | key, false, events, env, aspectConfiguration); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 612 | if (env.valuesMissing()) { |
| 613 | return null; |
| 614 | } |
| 615 | |
Dmitry Lomov | 6cd9897 | 2017-03-01 15:44:00 +0000 | [diff] [blame] | 616 | ConfiguredAspect configuredAspect; |
cparsons | 089148b | 2019-09-17 08:14:41 -0700 | [diff] [blame] | 617 | if (aspect.getDefinition().applyToGeneratingRules() |
| 618 | && associatedTarget.getTarget() instanceof OutputFile) { |
| 619 | OutputFile outputFile = (OutputFile) associatedTarget.getTarget(); |
| 620 | Label label = outputFile.getGeneratingRule().getLabel(); |
| 621 | return createAliasAspect(env, associatedTarget.getTarget(), aspect, key, label); |
| 622 | } else if (AspectResolver.aspectMatchesConfiguredTarget(associatedTarget, aspect)) { |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 623 | try { |
| 624 | CurrentRuleTracker.beginConfiguredAspect(aspect.getAspectClass()); |
| 625 | configuredAspect = |
| 626 | view.getConfiguredTargetFactory() |
| 627 | .createAspect( |
| 628 | analysisEnvironment, |
| 629 | associatedTarget, |
| 630 | aspectPath, |
| 631 | aspectFactory, |
| 632 | aspect, |
| 633 | directDeps, |
| 634 | configConditions, |
| 635 | toolchainContext, |
| 636 | aspectConfiguration, |
janakr | eaff19c | 2019-01-31 13:59:40 -0800 | [diff] [blame] | 637 | view.getHostConfiguration(aspectConfiguration), |
| 638 | key); |
ulfjack | 3740768 | 2019-09-17 06:30:49 -0700 | [diff] [blame] | 639 | } catch (MissingDepException e) { |
| 640 | Preconditions.checkState(env.valuesMissing()); |
| 641 | return null; |
tomlu | 72642a2 | 2017-10-18 06:23:14 +0200 | [diff] [blame] | 642 | } finally { |
| 643 | CurrentRuleTracker.endConfiguredAspect(); |
| 644 | } |
Dmitry Lomov | 6cd9897 | 2017-03-01 15:44:00 +0000 | [diff] [blame] | 645 | } else { |
| 646 | configuredAspect = ConfiguredAspect.forNonapplicableTarget(aspect.getDescriptor()); |
| 647 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 648 | |
| 649 | events.replayOn(env.getListener()); |
| 650 | if (events.hasErrors()) { |
| 651 | analysisEnvironment.disable(associatedTarget.getTarget()); |
janakr | 043acd9 | 2020-02-28 18:59:06 -0800 | [diff] [blame] | 652 | String msg = "Analysis of target '" + associatedTarget.getTarget().getLabel() + "' failed"; |
janakr | f3e6f25 | 2018-01-18 07:45:12 -0800 | [diff] [blame] | 653 | throw new AspectFunctionException( |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 654 | new AspectCreationException(msg, key.getLabel(), aspectConfiguration)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 655 | } |
| 656 | Preconditions.checkState(!analysisEnvironment.hasErrors(), |
| 657 | "Analysis environment hasError() but no errors reported"); |
| 658 | |
| 659 | if (env.valuesMissing()) { |
| 660 | return null; |
| 661 | } |
| 662 | |
| 663 | analysisEnvironment.disable(associatedTarget.getTarget()); |
Dmitry Lomov | b487ac6 | 2015-11-09 13:09:12 +0000 | [diff] [blame] | 664 | Preconditions.checkNotNull(configuredAspect); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 665 | |
| 666 | return new AspectValue( |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 667 | key, |
Dmitry Lomov | 2eb8bdd | 2016-04-06 08:47:30 +0000 | [diff] [blame] | 668 | aspect, |
janakr | f3e6f25 | 2018-01-18 07:45:12 -0800 | [diff] [blame] | 669 | associatedTarget.getTarget().getLabel(), |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 670 | associatedTarget.getTarget().getLocation(), |
Dmitry Lomov | b487ac6 | 2015-11-09 13:09:12 +0000 | [diff] [blame] | 671 | configuredAspect, |
janakr | 931d285 | 2017-12-15 13:48:29 -0800 | [diff] [blame] | 672 | transitivePackagesForPackageRootResolution == null |
| 673 | ? null |
Googler | ce6ad29 | 2019-12-20 10:29:21 -0800 | [diff] [blame] | 674 | : transitivePackagesForPackageRootResolution.build()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 675 | } |
| 676 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 677 | @Override |
| 678 | public String extractTag(SkyKey skyKey) { |
Michael Staib | 2707a88 | 2016-09-16 21:06:40 +0000 | [diff] [blame] | 679 | AspectKey aspectKey = (AspectKey) skyKey.argument(); |
| 680 | return Label.print(aspectKey.getLabel()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 681 | } |
Marian Lobur | c62faba | 2015-09-09 10:08:06 +0000 | [diff] [blame] | 682 | |
jcater | a8ee68a | 2020-04-08 08:36:24 -0700 | [diff] [blame] | 683 | /** An exception indicating that there was a problem creating an aspect. */ |
| 684 | public static final class AspectCreationException extends Exception |
| 685 | implements SaneAnalysisException { |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 686 | private static ConfigurationId toId(BuildConfiguration config) { |
janakr | 3ca2468 | 2020-04-01 09:12:03 -0700 | [diff] [blame] | 687 | return config == null ? null : config.getEventId().getConfiguration(); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 688 | } |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 689 | |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 690 | private final NestedSet<Cause> causes; |
Ulf Adams | 25f03d8 | 2016-01-25 10:31:46 +0000 | [diff] [blame] | 691 | |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 692 | public AspectCreationException(String message, NestedSet<Cause> causes) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 693 | super(message); |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 694 | this.causes = causes; |
Ulf Adams | 25f03d8 | 2016-01-25 10:31:46 +0000 | [diff] [blame] | 695 | } |
| 696 | |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 697 | public AspectCreationException( |
| 698 | String message, Label currentTarget, @Nullable BuildConfiguration configuration) { |
| 699 | this( |
| 700 | message, |
| 701 | NestedSetBuilder.<Cause>stableOrder() |
| 702 | .add(new AnalysisFailedCause(currentTarget, toId(configuration), message)) |
| 703 | .build()); |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 704 | } |
| 705 | |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 706 | public AspectCreationException(String message, Label currentTarget) { |
| 707 | this(message, currentTarget, null); |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 708 | } |
| 709 | |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 710 | public AspectCreationException(String message, Cause cause) { |
| 711 | this(message, NestedSetBuilder.<Cause>stableOrder().add(cause).build()); |
Ulf Adams | 8490173 | 2016-01-28 15:05:16 +0000 | [diff] [blame] | 712 | } |
| 713 | |
ulfjack | 904a8d6 | 2018-05-29 05:17:35 -0700 | [diff] [blame] | 714 | public NestedSet<Cause> getCauses() { |
| 715 | return causes; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
tomlu | 39a0a38 | 2018-06-22 09:43:23 -0700 | [diff] [blame] | 719 | /** Used to indicate errors during the computation of an {@link AspectValue}. */ |
| 720 | public static final class AspectFunctionException extends SkyFunctionException { |
Ulf Adams | 9e16f0a | 2016-01-25 12:43:32 +0000 | [diff] [blame] | 721 | public AspectFunctionException(NoSuchThingException e) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 722 | super(e, Transience.PERSISTENT); |
| 723 | } |
| 724 | |
Ulf Adams | 9e16f0a | 2016-01-25 12:43:32 +0000 | [diff] [blame] | 725 | public AspectFunctionException(AspectCreationException e) { |
| 726 | super(e, Transience.PERSISTENT); |
Ulf Adams | d55d7af | 2016-01-19 11:03:22 +0000 | [diff] [blame] | 727 | } |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 728 | |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 729 | public AspectFunctionException(ActionConflictException cause) { |
Dmitry Lomov | d83af9e | 2017-02-23 15:44:23 +0000 | [diff] [blame] | 730 | super(cause, Transience.PERSISTENT); |
| 731 | } |
Ulf Adams | d55d7af | 2016-01-19 11:03:22 +0000 | [diff] [blame] | 732 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 733 | } |