Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 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 android |
| 16 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 17 | import ( |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 18 | "fmt" |
Colin Cross | cefa94bd | 2019-06-03 15:07:03 -0700 | [diff] [blame] | 19 | "sort" |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 20 | "strconv" |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 21 | "strings" |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 22 | "sync" |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint" |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 25 | ) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 26 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 27 | var ( |
| 28 | SdkVersion_Android10 = uncheckedFinalApiLevel(29) |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 29 | ) |
| 30 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 31 | // ApexInfo describes the metadata common to all modules in an apexBundle. |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 32 | type ApexInfo struct { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 33 | // Name of the apex variation that this module is mutated into, or "" for |
| 34 | // a platform variant. Note that a module can be included in multiple APEXes, |
| 35 | // in which case, the module is mutated into one or more variants, each of |
| 36 | // which is for one or more APEXes. |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 37 | ApexVariationName string |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 38 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 39 | // Serialized ApiLevel. Use via MinSdkVersion() method. Cannot be stored in |
| 40 | // its struct form because this is cloned into properties structs, and |
| 41 | // ApiLevel has private members. |
| 42 | MinSdkVersionStr string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 43 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 44 | // True if the module comes from an updatable APEX. |
| 45 | Updatable bool |
| 46 | RequiredSdks SdkRefs |
| 47 | |
| 48 | InApexes []string |
| 49 | ApexContents []*ApexContents |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 52 | var ApexInfoProvider = blueprint.NewMutatorProvider(ApexInfo{}, "apex") |
| 53 | |
Colin Cross | 9f720ce | 2020-10-02 10:26:04 -0700 | [diff] [blame] | 54 | func (i ApexInfo) mergedName(ctx PathContext) string { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 55 | name := "apex" + strconv.Itoa(i.MinSdkVersion(ctx).FinalOrFutureInt()) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 56 | for _, sdk := range i.RequiredSdks { |
| 57 | name += "_" + sdk.Name + "_" + sdk.Version |
| 58 | } |
| 59 | return name |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Colin Cross | 9f720ce | 2020-10-02 10:26:04 -0700 | [diff] [blame] | 62 | func (this *ApexInfo) MinSdkVersion(ctx PathContext) ApiLevel { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 63 | return ApiLevelOrPanic(ctx, this.MinSdkVersionStr) |
| 64 | } |
| 65 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 66 | func (i ApexInfo) IsForPlatform() bool { |
| 67 | return i.ApexVariationName == "" |
| 68 | } |
| 69 | |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 70 | func (i ApexInfo) InApex(apex string) bool { |
| 71 | for _, a := range i.InApexes { |
| 72 | if a == apex { |
| 73 | return true |
| 74 | } |
| 75 | } |
| 76 | return false |
| 77 | } |
| 78 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 79 | // ApexTestForInfo stores the contents of APEXes for which this module is a test and thus has |
| 80 | // access to APEX internals. |
| 81 | type ApexTestForInfo struct { |
| 82 | ApexContents []*ApexContents |
| 83 | } |
| 84 | |
| 85 | var ApexTestForInfoProvider = blueprint.NewMutatorProvider(ApexTestForInfo{}, "apex_test_for") |
| 86 | |
Paul Duffin | 923e8a5 | 2020-03-30 15:33:32 +0100 | [diff] [blame] | 87 | // Extracted from ApexModule to make it easier to define custom subsets of the |
| 88 | // ApexModule interface and improve code navigation within the IDE. |
| 89 | type DepIsInSameApex interface { |
| 90 | // DepIsInSameApex tests if the other module 'dep' is installed to the same |
| 91 | // APEX as this module |
| 92 | DepIsInSameApex(ctx BaseModuleContext, dep Module) bool |
| 93 | } |
| 94 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 95 | // ApexModule is the interface that a module type is expected to implement if |
| 96 | // the module has to be built differently depending on whether the module |
| 97 | // is destined for an apex or not (installed to one of the regular partitions). |
| 98 | // |
| 99 | // Native shared libraries are one such module type; when it is built for an |
| 100 | // APEX, it should depend only on stable interfaces such as NDK, stable AIDL, |
| 101 | // or C APIs from other APEXs. |
| 102 | // |
| 103 | // A module implementing this interface will be mutated into multiple |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 104 | // variations by apex.apexMutator if it is directly or indirectly included |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 105 | // in one or more APEXs. Specifically, if a module is included in apex.foo and |
| 106 | // apex.bar then three apex variants are created: platform, apex.foo and |
| 107 | // apex.bar. The platform variant is for the regular partitions |
| 108 | // (e.g., /system or /vendor, etc.) while the other two are for the APEXs, |
| 109 | // respectively. |
| 110 | type ApexModule interface { |
| 111 | Module |
Paul Duffin | 923e8a5 | 2020-03-30 15:33:32 +0100 | [diff] [blame] | 112 | DepIsInSameApex |
| 113 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 114 | apexModuleBase() *ApexModuleBase |
| 115 | |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 116 | // Marks that this module should be built for the specified APEX. |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 117 | // Call this before apex.apexMutator is run. |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 118 | BuildForApex(apex ApexInfo) |
Jiyong Park | f760cae | 2020-02-12 07:53:12 +0900 | [diff] [blame] | 119 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 120 | // Returns true if this module is present in any APEXes |
| 121 | // directly or indirectly. |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 122 | // Call this after apex.apexMutator is run. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 123 | InAnyApex() bool |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 124 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 125 | // Returns true if this module is directly in any APEXes. |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 126 | // Call this after apex.apexMutator is run. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 127 | DirectlyInAnyApex() bool |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 128 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 129 | // Returns true if any variant of this module is directly in any APEXes. |
| 130 | // Call this after apex.apexMutator is run. |
| 131 | AnyVariantDirectlyInAnyApex() bool |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 132 | |
| 133 | // Tests if this module could have APEX variants. APEX variants are |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 134 | // created only for the modules that returns true here. This is useful |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 135 | // for not creating APEX variants for certain types of shared libraries |
| 136 | // such as NDK stubs. |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 137 | CanHaveApexVariants() bool |
| 138 | |
| 139 | // Tests if this module can be installed to APEX as a file. For example, |
| 140 | // this would return true for shared libs while return false for static |
| 141 | // libs. |
| 142 | IsInstallableToApex() bool |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 143 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 144 | // Tests if this module is available for the specified APEX or ":platform" |
| 145 | AvailableFor(what string) bool |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 146 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 147 | // Return true if this module is not available to platform (i.e. apex_available |
| 148 | // property doesn't have "//apex_available:platform"), or shouldn't be available |
| 149 | // to platform, which is the case when this module depends on other module that |
| 150 | // isn't available to platform. |
| 151 | NotAvailableForPlatform() bool |
| 152 | |
| 153 | // Mark that this module is not available to platform. Set by the |
| 154 | // check-platform-availability mutator in the apex package. |
| 155 | SetNotAvailableForPlatform() |
| 156 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 157 | // List of APEXes that this module tests. The module has access to |
| 158 | // the private part of the listed APEXes even when it is not included in the |
| 159 | // APEXes. |
| 160 | TestFor() []string |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 161 | |
| 162 | // Returns nil if this module supports sdkVersion |
| 163 | // Otherwise, returns error with reason |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 164 | ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 165 | |
| 166 | // Returns true if this module needs a unique variation per apex, for example if |
| 167 | // use_apex_name_macro is set. |
| 168 | UniqueApexVariations() bool |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | type ApexProperties struct { |
Martin Stjernholm | 06ca82d | 2020-01-17 13:02:56 +0000 | [diff] [blame] | 172 | // Availability of this module in APEXes. Only the listed APEXes can contain |
| 173 | // this module. If the module has stubs then other APEXes and the platform may |
| 174 | // access it through them (subject to visibility). |
| 175 | // |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 176 | // "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX. |
| 177 | // "//apex_available:platform" refers to non-APEX partitions like "system.img". |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 178 | // "com.android.gki.*" matches any APEX module name with the prefix "com.android.gki.". |
Jiyong Park | 9a1e14e | 2020-02-13 02:30:45 +0900 | [diff] [blame] | 179 | // Default is ["//apex_available:platform"]. |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 180 | Apex_available []string |
| 181 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 182 | // AnyVariantDirectlyInAnyApex is true in the primary variant of a module if _any_ variant |
| 183 | // of the module is directly in any apex. This includes host, arch, asan, etc. variants. |
| 184 | // It is unused in any variant that is not the primary variant. |
| 185 | // Ideally this wouldn't be used, as it incorrectly mixes arch variants if only one arch |
| 186 | // is in an apex, but a few places depend on it, for example when an ASAN variant is |
| 187 | // created before the apexMutator. |
| 188 | AnyVariantDirectlyInAnyApex bool `blueprint:"mutated"` |
| 189 | |
| 190 | // DirectlyInAnyApex is true if any APEX variant (including the "" variant used for the |
| 191 | // platform) of this module is directly in any APEX. |
| 192 | DirectlyInAnyApex bool `blueprint:"mutated"` |
| 193 | |
| 194 | // DirectlyInAnyApex is true if any APEX variant (including the "" variant used for the |
| 195 | // platform) of this module is directly or indirectly in any APEX. |
| 196 | InAnyApex bool `blueprint:"mutated"` |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 197 | |
| 198 | NotAvailableForPlatform bool `blueprint:"mutated"` |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 199 | |
| 200 | UniqueApexVariationsForDeps bool `blueprint:"mutated"` |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 201 | } |
| 202 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 203 | // Marker interface that identifies dependencies that are excluded from APEX |
| 204 | // contents. |
| 205 | type ExcludeFromApexContentsTag interface { |
| 206 | blueprint.DependencyTag |
| 207 | |
| 208 | // Method that differentiates this interface from others. |
| 209 | ExcludeFromApexContents() |
| 210 | } |
| 211 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 212 | // Marker interface that identifies dependencies that should inherit the DirectlyInAnyApex |
| 213 | // state from the parent to the child. For example, stubs libraries are marked as |
| 214 | // DirectlyInAnyApex if their implementation is in an apex. |
| 215 | type CopyDirectlyInAnyApexTag interface { |
| 216 | blueprint.DependencyTag |
| 217 | |
| 218 | CopyDirectlyInAnyApex() |
| 219 | } |
| 220 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 221 | // Provides default implementation for the ApexModule interface. APEX-aware |
| 222 | // modules are expected to include this struct and call InitApexModule(). |
| 223 | type ApexModuleBase struct { |
| 224 | ApexProperties ApexProperties |
| 225 | |
| 226 | canHaveApexVariants bool |
Colin Cross | cefa94bd | 2019-06-03 15:07:03 -0700 | [diff] [blame] | 227 | |
| 228 | apexVariationsLock sync.Mutex // protects apexVariations during parallel apexDepsMutator |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 229 | apexVariations []ApexInfo |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase { |
| 233 | return m |
| 234 | } |
| 235 | |
Paul Duffin | befa4b9 | 2020-03-04 14:22:45 +0000 | [diff] [blame] | 236 | func (m *ApexModuleBase) ApexAvailable() []string { |
| 237 | return m.ApexProperties.Apex_available |
| 238 | } |
| 239 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 240 | func (m *ApexModuleBase) TestFor() []string { |
| 241 | // To be implemented by concrete types inheriting ApexModuleBase |
| 242 | return nil |
| 243 | } |
| 244 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 245 | func (m *ApexModuleBase) UniqueApexVariations() bool { |
| 246 | return false |
| 247 | } |
| 248 | |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 249 | func (m *ApexModuleBase) BuildForApex(apex ApexInfo) { |
Colin Cross | cefa94bd | 2019-06-03 15:07:03 -0700 | [diff] [blame] | 250 | m.apexVariationsLock.Lock() |
| 251 | defer m.apexVariationsLock.Unlock() |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 252 | for _, v := range m.apexVariations { |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 253 | if v.ApexVariationName == apex.ApexVariationName { |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 254 | return |
Jiyong Park | f760cae | 2020-02-12 07:53:12 +0900 | [diff] [blame] | 255 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 256 | } |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 257 | m.apexVariations = append(m.apexVariations, apex) |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 258 | } |
| 259 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 260 | func (m *ApexModuleBase) DirectlyInAnyApex() bool { |
| 261 | return m.ApexProperties.DirectlyInAnyApex |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 262 | } |
| 263 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 264 | func (m *ApexModuleBase) AnyVariantDirectlyInAnyApex() bool { |
| 265 | return m.ApexProperties.AnyVariantDirectlyInAnyApex |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 268 | func (m *ApexModuleBase) InAnyApex() bool { |
| 269 | return m.ApexProperties.InAnyApex |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | func (m *ApexModuleBase) CanHaveApexVariants() bool { |
| 273 | return m.canHaveApexVariants |
| 274 | } |
| 275 | |
| 276 | func (m *ApexModuleBase) IsInstallableToApex() bool { |
| 277 | // should be overriden if needed |
| 278 | return false |
| 279 | } |
| 280 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 281 | const ( |
Jiyong Park | b02bb40 | 2019-12-03 00:43:57 +0900 | [diff] [blame] | 282 | AvailableToPlatform = "//apex_available:platform" |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 283 | AvailableToAnyApex = "//apex_available:anyapex" |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 284 | AvailableToGkiApex = "com.android.gki.*" |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 285 | ) |
| 286 | |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 287 | func CheckAvailableForApex(what string, apex_available []string) bool { |
| 288 | if len(apex_available) == 0 { |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 289 | // apex_available defaults to ["//apex_available:platform"], |
| 290 | // which means 'available to the platform but no apexes'. |
| 291 | return what == AvailableToPlatform |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 292 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 293 | return InList(what, apex_available) || |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 294 | (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available)) || |
| 295 | (strings.HasPrefix(what, "com.android.gki.") && InList(AvailableToGkiApex, apex_available)) |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | func (m *ApexModuleBase) AvailableFor(what string) bool { |
| 299 | return CheckAvailableForApex(what, m.ApexProperties.Apex_available) |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 300 | } |
| 301 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 302 | func (m *ApexModuleBase) NotAvailableForPlatform() bool { |
| 303 | return m.ApexProperties.NotAvailableForPlatform |
| 304 | } |
| 305 | |
| 306 | func (m *ApexModuleBase) SetNotAvailableForPlatform() { |
| 307 | m.ApexProperties.NotAvailableForPlatform = true |
| 308 | } |
| 309 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 310 | func (m *ApexModuleBase) DepIsInSameApex(ctx BaseModuleContext, dep Module) bool { |
| 311 | // By default, if there is a dependency from A to B, we try to include both in the same APEX, |
| 312 | // unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning true. |
| 313 | // This is overridden by some module types like apex.ApexBundle, cc.Module, java.Module, etc. |
| 314 | return true |
| 315 | } |
| 316 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 317 | func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) { |
| 318 | for _, n := range m.ApexProperties.Apex_available { |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 319 | if n == AvailableToPlatform || n == AvailableToAnyApex || n == AvailableToGkiApex { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 320 | continue |
| 321 | } |
Orion Hodson | 4b5438a | 2019-10-08 10:40:51 +0100 | [diff] [blame] | 322 | if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 323 | mctx.PropertyErrorf("apex_available", "%q is not a valid module name", n) |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 328 | type byApexName []ApexInfo |
| 329 | |
| 330 | func (a byApexName) Len() int { return len(a) } |
| 331 | func (a byApexName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 332 | func (a byApexName) Less(i, j int) bool { return a[i].ApexVariationName < a[j].ApexVariationName } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 333 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 334 | // mergeApexVariations deduplicates APEX variations that would build identically into a common |
| 335 | // variation. It returns the reduced list of variations and a list of aliases from the original |
| 336 | // variation names to the new variation names. |
Colin Cross | 9f720ce | 2020-10-02 10:26:04 -0700 | [diff] [blame] | 337 | func mergeApexVariations(ctx PathContext, apexVariations []ApexInfo) (merged []ApexInfo, aliases [][2]string) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 338 | sort.Sort(byApexName(apexVariations)) |
| 339 | seen := make(map[string]int) |
| 340 | for _, apexInfo := range apexVariations { |
| 341 | apexName := apexInfo.ApexVariationName |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 342 | mergedName := apexInfo.mergedName(ctx) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 343 | if index, exists := seen[mergedName]; exists { |
| 344 | merged[index].InApexes = append(merged[index].InApexes, apexName) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 345 | merged[index].ApexContents = append(merged[index].ApexContents, apexInfo.ApexContents...) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 346 | merged[index].Updatable = merged[index].Updatable || apexInfo.Updatable |
| 347 | } else { |
| 348 | seen[mergedName] = len(merged) |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 349 | apexInfo.ApexVariationName = apexInfo.mergedName(ctx) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 350 | apexInfo.InApexes = CopyOf(apexInfo.InApexes) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 351 | apexInfo.ApexContents = append([]*ApexContents(nil), apexInfo.ApexContents...) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 352 | merged = append(merged, apexInfo) |
| 353 | } |
| 354 | aliases = append(aliases, [2]string{apexName, mergedName}) |
| 355 | } |
| 356 | return merged, aliases |
| 357 | } |
| 358 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 359 | func CreateApexVariations(mctx BottomUpMutatorContext, module ApexModule) []Module { |
| 360 | base := module.apexModuleBase() |
| 361 | if len(base.apexVariations) > 0 { |
| 362 | base.checkApexAvailableProperty(mctx) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 363 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 364 | var apexVariations []ApexInfo |
| 365 | var aliases [][2]string |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 366 | if !mctx.Module().(ApexModule).UniqueApexVariations() && !base.ApexProperties.UniqueApexVariationsForDeps { |
| 367 | apexVariations, aliases = mergeApexVariations(mctx, base.apexVariations) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 368 | } else { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 369 | apexVariations = base.apexVariations |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 370 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 371 | // base.apexVariations is only needed to propagate the list of apexes from |
| 372 | // apexDepsMutator to apexMutator. It is no longer accurate after |
| 373 | // mergeApexVariations, and won't be copied to all but the first created |
| 374 | // variant. Clear it so it doesn't accidentally get used later. |
| 375 | base.apexVariations = nil |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 376 | |
| 377 | sort.Sort(byApexName(apexVariations)) |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 378 | variations := []string{} |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 379 | variations = append(variations, "") // Original variation for platform |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 380 | for _, apex := range apexVariations { |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 381 | variations = append(variations, apex.ApexVariationName) |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 382 | } |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 383 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 384 | defaultVariation := "" |
| 385 | mctx.SetDefaultDependencyVariation(&defaultVariation) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 386 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 387 | var inApex ApexMembership |
| 388 | for _, a := range apexVariations { |
| 389 | for _, apexContents := range a.ApexContents { |
| 390 | inApex = inApex.merge(apexContents.contents[mctx.ModuleName()]) |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | base.ApexProperties.InAnyApex = true |
| 395 | base.ApexProperties.DirectlyInAnyApex = inApex == directlyInApex |
| 396 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 397 | modules := mctx.CreateVariations(variations...) |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 398 | for i, mod := range modules { |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 399 | platformVariation := i == 0 |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 400 | if platformVariation && !mctx.Host() && !mod.(ApexModule).AvailableFor(AvailableToPlatform) { |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 401 | // Do not install the module for platform, but still allow it to output |
| 402 | // uninstallable AndroidMk entries in certain cases when they have |
| 403 | // side effects. |
| 404 | mod.MakeUninstallable() |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 405 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 406 | if !platformVariation { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 407 | mctx.SetVariationProvider(mod, ApexInfoProvider, apexVariations[i-1]) |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 408 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 409 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 410 | |
| 411 | for _, alias := range aliases { |
| 412 | mctx.CreateAliasVariation(alias[0], alias[1]) |
| 413 | } |
| 414 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 415 | return modules |
| 416 | } |
| 417 | return nil |
| 418 | } |
| 419 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 420 | // UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies |
| 421 | // that are in the same APEX have unique APEX variations so that the module can link against |
| 422 | // the right variant. |
| 423 | func UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext, am ApexModule) { |
| 424 | // anyInSameApex returns true if the two ApexInfo lists contain any values in an InApexes list |
| 425 | // in common. It is used instead of DepIsInSameApex because it needs to determine if the dep |
| 426 | // is in the same APEX due to being directly included, not only if it is included _because_ it |
| 427 | // is a dependency. |
| 428 | anyInSameApex := func(a, b []ApexInfo) bool { |
| 429 | collectApexes := func(infos []ApexInfo) []string { |
| 430 | var ret []string |
| 431 | for _, info := range infos { |
| 432 | ret = append(ret, info.InApexes...) |
| 433 | } |
| 434 | return ret |
| 435 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 436 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 437 | aApexes := collectApexes(a) |
| 438 | bApexes := collectApexes(b) |
| 439 | sort.Strings(bApexes) |
| 440 | for _, aApex := range aApexes { |
| 441 | index := sort.SearchStrings(bApexes, aApex) |
| 442 | if index < len(bApexes) && bApexes[index] == aApex { |
| 443 | return true |
| 444 | } |
| 445 | } |
| 446 | return false |
| 447 | } |
| 448 | |
| 449 | mctx.VisitDirectDeps(func(dep Module) { |
| 450 | if depApexModule, ok := dep.(ApexModule); ok { |
| 451 | if anyInSameApex(depApexModule.apexModuleBase().apexVariations, am.apexModuleBase().apexVariations) && |
| 452 | (depApexModule.UniqueApexVariations() || |
| 453 | depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) { |
| 454 | am.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps = true |
| 455 | } |
| 456 | } |
| 457 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 458 | } |
| 459 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 460 | // UpdateDirectlyInAnyApex uses the final module to store if any variant of this |
| 461 | // module is directly in any APEX, and then copies the final value to all the modules. |
| 462 | // It also copies the DirectlyInAnyApex value to any direct dependencies with a |
| 463 | // CopyDirectlyInAnyApexTag dependency tag. |
| 464 | func UpdateDirectlyInAnyApex(mctx BottomUpMutatorContext, am ApexModule) { |
| 465 | base := am.apexModuleBase() |
| 466 | // Copy DirectlyInAnyApex and InAnyApex from any direct dependencies with a |
| 467 | // CopyDirectlyInAnyApexTag dependency tag. |
| 468 | mctx.VisitDirectDeps(func(dep Module) { |
| 469 | if _, ok := mctx.OtherModuleDependencyTag(dep).(CopyDirectlyInAnyApexTag); ok { |
| 470 | depBase := dep.(ApexModule).apexModuleBase() |
| 471 | base.ApexProperties.DirectlyInAnyApex = depBase.ApexProperties.DirectlyInAnyApex |
| 472 | base.ApexProperties.InAnyApex = depBase.ApexProperties.InAnyApex |
| 473 | } |
| 474 | }) |
| 475 | |
| 476 | if base.ApexProperties.DirectlyInAnyApex { |
| 477 | // Variants of a module are always visited sequentially in order, so it is safe to |
| 478 | // write to another variant of this module. |
| 479 | // For a BottomUpMutator the PrimaryModule() is visited first and FinalModule() is |
| 480 | // visited last. |
| 481 | mctx.FinalModule().(ApexModule).apexModuleBase().ApexProperties.AnyVariantDirectlyInAnyApex = true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 482 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 483 | |
| 484 | // If this is the FinalModule (last visited module) copy AnyVariantDirectlyInAnyApex to |
| 485 | // all the other variants |
| 486 | if am == mctx.FinalModule().(ApexModule) { |
| 487 | mctx.VisitAllModuleVariants(func(variant Module) { |
| 488 | variant.(ApexModule).apexModuleBase().ApexProperties.AnyVariantDirectlyInAnyApex = |
| 489 | base.ApexProperties.AnyVariantDirectlyInAnyApex |
| 490 | }) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 491 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 492 | } |
| 493 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 494 | type ApexMembership int |
| 495 | |
| 496 | const ( |
| 497 | notInApex ApexMembership = 0 |
| 498 | indirectlyInApex = iota |
| 499 | directlyInApex |
| 500 | ) |
| 501 | |
| 502 | // Each apexBundle has an apexContents, and modules in that apex have a provider containing the |
| 503 | // apexContents of each apexBundle they are part of. |
| 504 | type ApexContents struct { |
| 505 | ApexName string |
| 506 | contents map[string]ApexMembership |
| 507 | } |
| 508 | |
| 509 | func NewApexContents(name string, contents map[string]ApexMembership) *ApexContents { |
| 510 | return &ApexContents{ |
| 511 | ApexName: name, |
| 512 | contents: contents, |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 516 | func (i ApexMembership) Add(direct bool) ApexMembership { |
| 517 | if direct || i == directlyInApex { |
| 518 | return directlyInApex |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 519 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 520 | return indirectlyInApex |
| 521 | } |
| 522 | |
| 523 | func (i ApexMembership) merge(other ApexMembership) ApexMembership { |
| 524 | if other == directlyInApex || i == directlyInApex { |
| 525 | return directlyInApex |
| 526 | } |
| 527 | |
| 528 | if other == indirectlyInApex || i == indirectlyInApex { |
| 529 | return indirectlyInApex |
| 530 | } |
| 531 | return notInApex |
| 532 | } |
| 533 | |
| 534 | func (ac *ApexContents) DirectlyInApex(name string) bool { |
| 535 | return ac.contents[name] == directlyInApex |
| 536 | } |
| 537 | |
| 538 | func (ac *ApexContents) InApex(name string) bool { |
| 539 | return ac.contents[name] != notInApex |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 540 | } |
| 541 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 542 | // Tests whether a module named moduleName is directly depended on by all APEXes |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 543 | // in an ApexInfo. |
| 544 | func DirectlyInAllApexes(apexInfo ApexInfo, moduleName string) bool { |
| 545 | for _, contents := range apexInfo.ApexContents { |
| 546 | if !contents.DirectlyInApex(moduleName) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 547 | return false |
| 548 | } |
| 549 | } |
| 550 | return true |
| 551 | } |
| 552 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 553 | func InitApexModule(m ApexModule) { |
| 554 | base := m.apexModuleBase() |
| 555 | base.canHaveApexVariants = true |
| 556 | |
| 557 | m.AddProperties(&base.ApexProperties) |
| 558 | } |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 559 | |
| 560 | // A dependency info for a single ApexModule, either direct or transitive. |
| 561 | type ApexModuleDepInfo struct { |
| 562 | // Name of the dependency |
| 563 | To string |
| 564 | // List of dependencies To belongs to. Includes APEX itself, if a direct dependency. |
| 565 | From []string |
| 566 | // Whether the dependency belongs to the final compiled APEX. |
| 567 | IsExternal bool |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 568 | // min_sdk_version of the ApexModule |
| 569 | MinSdkVersion string |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | // A map of a dependency name to its ApexModuleDepInfo |
| 573 | type DepNameToDepInfoMap map[string]ApexModuleDepInfo |
| 574 | |
| 575 | type ApexBundleDepsInfo struct { |
Jooyung Han | 98d63e1 | 2020-05-14 07:44:03 +0900 | [diff] [blame] | 576 | flatListPath OutputPath |
| 577 | fullListPath OutputPath |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 578 | } |
| 579 | |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 580 | type ApexBundleDepsInfoIntf interface { |
| 581 | Updatable() bool |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 582 | FlatListPath() Path |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 583 | FullListPath() Path |
| 584 | } |
| 585 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 586 | func (d *ApexBundleDepsInfo) FlatListPath() Path { |
| 587 | return d.flatListPath |
| 588 | } |
| 589 | |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 590 | func (d *ApexBundleDepsInfo) FullListPath() Path { |
| 591 | return d.fullListPath |
| 592 | } |
| 593 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 594 | // Generate two module out files: |
| 595 | // 1. FullList with transitive deps and their parents in the dep graph |
| 596 | // 2. FlatList with a flat list of transitive deps |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 597 | func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) { |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 598 | var fullContent strings.Builder |
| 599 | var flatContent strings.Builder |
| 600 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame^] | 601 | fmt.Fprintf(&fullContent, "%s(minSdkVersion:%s):\n", ctx.ModuleName(), minSdkVersion) |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 602 | for _, key := range FirstUniqueStrings(SortedStringKeys(depInfos)) { |
| 603 | info := depInfos[key] |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 604 | toName := fmt.Sprintf("%s(minSdkVersion:%s)", info.To, info.MinSdkVersion) |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 605 | if info.IsExternal { |
| 606 | toName = toName + " (external)" |
| 607 | } |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame^] | 608 | fmt.Fprintf(&fullContent, " %s <- %s\n", toName, strings.Join(SortedUniqueStrings(info.From), ", ")) |
| 609 | fmt.Fprintf(&flatContent, "%s\n", toName) |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | d.fullListPath = PathForModuleOut(ctx, "depsinfo", "fulllist.txt").OutputPath |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame^] | 613 | WriteFileRule(ctx, d.fullListPath, fullContent.String()) |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 614 | |
| 615 | d.flatListPath = PathForModuleOut(ctx, "depsinfo", "flatlist.txt").OutputPath |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame^] | 616 | WriteFileRule(ctx, d.flatListPath, flatContent.String()) |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 617 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 618 | |
| 619 | // TODO(b/158059172): remove minSdkVersion allowlist |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 620 | var minSdkVersionAllowlist = func(apiMap map[string]int) map[string]ApiLevel { |
| 621 | list := make(map[string]ApiLevel, len(apiMap)) |
| 622 | for name, finalApiInt := range apiMap { |
| 623 | list[name] = uncheckedFinalApiLevel(finalApiInt) |
| 624 | } |
| 625 | return list |
| 626 | }(map[string]int{ |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 627 | "adbd": 30, |
| 628 | "android.net.ipsec.ike": 30, |
| 629 | "androidx-constraintlayout_constraintlayout-solver": 30, |
| 630 | "androidx.annotation_annotation": 28, |
| 631 | "androidx.arch.core_core-common": 28, |
| 632 | "androidx.collection_collection": 28, |
| 633 | "androidx.lifecycle_lifecycle-common": 28, |
| 634 | "apache-commons-compress": 29, |
| 635 | "bouncycastle_ike_digests": 30, |
| 636 | "brotli-java": 29, |
| 637 | "captiveportal-lib": 28, |
| 638 | "flatbuffer_headers": 30, |
| 639 | "framework-permission": 30, |
| 640 | "framework-statsd": 30, |
| 641 | "gemmlowp_headers": 30, |
| 642 | "ike-internals": 30, |
| 643 | "kotlinx-coroutines-android": 28, |
| 644 | "kotlinx-coroutines-core": 28, |
| 645 | "libadb_crypto": 30, |
| 646 | "libadb_pairing_auth": 30, |
| 647 | "libadb_pairing_connection": 30, |
| 648 | "libadb_pairing_server": 30, |
| 649 | "libadb_protos": 30, |
| 650 | "libadb_tls_connection": 30, |
| 651 | "libadbconnection_client": 30, |
| 652 | "libadbconnection_server": 30, |
| 653 | "libadbd_core": 30, |
| 654 | "libadbd_services": 30, |
| 655 | "libadbd": 30, |
| 656 | "libapp_processes_protos_lite": 30, |
| 657 | "libasyncio": 30, |
| 658 | "libbrotli": 30, |
| 659 | "libbuildversion": 30, |
| 660 | "libcrypto_static": 30, |
| 661 | "libcrypto_utils": 30, |
| 662 | "libdiagnose_usb": 30, |
| 663 | "libeigen": 30, |
| 664 | "liblz4": 30, |
| 665 | "libmdnssd": 30, |
| 666 | "libneuralnetworks_common": 30, |
| 667 | "libneuralnetworks_headers": 30, |
| 668 | "libneuralnetworks": 30, |
| 669 | "libprocpartition": 30, |
| 670 | "libprotobuf-java-lite": 30, |
| 671 | "libprotoutil": 30, |
| 672 | "libqemu_pipe": 30, |
| 673 | "libstats_jni": 30, |
| 674 | "libstatslog_statsd": 30, |
| 675 | "libstatsmetadata": 30, |
| 676 | "libstatspull": 30, |
| 677 | "libstatssocket": 30, |
| 678 | "libsync": 30, |
| 679 | "libtextclassifier_hash_headers": 30, |
| 680 | "libtextclassifier_hash_static": 30, |
| 681 | "libtflite_kernel_utils": 30, |
| 682 | "libwatchdog": 29, |
| 683 | "libzstd": 30, |
| 684 | "metrics-constants-protos": 28, |
| 685 | "net-utils-framework-common": 29, |
| 686 | "permissioncontroller-statsd": 28, |
| 687 | "philox_random_headers": 30, |
| 688 | "philox_random": 30, |
| 689 | "service-permission": 30, |
| 690 | "service-statsd": 30, |
| 691 | "statsd-aidl-ndk_platform": 30, |
| 692 | "statsd": 30, |
| 693 | "tensorflow_headers": 30, |
| 694 | "xz-java": 29, |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 695 | }) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 696 | |
| 697 | // Function called while walking an APEX's payload dependencies. |
| 698 | // |
| 699 | // Return true if the `to` module should be visited, false otherwise. |
| 700 | type PayloadDepsCallback func(ctx ModuleContext, from blueprint.Module, to ApexModule, externalDep bool) bool |
| 701 | |
| 702 | // UpdatableModule represents updatable APEX/APK |
| 703 | type UpdatableModule interface { |
| 704 | Module |
| 705 | WalkPayloadDeps(ctx ModuleContext, do PayloadDepsCallback) |
| 706 | } |
| 707 | |
| 708 | // CheckMinSdkVersion checks if every dependency of an updatable module sets min_sdk_version accordingly |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 709 | func CheckMinSdkVersion(m UpdatableModule, ctx ModuleContext, minSdkVersion ApiLevel) { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 710 | // do not enforce min_sdk_version for host |
| 711 | if ctx.Host() { |
| 712 | return |
| 713 | } |
| 714 | |
| 715 | // do not enforce for coverage build |
| 716 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled() { |
| 717 | return |
| 718 | } |
| 719 | |
| 720 | // do not enforce deps.min_sdk_version if APEX/APK doesn't set min_sdk_version or |
| 721 | // min_sdk_version is not finalized (e.g. current or codenames) |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 722 | if minSdkVersion.IsCurrent() { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 723 | return |
| 724 | } |
| 725 | |
| 726 | m.WalkPayloadDeps(ctx, func(ctx ModuleContext, from blueprint.Module, to ApexModule, externalDep bool) bool { |
| 727 | if externalDep { |
| 728 | // external deps are outside the payload boundary, which is "stable" interface. |
| 729 | // We don't have to check min_sdk_version for external dependencies. |
| 730 | return false |
| 731 | } |
| 732 | if am, ok := from.(DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) { |
| 733 | return false |
| 734 | } |
| 735 | if err := to.ShouldSupportSdkVersion(ctx, minSdkVersion); err != nil { |
| 736 | toName := ctx.OtherModuleName(to) |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 737 | if ver, ok := minSdkVersionAllowlist[toName]; !ok || ver.GreaterThan(minSdkVersion) { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 738 | ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v. Dependency path: %s", |
| 739 | minSdkVersion, ctx.ModuleName(), err.Error(), ctx.GetPathString(false)) |
| 740 | return false |
| 741 | } |
| 742 | } |
| 743 | return true |
| 744 | }) |
| 745 | } |