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 | |
cparsons | 15c9ec4 | 2018-03-01 14:06:51 -0800 | [diff] [blame] | 17 | import com.google.devtools.build.lib.actions.Artifact; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
janakr | 171a7eb | 2018-03-26 09:26:53 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.analysis.configuredtargets.InputFileConfiguredTarget; |
| 20 | import com.google.devtools.build.lib.analysis.configuredtargets.PackageGroupConfiguredTarget; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 21 | import com.google.devtools.build.lib.cmdline.Label; |
cparsons | 15c9ec4 | 2018-03-01 14:06:51 -0800 | [diff] [blame] | 22 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
| 23 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 24 | import com.google.devtools.build.lib.collect.nestedset.Order; |
dslomov | c13bb39 | 2017-08-02 23:29:54 +0200 | [diff] [blame] | 25 | import com.google.devtools.build.lib.packages.RequiredProviders; |
janakr | 171a7eb | 2018-03-26 09:26:53 -0700 | [diff] [blame] | 26 | import com.google.devtools.build.lib.skyframe.BuildConfigurationValue; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 27 | import com.google.devtools.build.lib.skylarkbuildapi.TransitiveInfoCollectionApi; |
Vladimir Moskva | 748ba86 | 2016-09-20 13:46:11 +0000 | [diff] [blame] | 28 | import com.google.devtools.build.lib.syntax.SkylarkIndexable; |
cparsons | 15c9ec4 | 2018-03-01 14:06:51 -0800 | [diff] [blame] | 29 | import com.google.devtools.build.lib.syntax.SkylarkNestedSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | import javax.annotation.Nullable; |
| 31 | |
| 32 | /** |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 33 | * Multiple {@link TransitiveInfoProvider}s bundled together. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | * |
Dmitry Lomov | 34cdae3 | 2016-06-28 16:13:35 +0000 | [diff] [blame] | 35 | * <p>Represents the information made available by a {@link ConfiguredTarget} to other ones that |
| 36 | * depend on it. For more information about the analysis phase, see {@link |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 37 | * com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory}. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 38 | * |
Dmitry Lomov | 34cdae3 | 2016-06-28 16:13:35 +0000 | [diff] [blame] | 39 | * <p>Implementations of build rules should <b>not</b> hold on to references to the {@link |
| 40 | * TransitiveInfoCollection}s representing their direct prerequisites in order to reduce their |
| 41 | * memory footprint (otherwise, the referenced object could refer one of its direct dependencies in |
| 42 | * turn, thereby making the size of the objects reachable from a single instance unbounded). |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | * |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 44 | * @see com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | * @see TransitiveInfoProvider |
| 46 | */ |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 47 | public interface TransitiveInfoCollection |
tomlu | 64416ce | 2018-10-02 12:46:08 -0700 | [diff] [blame] | 48 | extends SkylarkIndexable, ProviderCollection, TransitiveInfoCollectionApi { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 49 | |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 50 | @Override |
cparsons | 15c9ec4 | 2018-03-01 14:06:51 -0800 | [diff] [blame] | 51 | default SkylarkNestedSet outputGroup(String group) { |
| 52 | OutputGroupInfo provider = OutputGroupInfo.get(this); |
| 53 | NestedSet<Artifact> result = provider != null |
| 54 | ? provider.getOutputGroup(group) |
| 55 | : NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER); |
| 56 | return SkylarkNestedSet.of(Artifact.class, result); |
| 57 | } |
| 58 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 59 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 60 | * Returns the label associated with this prerequisite. |
| 61 | */ |
| 62 | Label getLabel(); |
| 63 | |
| 64 | /** |
janakr | 171a7eb | 2018-03-26 09:26:53 -0700 | [diff] [blame] | 65 | * Returns the {@link BuildConfigurationValue.Key} naming the {@link BuildConfiguration} for which |
| 66 | * this transitive info collection is defined. Configuration is defined for all configured targets |
| 67 | * with exception of {@link InputFileConfiguredTarget} and {@link PackageGroupConfiguredTarget} |
| 68 | * for which it is always <b>null</b>. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 69 | */ |
janakr | 171a7eb | 2018-03-26 09:26:53 -0700 | [diff] [blame] | 70 | @Nullable |
janakr | 9c4fa4a | 2018-03-28 11:37:34 -0700 | [diff] [blame] | 71 | BuildConfigurationValue.Key getConfigurationKey(); |
dslomov | c13bb39 | 2017-08-02 23:29:54 +0200 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Checks whether this {@link TransitiveInfoCollection} satisfies given {@link RequiredProviders}. |
| 75 | */ |
| 76 | default boolean satisfies(RequiredProviders providers) { |
| 77 | return providers.isSatisfiedBy( |
| 78 | aClass -> getProvider(aClass.asSubclass(TransitiveInfoProvider.class)) != null, |
| 79 | id -> this.get(id) != null); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns providers that this {@link TransitiveInfoCollection} misses from a given {@link |
| 84 | * RequiredProviders}. |
| 85 | * |
| 86 | * <p>If none are missing, returns {@link RequiredProviders} that accept any set of providers. |
| 87 | */ |
| 88 | default RequiredProviders missingProviders(RequiredProviders providers) { |
| 89 | return providers.getMissing( |
| 90 | aClass -> getProvider(aClass.asSubclass(TransitiveInfoProvider.class)) != null, |
| 91 | id -> this.get(id) != null); |
| 92 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 93 | } |