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