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 | |
| 17 | /** |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 18 | * Contains rolled-up data about the transitive closure of a configured target. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 19 | * |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 20 | * For more information about how analysis works, see |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 21 | * {@link com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory}. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | * TransitiveInfoProviders need to be serializable, and for that reason they must conform to |
| 23 | * the following restrictions: |
| 24 | * |
| 25 | * <ul> |
| 26 | * <li>The provider interface must directly extend {@code TransitiveInfoProvider}. |
| 27 | * <li>Every method must return immutable data.</li> |
| 28 | * <li>Every method must return the same object if called multiple times with the same |
| 29 | * arguments.</li> |
| 30 | * <li>Overloading a method name multiple times is forbidden.</li> |
| 31 | * <li>The return type of a method must satisfy one of the following conditions: |
| 32 | * <ul> |
Han-Wen Nienhuys | 18740ae | 2015-06-11 14:57:17 +0000 | [diff] [blame] | 33 | * <li>It must be from the set of {String, Integer, int, Boolean, bool, Label, PathFragment, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | * Artifact}, OR</li> |
Han-Wen Nienhuys | 18740ae | 2015-06-11 14:57:17 +0000 | [diff] [blame] | 35 | * <li>it must be an ImmutableList/List/Collection/Iterable of T, where T is either |
Adam Michael | f3c3210 | 2016-08-19 17:24:33 +0000 | [diff] [blame] | 36 | * one of the types above with a default serializer or T implements ValueSerializer, OR</li> |
Han-Wen Nienhuys | 18740ae | 2015-06-11 14:57:17 +0000 | [diff] [blame] | 37 | * <li>it must be serializable (TBD)</li> |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 38 | * </ul> |
| 39 | * <li>If the method takes arguments, it must declare a custom serializer (TBD).</li> |
| 40 | * </ul> |
| 41 | * |
| 42 | * <p>Some typical uses of this interface are: |
| 43 | * <ul> |
| 44 | * <li>The set of Python source files in the transitive closure of this rule |
| 45 | * <li>The set of declared C++ header files in the transitive closure |
| 46 | * <li>The files that need to be built when the target is mentioned on the command line |
| 47 | * </ul> |
| 48 | * |
| 49 | * <p>Note that if implemented naively, this would result in the memory requirements |
| 50 | * being O(n^2): in a long dependency chain, if every target adds one single artifact, storing the |
| 51 | * transitive closures of every rule would take 1+2+3+...+n-1+n = O(n^2) memory. |
| 52 | * |
Lukacs Berki | 2300cd6 | 2016-05-19 11:06:37 +0000 | [diff] [blame] | 53 | * <p>In order to avoid this, we introduce the concept of nested sets, {@link |
| 54 | * com.google.devtools.build.lib.collect.nestedset.NestedSet}. A nested set is an immutable |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 55 | * data structure that can contain direct members and other nested sets (recursively). Nested sets |
| 56 | * are iterable and can be flattened into ordered sets, where the order depends on which |
| 57 | * implementation of NestedSet you pick. |
| 58 | * |
| 59 | * @see TransitiveInfoCollection |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 60 | * @see com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 61 | */ |
| 62 | public interface TransitiveInfoProvider { |
dslomov | f6a7e5a | 2017-07-05 07:23:31 -0400 | [diff] [blame] | 63 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 64 | } |