blob: 75f253c519092208635b8ecc1c62441d5b889e30 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.analysis;
16
cparsons15c9ec42018-03-01 14:06:51 -080017import com.google.devtools.build.lib.actions.Artifact;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
janakr171a7eb2018-03-26 09:26:53 -070019import com.google.devtools.build.lib.analysis.configuredtargets.InputFileConfiguredTarget;
20import com.google.devtools.build.lib.analysis.configuredtargets.PackageGroupConfiguredTarget;
Lukacs Berki6e91eb92015-09-21 09:12:37 +000021import com.google.devtools.build.lib.cmdline.Label;
cparsons15c9ec42018-03-01 14:06:51 -080022import com.google.devtools.build.lib.collect.nestedset.NestedSet;
23import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
24import com.google.devtools.build.lib.collect.nestedset.Order;
dslomovc13bb392017-08-02 23:29:54 +020025import com.google.devtools.build.lib.packages.RequiredProviders;
janakr171a7eb2018-03-26 09:26:53 -070026import com.google.devtools.build.lib.skyframe.BuildConfigurationValue;
cparsonsabbb9002018-05-11 11:54:17 -070027import com.google.devtools.build.lib.skylarkbuildapi.TransitiveInfoCollectionApi;
Vladimir Moskva748ba862016-09-20 13:46:11 +000028import com.google.devtools.build.lib.syntax.SkylarkIndexable;
cparsons15c9ec42018-03-01 14:06:51 -080029import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010030import javax.annotation.Nullable;
31
32/**
Lukacs Berki2300cd62016-05-19 11:06:37 +000033 * Multiple {@link TransitiveInfoProvider}s bundled together.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010034 *
Dmitry Lomov34cdae32016-06-28 16:13:35 +000035 * <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
ulfjack26d0e492017-08-07 13:42:33 +020037 * com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory}.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010038 *
Dmitry Lomov34cdae32016-06-28 16:13:35 +000039 * <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 Nienhuysd08b27f2015-02-25 16:45:20 +010043 *
ulfjack26d0e492017-08-07 13:42:33 +020044 * @see com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010045 * @see TransitiveInfoProvider
46 */
cparsonsabbb9002018-05-11 11:54:17 -070047public interface TransitiveInfoCollection
tomlu64416ce2018-10-02 12:46:08 -070048 extends SkylarkIndexable, ProviderCollection, TransitiveInfoCollectionApi {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010049
cparsonsabbb9002018-05-11 11:54:17 -070050 @Override
cparsons15c9ec42018-03-01 14:06:51 -080051 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 Nienhuysd08b27f2015-02-25 16:45:20 +010059 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060 * Returns the label associated with this prerequisite.
61 */
62 Label getLabel();
63
64 /**
janakr171a7eb2018-03-26 09:26:53 -070065 * 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 Nienhuysd08b27f2015-02-25 16:45:20 +010069 */
janakr171a7eb2018-03-26 09:26:53 -070070 @Nullable
janakr9c4fa4a2018-03-28 11:37:34 -070071 BuildConfigurationValue.Key getConfigurationKey();
dslomovc13bb392017-08-02 23:29:54 +020072
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 Nienhuysd08b27f2015-02-25 16:45:20 +010093}