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