blob: b7faa5b989eca5d6f635e7bae79f177205d9578b [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
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
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090034 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/java"
36 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090037 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090039)
40
Jiyong Park8e6d52f2020-11-19 14:37:47 +090041func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000042 registerApexBuildComponents(android.InitRegistrationContext)
43}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044
Paul Duffin667893c2021-03-09 22:34:13 +000045func registerApexBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("apex", BundleFactory)
47 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
48 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
49 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
50 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
51 ctx.RegisterModuleType("override_apex", overrideApexFactory)
52 ctx.RegisterModuleType("apex_set", apexSetFactory)
53
Paul Duffin5dda3e32021-05-05 14:13:27 +010054 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.PreDepsMutators(RegisterPreDepsMutators)
56 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090057}
58
Paul Duffin5dda3e32021-05-05 14:13:27 +010059func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
60 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
61}
62
Jiyong Park8e6d52f2020-11-19 14:37:47 +090063func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
64 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
65 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
66}
67
68func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000069 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090070 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
71 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
72 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010073 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
74 // it should create a platform variant.
75 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090076 ctx.BottomUp("apex", apexMutator).Parallel()
77 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
78 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090079}
80
81type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090082 // Json manifest file describing meta info of this APEX bundle. Refer to
83 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090084 Manifest *string `android:"path"`
85
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090086 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
87 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090088 AndroidManifest *string `android:"path"`
89
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090090 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
91 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090092 Apex_name *string
93
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090094 // Determines the file contexts file for setting the security contexts to files in this APEX
95 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
96 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090097 File_contexts *string `android:"path"`
98
Jiyong Park038e8522021-12-13 23:56:35 +090099 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
100 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
101 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
102 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
103 // capability. If this property is not set, or a file is missing in the file, default config
104 // is used.
105 Canned_fs_config *string `android:"path"`
106
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900107 ApexNativeDependencies
108
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900109 Multilib apexMultilibProperties
110
Paul Duffin4b64ba02021-03-29 11:02:53 +0100111 // List of bootclasspath fragments that are embedded inside this APEX bundle.
112 Bootclasspath_fragments []string
113
satayev333a1732021-05-17 21:35:26 +0100114 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
115 Systemserverclasspath_fragments []string
116
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900117 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900118 Java_libs []string
119
Sundong Ahn80c04892021-11-23 00:57:19 +0000120 // List of sh binaries that are embedded inside this APEX bundle.
121 Sh_binaries []string
122
Paul Duffin3abc1742021-03-15 19:32:23 +0000123 // List of platform_compat_config files that are embedded inside this APEX bundle.
124 Compat_configs []string
125
Jiyong Park12a719c2021-01-07 15:31:24 +0900126 // List of filesystem images that are embedded inside this APEX bundle.
127 Filesystems []string
128
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900129 // The minimum SDK version that this APEX must support at minimum. This is usually set to
130 // the SDK version that the APEX was first introduced.
131 Min_sdk_version *string
132
133 // Whether this APEX is considered updatable or not. When set to true, this will enforce
134 // additional rules for making sure that the APEX is truly updatable. To be updatable,
135 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000136 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900137 Updatable *bool
138
Jiyong Parkf4020582021-11-29 12:37:10 +0900139 // Marks that this APEX is designed to be updatable in the future, although it's not
140 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
141 // updatable APEXes. Currently, this disables the size optimization, so that the size of
142 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
143 // false.
144 Future_updatable *bool
145
Jiyong Park1bc84122021-06-22 20:23:05 +0900146 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
147 // false`. Default is false.
148 Platform_apis *bool
149
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900150 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
151 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900152 Installable *bool
153
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000154 // Whether this APEX can be compressed or not. Setting this property to false means this
155 // APEX will never be compressed. When set to true, APEX will be compressed if other
156 // conditions, e.g, target device needs to support APEX compression, are also fulfilled.
157 // Default: true.
158 Compressible *bool
159
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900160 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
161 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
162 Use_vndk_as_stable *bool
163
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000164 // Whether this is multi-installed APEX should skip installing symbol files.
165 // Multi-installed APEXes share the same apex_name and are installed at the same time.
166 // Default is false.
167 //
168 // Should be set to true for all multi-installed APEXes except the singular
169 // default version within the multi-installed group.
170 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
171 // or else conflicting build rules may be created.
172 Multi_install_skip_symbol_files *bool
173
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900174 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
175 // `name#version` or `name` which is an alias for `name#current`. If left empty,
176 // `platform#current` is implied. This value affects all modules included in this APEX. In
177 // other words, they are also built with the SDKs specified here.
178 Uses_sdks []string
179
180 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
181 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
182 // container. When set to zip, contents are stored in a zip container directly. This type is
183 // mostly for host-side debugging. When set to both, the two types are both built. Default
184 // is 'image'.
185 Payload_type *string
186
Huang Jianan13cac632021-08-02 15:02:17 +0800187 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
188 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900189 Payload_fs_type *string
190
191 // For telling the APEX to ignore special handling for system libraries such as bionic.
192 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900193 Ignore_system_library_special_case *bool
194
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100195 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100196 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100197 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900198
199 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
200 // used in tests.
201 Test_only_unsigned_payload *bool
202
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000203 // Whenever apex should be compressed, regardless of product flag used. Should be only
204 // used in tests.
205 Test_only_force_compression *bool
206
Jooyung Han09c11ad2021-10-27 03:45:31 +0900207 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
208 // with the tool to sign payload contents.
209 Custom_sign_tool *string
210
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100211 // Canonical name of this APEX bundle. Used to determine the path to the
212 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
213 // apex mutator variations. For override_apex modules, this is the name of the
214 // overridden base module.
215 ApexVariationName string `blueprint:"mutated"`
216
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900217 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900218
219 // List of sanitizer names that this APEX is enabled for
220 SanitizerNames []string `blueprint:"mutated"`
221
222 PreventInstall bool `blueprint:"mutated"`
223
224 HideFromMake bool `blueprint:"mutated"`
225
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900226 // Internal package method for this APEX. When payload_type is image, this can be either
227 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
228 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900229 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900230}
231
232type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900233 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900234 Native_shared_libs []string
235
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900236 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900237 Jni_libs []string
238
Jiyong Park99644e92020-11-17 22:21:02 +0900239 // List of rust dyn libraries
240 Rust_dyn_libs []string
241
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900242 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900243 Binaries []string
244
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900245 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900246 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900247
248 // List of filesystem images that are embedded inside this APEX bundle.
249 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900250}
251
252type apexMultilibProperties struct {
253 // Native dependencies whose compile_multilib is "first"
254 First ApexNativeDependencies
255
256 // Native dependencies whose compile_multilib is "both"
257 Both ApexNativeDependencies
258
259 // Native dependencies whose compile_multilib is "prefer32"
260 Prefer32 ApexNativeDependencies
261
262 // Native dependencies whose compile_multilib is "32"
263 Lib32 ApexNativeDependencies
264
265 // Native dependencies whose compile_multilib is "64"
266 Lib64 ApexNativeDependencies
267}
268
269type apexTargetBundleProperties struct {
270 Target struct {
271 // Multilib properties only for android.
272 Android struct {
273 Multilib apexMultilibProperties
274 }
275
276 // Multilib properties only for host.
277 Host struct {
278 Multilib apexMultilibProperties
279 }
280
281 // Multilib properties only for host linux_bionic.
282 Linux_bionic struct {
283 Multilib apexMultilibProperties
284 }
285
286 // Multilib properties only for host linux_glibc.
287 Linux_glibc struct {
288 Multilib apexMultilibProperties
289 }
290 }
291}
292
Jiyong Park59140302020-12-14 18:44:04 +0900293type apexArchBundleProperties struct {
294 Arch struct {
295 Arm struct {
296 ApexNativeDependencies
297 }
298 Arm64 struct {
299 ApexNativeDependencies
300 }
301 X86 struct {
302 ApexNativeDependencies
303 }
304 X86_64 struct {
305 ApexNativeDependencies
306 }
307 }
308}
309
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900310// These properties can be used in override_apex to override the corresponding properties in the
311// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900312type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900313 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900314 Apps []string
315
Daniel Norman5a3ce132021-08-26 15:44:43 -0700316 // List of prebuilt files that are embedded inside this APEX bundle.
317 Prebuilts []string
318
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900319 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900320 Rros []string
321
markchien7c803b82021-08-26 22:10:06 +0800322 // List of BPF programs inside this APEX bundle.
323 Bpfs []string
324
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900325 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
326 // Soong). This does not completely prevent installation of the overridden binaries, but if
327 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
328 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900329 Overrides []string
330
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900331 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900332 Logging_parent string
333
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900334 // Apex Container package name. Override value for attribute package:name in
335 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900336 Package_name string
337
338 // A txt file containing list of files that are allowed to be included in this APEX.
339 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700340
341 // Name of the apex_key module that provides the private key to sign this APEX bundle.
342 Key *string
343
344 // Specifies the certificate and the private key to sign the zip container of this APEX. If
345 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
346 // as the certificate and the private key, respectively. If this is ":module", then the
347 // certificate and the private key are provided from the android_app_certificate module
348 // named "module".
349 Certificate *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900350}
351
352type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900353 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900354 android.ModuleBase
355 android.DefaultableModuleBase
356 android.OverridableModuleBase
357 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400358 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900359
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900360 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361 properties apexBundleProperties
362 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900363 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900364 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900365 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900366
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900367 ///////////////////////////////////////////////////////////////////////////////////////////
368 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900369
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900370 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800371 publicKeyFile android.Path
372 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900373
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900374 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800375 containerCertificateFile android.Path
376 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900377
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900378 // Flags for special variants of APEX
379 testApex bool
380 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900382 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
383 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900384 primaryApexType bool
385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900386 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900387 suffix string
388
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900389 // File system type of apex_payload.img
390 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900391
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900392 // Whether to create symlink to the system file instead of having a file inside the apex or
393 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900394 linkToSystemLib bool
395
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900396 // List of files to be included in this APEX. This is filled in the first part of
397 // GenerateAndroidBuildActions.
398 filesInfo []apexFile
399
400 // List of other module names that should be installed when this APEX gets installed.
401 requiredDeps []string
402
403 ///////////////////////////////////////////////////////////////////////////////////////////
404 // Outputs (final and intermediates)
405
406 // Processed apex manifest in JSONson format (for Q)
407 manifestJsonOut android.WritablePath
408
409 // Processed apex manifest in PB format (for R+)
410 manifestPbOut android.WritablePath
411
412 // Processed file_contexts files
413 fileContexts android.WritablePath
414
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900415 // Struct holding the merged notice file paths in different formats
416 mergedNotices android.NoticeOutputs
417
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900418 // The built APEX file. This is the main product.
419 outputFile android.WritablePath
420
421 // The built APEX file in app bundle format. This file is not directly installed to the
422 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
423 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
424 // system) to be merged into a single app bundle file that Play accepts. See
425 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
426 bundleModuleFile android.WritablePath
427
Colin Cross6340ea52021-11-04 12:01:18 -0700428 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900429 installDir android.InstallPath
430
Colin Cross6340ea52021-11-04 12:01:18 -0700431 // Path where this APEX was installed.
432 installedFile android.InstallPath
433
434 // Installed locations of symlinks for backward compatibility.
435 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900436
437 // Text file having the list of individual files that are included in this APEX. Used for
438 // debugging purpose.
439 installedFilesFile android.WritablePath
440
441 // List of module names that this APEX is including (to be shown via *-deps-info target).
442 // Used for debugging purpose.
443 android.ApexBundleDepsInfo
444
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900445 // Optional list of lint report zip files for apexes that contain java or app modules
446 lintReports android.Paths
447
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900448 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000449
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000450 isCompressed bool
451
sophiezc80a2b32020-11-12 16:39:19 +0000452 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700453 nativeApisUsedByModuleFile android.ModuleOutPath
454 nativeApisBackedByModuleFile android.ModuleOutPath
455 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800456
457 // Collect the module directory for IDE info in java/jdeps.go.
458 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900459}
460
Colin Cross6340ea52021-11-04 12:01:18 -0700461func (*apexBundle) InstallBypassMake() bool {
462 return true
463}
464
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900465// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900466type apexFileClass int
467
Jooyung Han72bd2f82019-10-23 16:46:38 +0900468const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900469 app apexFileClass = iota
470 appSet
471 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900472 goBinary
473 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900474 nativeExecutable
475 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900476 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900477 pyBinary
478 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900479)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900480
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900481// apexFile represents a file in an APEX bundle. This is created during the first half of
482// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
483// of the function, this is used to create commands that copies the files into a staging directory,
484// where they are packaged into the APEX file. This struct is also used for creating Make modules
485// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900486type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900487 // buildFile is put in the installDir inside the APEX.
488 builtFile android.Path
489 noticeFiles android.Paths
490 installDir string
491 customStem string
492 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900493
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900494 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
495 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
496 // suffix>]
497 androidMkModuleName string // becomes LOCAL_MODULE
498 class apexFileClass // becomes LOCAL_MODULE_CLASS
499 moduleDir string // becomes LOCAL_PATH
500 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
501 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
502 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
503 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900504
505 jacocoReportClassesFile android.Path // only for javalibs and apps
506 lintDepSets java.LintDepSets // only for javalibs and apps
507 certificate java.Certificate // only for apps
508 overriddenPackageName string // only for apps
509
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900510 transitiveDep bool
511 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900512
Jiyong Park57621b22021-01-20 20:33:11 +0900513 multilib string
514
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900515 // TODO(jiyong): remove this
516 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900517}
518
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900519// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900520func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
521 ret := apexFile{
522 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900524 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900525 class: class,
526 module: module,
527 }
528 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900529 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900530 ret.moduleDir = ctx.OtherModuleDir(module)
531 ret.requiredModuleNames = module.RequiredModuleNames()
532 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
533 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900534 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900535 }
536 return ret
537}
538
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900539func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900540 return af.builtFile != nil && af.builtFile.String() != ""
541}
542
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900543// apexRelativePath returns the relative path of the given path from the install directory of this
544// apexFile.
545// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900546func (af *apexFile) apexRelativePath(path string) string {
547 return filepath.Join(af.installDir, path)
548}
549
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900550// path returns path of this apex file relative to the APEX root
551func (af *apexFile) path() string {
552 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900553}
554
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900555// stem returns the base filename of this apex file
556func (af *apexFile) stem() string {
557 if af.customStem != "" {
558 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900559 }
560 return af.builtFile.Base()
561}
562
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900563// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
564func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900565 var ret []string
566 for _, symlink := range af.symlinks {
567 ret = append(ret, af.apexRelativePath(symlink))
568 }
569 return ret
570}
571
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900572// availableToPlatform tests whether this apexFile is from a module that can be installed to the
573// platform.
574func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900575 if af.module == nil {
576 return false
577 }
578 if am, ok := af.module.(android.ApexModule); ok {
579 return am.AvailableFor(android.AvailableToPlatform)
580 }
581 return false
582}
583
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900584////////////////////////////////////////////////////////////////////////////////////////////////////
585// Mutators
586//
587// Brief description about mutators for APEX. The following three mutators are the most important
588// ones.
589//
590// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
591// to the (direct) dependencies of this APEX bundle.
592//
Paul Duffin949abc02020-12-08 10:34:30 +0000593// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900594// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
595// modules are marked as being included in the APEX via BuildForApex().
596//
Paul Duffin949abc02020-12-08 10:34:30 +0000597// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
598// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900599
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900600type dependencyTag struct {
601 blueprint.BaseDependencyTag
602 name string
603
604 // Determines if the dependent will be part of the APEX payload. Can be false for the
605 // dependencies to the signing key module, etc.
606 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000607
608 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
609 // replacement. This is needed because some prebuilt modules do not provide all the information
610 // needed by the apex.
611 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900612}
613
Paul Duffin8c535da2021-03-17 14:51:03 +0000614func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
615 return !d.sourceOnly
616}
617
618var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
619
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900620var (
Paul Duffin0b817782021-03-17 15:02:19 +0000621 androidAppTag = dependencyTag{name: "androidApp", payload: true}
622 bpfTag = dependencyTag{name: "bpf", payload: true}
623 certificateTag = dependencyTag{name: "certificate"}
624 executableTag = dependencyTag{name: "executable", payload: true}
625 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100626 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100627 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000628 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000629 javaLibTag = dependencyTag{name: "javaLib", payload: true}
630 jniLibTag = dependencyTag{name: "jniLib", payload: true}
631 keyTag = dependencyTag{name: "key"}
632 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
633 rroTag = dependencyTag{name: "rro", payload: true}
634 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
635 testForTag = dependencyTag{name: "test for"}
636 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000637 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900638)
639
640// TODO(jiyong): shorten this function signature
641func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900642 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900643 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900644 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900645
646 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900647 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900648 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
649 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900650 }
651
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900652 // Use *FarVariation* to be able to depend on modules having conflicting variations with
653 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
654 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900655 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900656 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900657 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
658 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900659 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900660 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900661}
662
663func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900664 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900665 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
666 } else {
667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
668 if ctx.Os().Bionic() {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
670 } else {
671 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
672 }
673 }
674}
675
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900676// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
677// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
678func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
679 deviceConfig := ctx.DeviceConfig()
680 if a.vndkApex {
681 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900682 }
683
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900684 var prefix string
685 var vndkVersion string
686 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000687 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900688 prefix = cc.VendorVariationPrefix
689 vndkVersion = deviceConfig.VndkVersion()
690 } else if a.ProductSpecific() {
691 prefix = cc.ProductVariationPrefix
692 vndkVersion = deviceConfig.ProductVndkVersion()
693 }
694 }
695 if vndkVersion == "current" {
696 vndkVersion = deviceConfig.PlatformVndkVersion()
697 }
698 if vndkVersion != "" {
699 return prefix + vndkVersion
700 }
701
702 return android.CoreVariation // The usual case
703}
704
705func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900706 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
707 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
708 // each target os/architectures, appropriate dependencies are selected by their
709 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900710 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900711 imageVariation := a.getImageVariation(ctx)
712
713 a.combineProperties(ctx)
714
715 has32BitTarget := false
716 for _, target := range targets {
717 if target.Arch.ArchType.Multilib == "lib32" {
718 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000719 }
720 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900721 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900722 // Don't include artifacts for the host cross targets because there is no way for us
723 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900724 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900725 continue
726 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000727
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900728 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000729
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 // Add native modules targeting both ABIs. When multilib.* is omitted for
731 // native_shared_libs/jni_libs/tests, it implies multilib.both
732 depsList = append(depsList, a.properties.Multilib.Both)
733 depsList = append(depsList, ApexNativeDependencies{
734 Native_shared_libs: a.properties.Native_shared_libs,
735 Tests: a.properties.Tests,
736 Jni_libs: a.properties.Jni_libs,
737 Binaries: nil,
738 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900739
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900740 // Add native modules targeting the first ABI When multilib.* is omitted for
741 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900742 isPrimaryAbi := i == 0
743 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900744 depsList = append(depsList, a.properties.Multilib.First)
745 depsList = append(depsList, ApexNativeDependencies{
746 Native_shared_libs: nil,
747 Tests: nil,
748 Jni_libs: nil,
749 Binaries: a.properties.Binaries,
750 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900751 }
752
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900753 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900754 switch target.Arch.ArchType.Multilib {
755 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900756 depsList = append(depsList, a.properties.Multilib.Lib32)
757 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900758 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900759 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900762 }
763 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900764
Jiyong Park59140302020-12-14 18:44:04 +0900765 // Add native modules targeting a specific arch variant
766 switch target.Arch.ArchType {
767 case android.Arm:
768 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
769 case android.Arm64:
770 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
771 case android.X86:
772 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
773 case android.X86_64:
774 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
775 default:
776 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
777 }
778
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900779 for _, d := range depsList {
780 addDependenciesForNativeModules(ctx, d, target, imageVariation)
781 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000782 ctx.AddFarVariationDependencies([]blueprint.Variation{
783 {Mutator: "os", Variation: target.OsVariation()},
784 {Mutator: "arch", Variation: target.ArchVariation()},
785 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900786 }
787
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900788 // Common-arch dependencies come next
789 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100790 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100791 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900792 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900793 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000794 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900795
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900796 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
797 // This field currently isn't used.
798 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900799 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
800 if len(a.properties.Uses_sdks) > 0 {
801 sdkRefs := []android.SdkRef{}
802 for _, str := range a.properties.Uses_sdks {
803 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
804 sdkRefs = append(sdkRefs, parsed)
805 }
806 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100807 }
808}
809
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900810// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900811func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
812 if a.overridableProperties.Allowed_files != nil {
813 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100814 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900815
816 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
817 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800818 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900819 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700820 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
821 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
822 // regardless of the TARGET_PREFER_* setting. See b/144532908
823 arches := ctx.DeviceConfig().Arches()
824 if len(arches) != 0 {
825 archForPrebuiltEtc := arches[0]
826 for _, arch := range arches {
827 // Prefer 64-bit arch if there is any
828 if arch.ArchType.Multilib == "lib64" {
829 archForPrebuiltEtc = arch
830 break
831 }
832 }
833 ctx.AddFarVariationDependencies([]blueprint.Variation{
834 {Mutator: "os", Variation: ctx.Os().String()},
835 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
836 }, prebuiltTag, prebuilts...)
837 }
838 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700839
840 // Dependencies for signing
841 if String(a.overridableProperties.Key) == "" {
842 ctx.PropertyErrorf("key", "missing")
843 return
844 }
845 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
846
847 cert := android.SrcIsModule(a.getCertString(ctx))
848 if cert != "" {
849 ctx.AddDependency(ctx.Module(), certificateTag, cert)
850 // empty cert is not an error. Cert and private keys will be directly found under
851 // PRODUCT_DEFAULT_DEV_CERTIFICATE
852 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100853}
854
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900855type ApexBundleInfo struct {
856 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100857}
858
Paul Duffin949abc02020-12-08 10:34:30 +0000859var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900860
Paul Duffina7d6a892020-12-07 17:39:59 +0000861var _ ApexInfoMutator = (*apexBundle)(nil)
862
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100863func (a *apexBundle) ApexVariationName() string {
864 return a.properties.ApexVariationName
865}
866
Paul Duffina7d6a892020-12-07 17:39:59 +0000867// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900868// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
869// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
870// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
871// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000872//
873// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
874// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
875// The apexMutator uses that list to create module variants for the apexes to which it belongs.
876// The relationship between module variants and apexes is not one-to-one as variants will be
877// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000878func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900879
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900880 // The VNDK APEX is special. For the APEX, the membership is described in a very different
881 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
882 // libraries are self-identified by their vndk.enabled properties. There is no need to run
883 // this mutator for the APEX as nothing will be collected. So, let's return fast.
884 if a.vndkApex {
885 return
886 }
887
888 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
889 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
890 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
891 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
892 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900893 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
894 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
895 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
896 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
897 return
898 }
899
Colin Cross56a83212020-09-15 18:30:11 -0700900 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900901 am, ok := child.(android.ApexModule)
902 if !ok || !am.CanHaveApexVariants() {
903 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900904 }
Paul Duffin573989d2021-03-17 13:25:29 +0000905 depTag := mctx.OtherModuleDependencyTag(child)
906
907 // Check to see if the tag always requires that the child module has an apex variant for every
908 // apex variant of the parent module. If it does not then it is still possible for something
909 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
910 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
911 return true
912 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000913 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900914 return false
915 }
Jooyung Handf78e212020-07-22 15:54:47 +0900916 if excludeVndkLibs {
917 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
918 return false
919 }
920 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900921 // By default, all the transitive dependencies are collected, unless filtered out
922 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700923 return true
924 }
925
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900926 // Records whether a certain module is included in this apexBundle via direct dependency or
927 // inndirect dependency.
928 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700929 mctx.WalkDeps(func(child, parent android.Module) bool {
930 if !continueApexDepsWalk(child, parent) {
931 return false
932 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900933 // If the parent is apexBundle, this child is directly depended.
934 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900935 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700936 contents[depName] = contents[depName].Add(directDep)
937 return true
938 })
939
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900940 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900941 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700942 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
943 Contents: apexContents,
944 })
945
Jooyung Haned124c32021-01-26 11:43:46 +0900946 minSdkVersion := a.minSdkVersion(mctx)
947 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
948 if minSdkVersion.IsNone() {
949 minSdkVersion = android.FutureApiLevel
950 }
951
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900952 // This is the main part of this mutator. Mark the collected dependencies that they need to
953 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900954
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100955 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
956 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700957 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100958 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900959 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700960 RequiredSdks: a.RequiredSdks(),
961 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900962 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100963 InApexVariants: []string{apexVariationName},
964 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700965 ApexContents: []*android.ApexContents{apexContents},
966 }
Colin Cross56a83212020-09-15 18:30:11 -0700967 mctx.WalkDeps(func(child, parent android.Module) bool {
968 if !continueApexDepsWalk(child, parent) {
969 return false
970 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900971 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900972 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900973 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900974}
975
Paul Duffina7d6a892020-12-07 17:39:59 +0000976type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100977 // ApexVariationName returns the name of the APEX variation to use in the apex
978 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
979 ApexVariationName() string
980
Paul Duffina7d6a892020-12-07 17:39:59 +0000981 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
982 // depended upon by an apex and which require an apex specific variant.
983 ApexInfoMutator(android.TopDownMutatorContext)
984}
985
986// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
987// specific variant to modules that support the ApexInfoMutator.
988func apexInfoMutator(mctx android.TopDownMutatorContext) {
989 if !mctx.Module().Enabled() {
990 return
991 }
992
993 if a, ok := mctx.Module().(ApexInfoMutator); ok {
994 a.ApexInfoMutator(mctx)
995 return
996 }
997}
998
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900999// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1000// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1001// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001002func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1003 if !mctx.Module().Enabled() {
1004 return
1005 }
1006 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001007 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1008 }
1009}
1010
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001011// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1012// the apex in order to retrieve its contents later.
1013// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001014func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1015 if !mctx.Module().Enabled() {
1016 return
1017 }
Colin Cross56a83212020-09-15 18:30:11 -07001018 if am, ok := mctx.Module().(android.ApexModule); ok {
1019 if testFor := am.TestFor(); len(testFor) > 0 {
1020 mctx.AddFarVariationDependencies([]blueprint.Variation{
1021 {Mutator: "os", Variation: am.Target().OsVariation()},
1022 {"arch", "common"},
1023 }, testForTag, testFor...)
1024 }
1025 }
1026}
1027
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001028// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001029func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1030 if !mctx.Module().Enabled() {
1031 return
1032 }
Colin Cross56a83212020-09-15 18:30:11 -07001033 if _, ok := mctx.Module().(android.ApexModule); ok {
1034 var contents []*android.ApexContents
1035 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1036 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1037 contents = append(contents, abInfo.Contents)
1038 }
1039 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1040 ApexContents: contents,
1041 })
Colin Crossaede88c2020-08-11 12:17:01 -07001042 }
1043}
1044
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001045// markPlatformAvailability marks whether or not a module can be available to platform. A module
1046// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1047// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1048// be) available to platform
1049// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001050func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1051 // Host and recovery are not considered as platform
1052 if mctx.Host() || mctx.Module().InstallInRecovery() {
1053 return
1054 }
1055
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001056 am, ok := mctx.Module().(android.ApexModule)
1057 if !ok {
1058 return
1059 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001060
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001061 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001062
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001063 // If any of the dep is not available to platform, this module is also considered as being
1064 // not available to platform even if it has "//apex_available:platform"
1065 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001066 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001067 // if the dependency crosses apex boundary, don't consider it
1068 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001069 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001070 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1071 availableToPlatform = false
1072 // TODO(b/154889534) trigger an error when 'am' has
1073 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001074 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001075 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001076
Paul Duffinb5769c12021-05-12 16:16:51 +01001077 // Exception 1: check to see if the module always requires it.
1078 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001079 availableToPlatform = true
1080 }
1081
1082 // Exception 2: bootstrap bionic libraries are also always available to platform
1083 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1084 availableToPlatform = true
1085 }
1086
1087 if !availableToPlatform {
1088 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001089 }
1090}
1091
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001092// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001093// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001094func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001095 if !mctx.Module().Enabled() {
1096 return
1097 }
Colin Cross56a83212020-09-15 18:30:11 -07001098
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001099 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001100 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001101 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001102 return
1103 }
1104
1105 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001106 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1107 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001108 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001109 if strings.HasPrefix(apexBundleName, "com.android.art") {
1110 // Create an alias from the platform variant. This is done to make
1111 // test_for dependencies work for modules that are split by the APEX
1112 // mutator, since test_for dependencies always go to the platform variant.
1113 // This doesn't happen for normal APEXes that are disjunct, so only do
1114 // this for the overlapping ART APEXes.
1115 // TODO(b/183882457): Remove this if the test_for functionality is
1116 // refactored to depend on the proper APEX variants instead of platform.
1117 mctx.CreateAliasVariation("", apexBundleName)
1118 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001119 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1120 apexBundleName := o.GetOverriddenModuleName()
1121 if apexBundleName == "" {
1122 mctx.ModuleErrorf("base property is not set")
1123 return
1124 }
1125 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001126 if strings.HasPrefix(apexBundleName, "com.android.art") {
1127 // TODO(b/183882457): See note for CreateAliasVariation above.
1128 mctx.CreateAliasVariation("", apexBundleName)
1129 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001130 }
1131}
Sundong Ahne9b55722019-09-06 17:37:42 +09001132
Paul Duffin6717d882021-06-15 19:09:41 +01001133// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1134// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001135func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001136 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001137 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001138 return !a.vndkApex
1139 }
1140
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001141 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001142}
1143
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001144// See android.UpdateDirectlyInAnyApex
1145// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001146func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1147 if !mctx.Module().Enabled() {
1148 return
1149 }
1150 if am, ok := mctx.Module().(android.ApexModule); ok {
1151 android.UpdateDirectlyInAnyApex(mctx, am)
1152 }
1153}
1154
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001155// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001156type apexPackaging int
1157
1158const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001159 // imageApex is a packaging method where contents are included in a filesystem image which
1160 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001161 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001162
1163 // zipApex is a packaging method where contents are directly included in the zip container.
1164 // This is used for host-side testing - because the contents are easily accessible by
1165 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001166 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001167
1168 // flattendApex is a packaging method where contents are not included in the APEX file, but
1169 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1170 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001171 flattenedApex
1172)
1173
1174const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001175 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001176 imageApexSuffix = ".apex"
1177 imageCapexSuffix = ".capex"
1178 zipApexSuffix = ".zipapex"
1179 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001180
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001181 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001182 imageApexType = "image"
1183 zipApexType = "zip"
1184 flattenedApexType = "flattened"
1185
Dan Willemsen47e1a752021-10-16 18:36:13 -07001186 ext4FsType = "ext4"
1187 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001188 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001189)
1190
1191// The suffix for the output "file", not the module
1192func (a apexPackaging) suffix() string {
1193 switch a {
1194 case imageApex:
1195 return imageApexSuffix
1196 case zipApex:
1197 return zipApexSuffix
1198 default:
1199 panic(fmt.Errorf("unknown APEX type %d", a))
1200 }
1201}
1202
1203func (a apexPackaging) name() string {
1204 switch a {
1205 case imageApex:
1206 return imageApexType
1207 case zipApex:
1208 return zipApexType
1209 default:
1210 panic(fmt.Errorf("unknown APEX type %d", a))
1211 }
1212}
1213
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001214// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1215// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001216func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001217 if !mctx.Module().Enabled() {
1218 return
1219 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001220 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001221 var variants []string
1222 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1223 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001224 // This is the normal case. Note that both image and flattend APEXes are
1225 // created. The image type is installed to the system partition, while the
1226 // flattened APEX is (optionally) installed to the system_ext partition.
1227 // This is mostly for GSI which has to support wide range of devices. If GSI
1228 // is installed on a newer (APEX-capable) device, the image APEX in the
1229 // system will be used. However, if the same GSI is installed on an old
1230 // device which can't support image APEX, the flattened APEX in the
1231 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001232 variants = append(variants, imageApexType, flattenedApexType)
1233 case "zip":
1234 variants = append(variants, zipApexType)
1235 case "both":
1236 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1237 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001238 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001239 return
1240 }
1241
1242 modules := mctx.CreateLocalVariations(variants...)
1243
1244 for i, v := range variants {
1245 switch v {
1246 case imageApexType:
1247 modules[i].(*apexBundle).properties.ApexType = imageApex
1248 case zipApexType:
1249 modules[i].(*apexBundle).properties.ApexType = zipApex
1250 case flattenedApexType:
1251 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001252 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001253 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001254 modules[i].(*apexBundle).MakeAsSystemExt()
1255 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001256 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001257 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001258 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001259 // payload_type is forcibly overridden to "image"
1260 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001261 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001262 }
1263}
1264
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001265var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001266
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001267// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001268func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1269 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001270 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001271 return true
1272}
1273
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001274var _ android.OutputFileProducer = (*apexBundle)(nil)
1275
1276// Implements android.OutputFileProducer
1277func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1278 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001279 case "", android.DefaultDistTag:
1280 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001281 return android.Paths{a.outputFile}, nil
1282 default:
1283 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1284 }
1285}
1286
1287var _ cc.Coverage = (*apexBundle)(nil)
1288
1289// Implements cc.Coverage
1290func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1291 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1292}
1293
1294// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001295func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001296 a.properties.PreventInstall = true
1297}
1298
1299// Implements cc.Coverage
1300func (a *apexBundle) HideFromMake() {
1301 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001302 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1303 // TODO(ccross): untangle these
1304 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001305}
1306
1307// Implements cc.Coverage
1308func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1309 a.properties.IsCoverageVariant = coverage
1310}
1311
1312// Implements cc.Coverage
1313func (a *apexBundle) EnableCoverageIfNeeded() {}
1314
1315var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1316
1317// Implements android.ApexBudleDepsInfoIntf
1318func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001319 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001320}
1321
Jiyong Parkf4020582021-11-29 12:37:10 +09001322func (a *apexBundle) FutureUpdatable() bool {
1323 return proptools.BoolDefault(a.properties.Future_updatable, false)
1324}
1325
Jiyong Park1bc84122021-06-22 20:23:05 +09001326func (a *apexBundle) UsePlatformApis() bool {
1327 return proptools.BoolDefault(a.properties.Platform_apis, false)
1328}
1329
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001330// getCertString returns the name of the cert that should be used to sign this APEX. This is
1331// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001332func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001333 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001334 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1335 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1336 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001337 if a.vndkApex {
1338 moduleName = vndkApexName
1339 }
1340 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001341 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001342 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001343 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001344 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001345}
1346
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001347// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001348func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001349 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001350}
1351
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001352// See the generate_hashtree property
1353func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001354 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001355}
1356
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001357// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001358func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1359 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1360}
1361
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001362// See the test_only_force_compression property
1363func (a *apexBundle) testOnlyShouldForceCompression() bool {
1364 return proptools.Bool(a.properties.Test_only_force_compression)
1365}
1366
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001367// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1368// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1369// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001370
Jiyong Parkf97782b2019-02-13 20:28:58 +09001371func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1372 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1373 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1374 }
1375}
1376
Jiyong Park388ef3f2019-01-28 19:47:32 +09001377func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001378 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1379 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001380 }
1381
1382 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001383 globalSanitizerNames := []string{}
1384 if a.Host() {
1385 globalSanitizerNames = ctx.Config().SanitizeHost()
1386 } else {
1387 arches := ctx.Config().SanitizeDeviceArch()
1388 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1389 globalSanitizerNames = ctx.Config().SanitizeDevice()
1390 }
1391 }
1392 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001393}
1394
Jooyung Han8ce8db92020-05-15 19:05:05 +09001395func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001396 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1397 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001398 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001399 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001400 for _, target := range ctx.MultiTargets() {
1401 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001402 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1403 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1404 Tests: nil,
1405 Jni_libs: nil,
1406 Binaries: nil,
1407 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001408 break
1409 }
1410 }
1411 }
1412}
1413
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001414// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1415// returned apexFile saves information about the Soong module that will be used for creating the
1416// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001417func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001418 // Decide the APEX-local directory by the multilib of the library In the future, we may
1419 // query this to the module.
1420 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001421 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001422 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001423 case "lib32":
1424 dirInApex = "lib"
1425 case "lib64":
1426 dirInApex = "lib64"
1427 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001428 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001429 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001430 }
Jooyung Han35155c42020-02-06 17:33:20 +09001431 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001432 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001433 // Special case for Bionic libs and other libs installed with them. This is to
1434 // prevent those libs from being included in the search path
1435 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1436 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1437 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1438 // will be loaded into the default linker namespace (aka "platform" namespace). If
1439 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1440 // be loaded again into the runtime linker namespace, which will result in double
1441 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001442 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001443 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001444
Jiyong Parkf653b052019-11-18 15:39:01 +09001445 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001446 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1447 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001448}
1449
Jiyong Park1833cef2019-12-13 13:28:36 +09001450func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001451 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001452 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001453 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001454 }
Jooyung Han35155c42020-02-06 17:33:20 +09001455 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001456 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001457 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1458 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001459 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001460 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001461 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001462}
1463
Jiyong Park99644e92020-11-17 22:21:02 +09001464func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1465 dirInApex := "bin"
1466 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1467 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1468 }
1469 fileToCopy := rustm.OutputFile().Path()
1470 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1471 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1472 return af
1473}
1474
1475func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1476 // Decide the APEX-local directory by the multilib of the library
1477 // In the future, we may query this to the module.
1478 var dirInApex string
1479 switch rustm.Arch().ArchType.Multilib {
1480 case "lib32":
1481 dirInApex = "lib"
1482 case "lib64":
1483 dirInApex = "lib64"
1484 }
1485 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1486 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1487 }
1488 fileToCopy := rustm.OutputFile().Path()
1489 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1490 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1491}
1492
Jiyong Park1833cef2019-12-13 13:28:36 +09001493func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001494 dirInApex := "bin"
1495 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001496 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001497}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001498
Jiyong Park1833cef2019-12-13 13:28:36 +09001499func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001500 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001501 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001502 // NB: Since go binaries are static we don't need the module for anything here, which is
1503 // good since the go tool is a blueprint.Module not an android.Module like we would
1504 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001505 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001506}
1507
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001508func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001509 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001510 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1511 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1512 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001513 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001514 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001515 af.symlinks = sh.Symlinks()
1516 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001517}
1518
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001519func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001520 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001521 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001522 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001523}
1524
atrost6e126252020-01-27 17:01:16 +00001525func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1526 dirInApex := filepath.Join("etc", config.SubDir())
1527 fileToCopy := config.CompatConfig()
1528 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1529}
1530
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001531// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1532// way.
1533type javaModule interface {
1534 android.Module
1535 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001536 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001537 JacocoReportClassesFile() android.Path
1538 LintDepSets() java.LintDepSets
1539 Stem() string
1540}
1541
1542var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001543var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001544var _ javaModule = (*java.SdkLibrary)(nil)
1545var _ javaModule = (*java.DexImport)(nil)
1546var _ javaModule = (*java.SdkLibraryImport)(nil)
1547
Paul Duffin190fdef2021-04-26 10:33:59 +01001548// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001549func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001550 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001551}
1552
1553// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1554func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001555 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001556 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001557 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1558 af.lintDepSets = module.LintDepSets()
1559 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001560 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1561 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1562 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1563 }
1564 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001565 return af
1566}
1567
1568// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1569// the same way.
1570type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001571 android.Module
1572 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001573 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001574 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001575 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001576 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001577 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001578 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001579}
1580
1581var _ androidApp = (*java.AndroidApp)(nil)
1582var _ androidApp = (*java.AndroidAppImport)(nil)
1583
1584func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001585 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001586 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001587 appDir = "priv-app"
1588 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001589 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001590 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001591 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001592 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001593 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001594 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001595
1596 if app, ok := aapp.(interface {
1597 OverriddenManifestPackageName() string
1598 }); ok {
1599 af.overriddenPackageName = app.OverriddenManifestPackageName()
1600 }
Jiyong Park618922e2020-01-08 13:35:43 +09001601 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001602}
1603
Jiyong Park69aeba92020-04-24 21:16:36 +09001604func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1605 rroDir := "overlay"
1606 dirInApex := filepath.Join(rroDir, rro.Theme())
1607 fileToCopy := rro.OutputFile()
1608 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1609 af.certificate = rro.Certificate()
1610
1611 if a, ok := rro.(interface {
1612 OverriddenManifestPackageName() string
1613 }); ok {
1614 af.overriddenPackageName = a.OverriddenManifestPackageName()
1615 }
1616 return af
1617}
1618
markchien2f59ec92020-09-02 16:23:38 +08001619func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1620 dirInApex := filepath.Join("etc", "bpf")
1621 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1622}
1623
Jiyong Park12a719c2021-01-07 15:31:24 +09001624func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1625 dirInApex := filepath.Join("etc", "fs")
1626 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1627}
1628
Paul Duffin064b70c2020-11-02 17:32:38 +00001629// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001630// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1631// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1632// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001633func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001634 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001635 am, ok := child.(android.ApexModule)
1636 if !ok || !am.CanHaveApexVariants() {
1637 return false
1638 }
1639
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001640 // Filter-out unwanted depedendencies
1641 depTag := ctx.OtherModuleDependencyTag(child)
1642 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1643 return false
1644 }
1645 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001646 return false
1647 }
1648
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001649 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001650 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001651
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001652 // Visit actually
1653 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001654 })
1655}
1656
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001657// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1658type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001659
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001660const (
1661 ext4 fsType = iota
1662 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001663 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001664)
Artur Satayev849f8442020-04-28 14:57:42 +01001665
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001666func (f fsType) string() string {
1667 switch f {
1668 case ext4:
1669 return ext4FsType
1670 case f2fs:
1671 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001672 case erofs:
1673 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001674 default:
1675 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001676 }
1677}
1678
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001679// Creates build rules for an APEX. It consists of the following major steps:
1680//
1681// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1682// 2) traverse the dependency tree to collect apexFile structs from them.
1683// 3) some fields in apexBundle struct are configured
1684// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001685func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001686 ////////////////////////////////////////////////////////////////////////////////////////////
1687 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001688 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001689 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001690 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001691 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001692 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001693 if len(a.properties.Tests) > 0 && !a.testApex {
1694 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1695 return
1696 }
Jiyong Park678c8812020-02-07 17:25:49 +09001697
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001698 ////////////////////////////////////////////////////////////////////////////////////////////
1699 // 2) traverse the dependency tree to collect apexFile structs from them.
1700
1701 // all the files that will be included in this APEX
1702 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001703
Jooyung Hane1633032019-08-01 17:41:43 +09001704 // native lib dependencies
1705 var provideNativeLibs []string
1706 var requireNativeLibs []string
1707
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001708 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1709
braleeb0c1f0c2021-06-07 22:49:13 +08001710 // Collect the module directory for IDE info in java/jdeps.go.
1711 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1712
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001713 // TODO(jiyong): do this using WalkPayloadDeps
1714 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001715 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001716 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001717 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1718 return false
1719 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001720 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1721 return false
1722 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001723 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001725 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001726 case sharedLibTag, jniLibTag:
1727 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001728 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001729 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1730 fi.isJniLib = isJniLib
1731 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001732 // Collect the list of stub-providing libs except:
1733 // - VNDK libs are only for vendors
1734 // - bootstrap bionic libs are treated as provided by system
1735 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001736 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001737 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001738 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001739 } else if r, ok := child.(*rust.Module); ok {
1740 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001741 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001742 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001743 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001744 propertyName := "native_shared_libs"
1745 if isJniLib {
1746 propertyName = "jni_libs"
1747 }
1748 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001749 }
1750 case executableTag:
1751 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001752 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001753 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001754 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001755 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001756 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001757 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001758 } else if rust, ok := child.(*rust.Module); ok {
1759 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1760 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001761 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001762 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1763 }
1764 case shBinaryTag:
1765 if sh, ok := child.(*sh.ShBinary); ok {
1766 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1767 } else {
1768 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001769 }
Paul Duffin94f19632021-04-20 12:40:07 +01001770 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001771 {
Paul Duffin7771eba2021-04-23 14:25:28 +01001772 if _, ok := child.(*java.BootclasspathFragmentModule); !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001773 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001774 return false
1775 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001776
Paul Duffincc33ec82021-04-25 23:14:55 +01001777 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1778 filesInfo = append(filesInfo, filesToAdd...)
Paul Duffin4d101b62021-03-24 15:42:20 +00001779 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001780 }
satayev333a1732021-05-17 21:35:26 +01001781 case sscpfTag:
1782 {
1783 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1784 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1785 return false
1786 }
satayevb98371c2021-06-15 16:49:50 +01001787 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1788 filesInfo = append(filesInfo, *af)
1789 }
satayev333a1732021-05-17 21:35:26 +01001790 return true
1791 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001792 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001793 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001794 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001795 af := apexFileForJavaModule(ctx, child.(javaModule))
1796 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001797 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1798 return false
1799 }
1800 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001801 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001802 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001803 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001804 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001805 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001806 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001807 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001808 return true // track transitive dependencies
1809 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001810 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001811 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001812 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001813 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1814 appDir := "app"
1815 if ap.Privileged() {
1816 appDir = "priv-app"
1817 }
Yo Chiange8128052020-07-23 20:09:18 +08001818 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001819 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1820 af.certificate = java.PresignedCertificate
1821 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001822 } else {
1823 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1824 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001825 case rroTag:
1826 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1827 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1828 } else {
1829 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1830 }
markchien2f59ec92020-09-02 16:23:38 +08001831 case bpfTag:
1832 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1833 filesToCopy, _ := bpfProgram.OutputFiles("")
1834 for _, bpfFile := range filesToCopy {
1835 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1836 }
1837 } else {
1838 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1839 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001840 case fsTag:
1841 if fs, ok := child.(filesystem.Filesystem); ok {
1842 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1843 } else {
1844 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1845 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001846 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001847 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001848 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001849 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001850 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001851 }
Paul Duffin0b817782021-03-17 15:02:19 +00001852 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001853 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1854 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1855 } else {
1856 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1857 }
Roland Levillain630846d2019-06-26 12:48:34 +01001858 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001859 if ccTest, ok := child.(*cc.Module); ok {
1860 if ccTest.IsTestPerSrcAllTestsVariation() {
1861 // Multiple-output test module (where `test_per_src: true`).
1862 //
1863 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1864 // We do not add this variation to `filesInfo`, as it has no output;
1865 // however, we do add the other variations of this module as indirect
1866 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001867 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001868 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001869 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001870 af.class = nativeTest
1871 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001872 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001873 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001874 } else {
1875 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1876 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001877 case keyTag:
1878 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001879 a.privateKeyFile = key.privateKeyFile
1880 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001881 } else {
1882 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001883 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001884 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001885 case certificateTag:
1886 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001887 a.containerCertificateFile = dep.Certificate.Pem
1888 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001889 } else {
1890 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1891 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001892 case android.PrebuiltDepTag:
1893 // If the prebuilt is force disabled, remember to delete the prebuilt file
1894 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001895 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001896 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1897 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001898 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001899 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001900 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001901 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001902 // We cannot use a switch statement on `depTag` here as the checked
1903 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001904 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001905 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001906 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001907 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001908 return false
1909 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001910 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1911 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001912
1913 // Always track transitive dependencies for host.
1914 if a.Host() {
1915 filesInfo = append(filesInfo, af)
1916 return true
1917 }
1918
Colin Cross56a83212020-09-15 18:30:11 -07001919 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001920 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001921 // If the dependency is a stubs lib, don't include it in this APEX,
1922 // but make sure that the lib is installed on the device.
1923 // In case no APEX is having the lib, the lib is installed to the system
1924 // partition.
1925 //
1926 // Always include if we are a host-apex however since those won't have any
1927 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001928 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001929 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001930 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001931 if !android.InList(name, a.requiredDeps) {
1932 a.requiredDeps = append(a.requiredDeps, name)
1933 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001934 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001935 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001936 // Don't track further
1937 return false
1938 }
Jiyong Parke3867542020-12-03 17:28:25 +09001939
1940 // If the dep is not considered to be in the same
1941 // apex, don't add it to filesInfo so that it is not
1942 // included in this APEX.
1943 // TODO(jiyong): move this to at the top of the
1944 // else-if clause for the indirect dependencies.
1945 // Currently, that's impossible because we would
1946 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001947 // DepIsInSameAPex is false. We also shouldn't do
1948 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001949 //
1950 // TODO(jiyong): explain why the same module is passed in twice.
1951 // Switching the first am to parent breaks lots of tests.
1952 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001953 return false
1954 }
1955
Jiyong Parkf653b052019-11-18 15:39:01 +09001956 filesInfo = append(filesInfo, af)
1957 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001958 } else if rm, ok := child.(*rust.Module); ok {
1959 af := apexFileForRustLibrary(ctx, rm)
1960 af.transitiveDep = true
1961 filesInfo = append(filesInfo, af)
1962 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001963 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001964 } else if cc.IsTestPerSrcDepTag(depTag) {
1965 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001966 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001967 // Handle modules created as `test_per_src` variations of a single test module:
1968 // use the name of the generated test binary (`fileToCopy`) instead of the name
1969 // of the original test module (`depName`, shared by all `test_per_src`
1970 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001971 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001972 // these are not considered transitive dep
1973 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001974 filesInfo = append(filesInfo, af)
1975 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001976 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001977 } else if cc.IsHeaderDepTag(depTag) {
1978 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001979 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001980 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1981 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001982 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001983 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001984 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1985 }
Jiyong Park99644e92020-11-17 22:21:02 +09001986 } else if rust.IsDylibDepTag(depTag) {
1987 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1988 af := apexFileForRustLibrary(ctx, rustm)
1989 af.transitiveDep = true
1990 filesInfo = append(filesInfo, af)
1991 return true // track transitive dependencies
1992 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09001993 } else if rust.IsRlibDepTag(depTag) {
1994 // Rlib is statically linked, but it might have shared lib
1995 // dependencies. Track them.
1996 return true
Paul Duffin65898052021-04-20 22:47:03 +01001997 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01001998 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00001999 switch child.(type) {
2000 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002001 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002002 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002003 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002004 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002005 return false
2006 }
2007 filesInfo = append(filesInfo, af)
2008 return true // track transitive dependencies
2009 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002010 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
Paul Duffin4d101b62021-03-24 15:42:20 +00002011 }
satayev333a1732021-05-17 21:35:26 +01002012 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2013 // Add the contents of the systemserverclasspath fragment to the apex.
2014 switch child.(type) {
2015 case *java.Library, *java.SdkLibrary:
2016 af := apexFileForJavaModule(ctx, child.(javaModule))
2017 filesInfo = append(filesInfo, af)
2018 return true // track transitive dependencies
2019 default:
2020 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2021 }
Colin Cross56a83212020-09-15 18:30:11 -07002022 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2023 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002024 } else if depTag == android.DarwinUniversalVariantTag {
2025 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002026 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002027 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002028 }
2029 }
2030 }
2031 return false
2032 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002033 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002034 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002035 return
2036 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002037
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002038 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002039 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002040 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002041 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002042 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002043 if e, ok := encountered[dest]; !ok {
2044 encountered[dest] = f
2045 } else {
2046 // If a module is directly included and also transitively depended on
2047 // consider it as directly included.
2048 e.transitiveDep = e.transitiveDep && f.transitiveDep
2049 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002050 }
2051 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002052 var result []apexFile
2053 for _, v := range encountered {
2054 result = append(result, v)
2055 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002056 return result
2057 }
2058 filesInfo = removeDup(filesInfo)
2059
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002060 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002061 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002062 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2063 // changes.
2064 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002065 })
2066
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002067 ////////////////////////////////////////////////////////////////////////////////////////////
2068 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002069 a.installDir = android.PathForModuleInstall(ctx, "apex")
2070 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002071
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002072 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002073 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002074 switch a.properties.ApexType {
2075 case imageApex:
2076 if buildFlattenedAsDefault {
2077 a.suffix = imageApexSuffix
2078 } else {
2079 a.suffix = ""
2080 a.primaryApexType = true
2081
2082 if ctx.Config().InstallExtraFlattenedApexes() {
2083 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2084 }
2085 }
2086 case zipApex:
2087 if proptools.String(a.properties.Payload_type) == "zip" {
2088 a.suffix = ""
2089 a.primaryApexType = true
2090 } else {
2091 a.suffix = zipApexSuffix
2092 }
2093 case flattenedApex:
2094 if buildFlattenedAsDefault {
2095 a.suffix = ""
2096 a.primaryApexType = true
2097 } else {
2098 a.suffix = flattenedSuffix
2099 }
2100 }
2101
Theotime Combes4ba38c12020-06-12 12:46:59 +00002102 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2103 case ext4FsType:
2104 a.payloadFsType = ext4
2105 case f2fsFsType:
2106 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002107 case erofsFsType:
2108 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002109 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002110 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type)
Theotime Combes4ba38c12020-06-12 12:46:59 +00002111 }
2112
Jiyong Park7cd10e32020-01-14 09:22:18 +09002113 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2114 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2115 // the same library in the system partition, thus effectively sharing the same libraries
2116 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2117 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002118 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002119
Jooyung Han85d61762020-06-24 23:50:26 +09002120 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2121 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002122 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002123 a.linkToSystemLib = false
2124 }
2125
Jiyong Park4da07972021-01-05 21:01:11 +09002126 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002127 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002128
Jiyong Park9d677202020-02-19 16:29:35 +09002129 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002130 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002131 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002132 a.linkToSystemLib = false
2133 }
2134
Jiyong Park638d30e2020-02-26 18:27:19 +09002135 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2136 if ctx.Host() {
2137 a.linkToSystemLib = false
2138 }
2139
Colin Cross6340ea52021-11-04 12:01:18 -07002140 if a.properties.ApexType != zipApex {
2141 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2142 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002143
2144 ////////////////////////////////////////////////////////////////////////////////////////////
2145 // 4) generate the build rules to create the APEX. This is done in builder.go.
2146 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002147 if a.properties.ApexType == flattenedApex {
2148 a.buildFlattenedApex(ctx)
2149 } else {
2150 a.buildUnflattenedApex(ctx)
2151 }
Jiyong Park956305c2020-01-09 12:32:06 +09002152 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002153 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002154
2155 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2156 if a.installable() {
2157 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2158 // along with other ordinary files. (Note that this is done by apexer for
2159 // non-flattened APEXes)
2160 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2161
2162 // Place the public key as apex_pubkey. This is also done by apexer for
2163 // non-flattened APEXes case.
2164 // TODO(jiyong): Why do we need this CP rule?
2165 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2166 ctx.Build(pctx, android.BuildParams{
2167 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002168 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002169 Output: copiedPubkey,
2170 })
2171 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2172 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002173}
2174
Paul Duffincc33ec82021-04-25 23:14:55 +01002175// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2176// the bootclasspath_fragment contributes to the apex.
2177func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2178 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2179 var filesToAdd []apexFile
2180
2181 // Add the boot image files, e.g. .art, .oat and .vdex files.
2182 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2183 dirInApex := filepath.Join("javalib", arch.String())
2184 for _, f := range files {
2185 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2186 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2187 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2188 filesToAdd = append(filesToAdd, af)
2189 }
2190 }
2191
satayev3db35472021-05-06 23:59:58 +01002192 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002193 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2194 filesToAdd = append(filesToAdd, *af)
2195 }
satayev3db35472021-05-06 23:59:58 +01002196
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002197 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2198 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2199 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2200
2201 if pathOnHost != nil {
2202 // We need to copy the profile to a temporary path with the right filename because the apexer
2203 // will take the filename as is.
2204 ctx.Build(pctx, android.BuildParams{
2205 Rule: android.Cp,
2206 Input: pathOnHost,
2207 Output: tempPath,
2208 })
2209 } else {
2210 // At this point, the boot image profile cannot be generated. It is probably because the boot
2211 // image profile source file does not exist on the branch, or it is not available for the
2212 // current build target.
2213 // However, we cannot enforce the boot image profile to be generated because some build
2214 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2215 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2216 // only if the APEX is being built.
2217 ctx.Build(pctx, android.BuildParams{
2218 Rule: android.ErrorRule,
2219 Output: tempPath,
2220 Args: map[string]string{
2221 "error": "Boot image profile cannot be generated",
2222 },
2223 })
2224 }
2225
2226 androidMkModuleName := filepath.Base(pathInApex)
2227 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2228 filesToAdd = append(filesToAdd, af)
2229 }
2230
Paul Duffincc33ec82021-04-25 23:14:55 +01002231 return filesToAdd
2232}
2233
satayevb98371c2021-06-15 16:49:50 +01002234// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2235// the module contributes to the apex; or nil if the proto config was not generated.
2236func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2237 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2238 if !info.ClasspathFragmentProtoGenerated {
2239 return nil
2240 }
2241 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2242 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2243 return &af
satayev14e49132021-05-17 21:03:07 +01002244}
2245
Paul Duffincc33ec82021-04-25 23:14:55 +01002246// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2247// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002248func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2249 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2250
2251 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2252 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002253 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2254 if err != nil {
2255 ctx.ModuleErrorf("%s", err)
2256 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002257
2258 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2259 // bootclasspath_fragment.
2260 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2261 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002262}
2263
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002264///////////////////////////////////////////////////////////////////////////////////////////////////
2265// Factory functions
2266//
2267
2268func newApexBundle() *apexBundle {
2269 module := &apexBundle{}
2270
2271 module.AddProperties(&module.properties)
2272 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002273 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002274 module.AddProperties(&module.overridableProperties)
2275
2276 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2277 android.InitDefaultableModule(module)
2278 android.InitSdkAwareModule(module)
2279 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002280 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002281 return module
2282}
2283
Paul Duffineb8051d2021-10-18 17:49:39 +01002284func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002285 bundle := newApexBundle()
2286 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002287 return bundle
2288}
2289
2290// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2291// certain compatibility checks such as apex_available are not done for apex_test.
2292func testApexBundleFactory() android.Module {
2293 bundle := newApexBundle()
2294 bundle.testApex = true
2295 return bundle
2296}
2297
2298// apex packages other modules into an APEX file which is a packaging format for system-level
2299// components like binaries, shared libraries, etc.
2300func BundleFactory() android.Module {
2301 return newApexBundle()
2302}
2303
2304type Defaults struct {
2305 android.ModuleBase
2306 android.DefaultsModuleBase
2307}
2308
2309// apex_defaults provides defaultable properties to other apex modules.
2310func defaultsFactory() android.Module {
2311 return DefaultsFactory()
2312}
2313
2314func DefaultsFactory(props ...interface{}) android.Module {
2315 module := &Defaults{}
2316
2317 module.AddProperties(props...)
2318 module.AddProperties(
2319 &apexBundleProperties{},
2320 &apexTargetBundleProperties{},
2321 &overridableProperties{},
2322 )
2323
2324 android.InitDefaultsModule(module)
2325 return module
2326}
2327
2328type OverrideApex struct {
2329 android.ModuleBase
2330 android.OverrideModuleBase
2331}
2332
2333func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2334 // All the overrides happen in the base module.
2335}
2336
2337// override_apex is used to create an apex module based on another apex module by overriding some of
2338// its properties.
2339func overrideApexFactory() android.Module {
2340 m := &OverrideApex{}
2341
2342 m.AddProperties(&overridableProperties{})
2343
2344 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2345 android.InitOverrideModule(m)
2346 return m
2347}
2348
2349///////////////////////////////////////////////////////////////////////////////////////////////////
2350// Vality check routines
2351//
2352// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2353// certain conditions are not met.
2354//
2355// TODO(jiyong): move these checks to a separate go file.
2356
satayevad991492021-12-03 18:58:32 +00002357var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2358
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002359// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2360// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002361func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002362 if a.testApex || a.vndkApex {
2363 return
2364 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002365 // apexBundle::minSdkVersion reports its own errors.
2366 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002367 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002368}
2369
satayevad991492021-12-03 18:58:32 +00002370func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2371 return android.SdkSpec{
2372 Kind: android.SdkNone,
2373 ApiLevel: a.minSdkVersion(ctx),
2374 Raw: String(a.properties.Min_sdk_version),
2375 }
2376}
2377
2378func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002379 ver := proptools.String(a.properties.Min_sdk_version)
2380 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002381 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002382 }
2383 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2384 if err != nil {
2385 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2386 return android.NoneApiLevel
2387 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002388 return apiLevel
2389}
2390
2391// Ensures that a lib providing stub isn't statically linked
2392func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2393 // Practically, we only care about regular APEXes on the device.
2394 if ctx.Host() || a.testApex || a.vndkApex {
2395 return
2396 }
2397
2398 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2399
2400 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2401 if ccm, ok := to.(*cc.Module); ok {
2402 apexName := ctx.ModuleName()
2403 fromName := ctx.OtherModuleName(from)
2404 toName := ctx.OtherModuleName(to)
2405
2406 // If `to` is not actually in the same APEX as `from` then it does not need
2407 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002408 //
2409 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002410 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2411 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2412 return false
2413 }
2414
2415 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2416 // exception to this rule. It can't make the static dependencies dynamic
2417 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002418 // Same rule should be applied to linkerconfig, because it should be executed
2419 // only with static linked libraries before linker is available with ld.config.txt
2420 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002421 return false
2422 }
2423
2424 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2425 if isStubLibraryFromOtherApex && !externalDep {
2426 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2427 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2428 }
2429
2430 }
2431 return true
2432 })
2433}
2434
satayevb98371c2021-06-15 16:49:50 +01002435// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002436func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2437 if a.Updatable() {
2438 if String(a.properties.Min_sdk_version) == "" {
2439 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2440 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002441 if a.UsePlatformApis() {
2442 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2443 }
Daniel Norman69109112021-12-02 12:52:42 -08002444 if a.SocSpecific() || a.DeviceSpecific() {
2445 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2446 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002447 if a.FutureUpdatable() {
2448 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2449 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002450 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002451 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002452 }
2453}
2454
satayevb98371c2021-06-15 16:49:50 +01002455// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2456func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2457 ctx.VisitDirectDeps(func(module android.Module) {
2458 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2459 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2460 if !info.ClasspathFragmentProtoGenerated {
2461 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2462 }
2463 }
2464 })
2465}
2466
2467// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002468func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002469 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2470 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002471 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2472 tag := ctx.OtherModuleDependencyTag(module)
2473 switch tag {
2474 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002475 if m, ok := module.(interface {
2476 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2477 }); ok {
2478 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002479 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2480 }
2481 }
2482 }
2483 })
2484}
2485
satayevb98371c2021-06-15 16:49:50 +01002486// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002487func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2488 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2489 if ctx.Host() || a.testApex || a.vndkApex {
2490 return
2491 }
2492
2493 // Because APEXes targeting other than system/system_ext partitions can't set
2494 // apex_available, we skip checks for these APEXes
2495 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2496 return
2497 }
2498
2499 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2500 // Requiring them and their transitive depencies with apex_available is not right
2501 // because they just add noise.
2502 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2503 return
2504 }
2505
2506 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2507 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2508 if externalDep {
2509 return false
2510 }
2511
2512 apexName := ctx.ModuleName()
2513 fromName := ctx.OtherModuleName(from)
2514 toName := ctx.OtherModuleName(to)
2515
2516 // If `to` is not actually in the same APEX as `from` then it does not need
2517 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002518 //
2519 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002520 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2521 // As soon as the dependency graph crosses the APEX boundary, don't go
2522 // further.
2523 return false
2524 }
2525
2526 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2527 return true
2528 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002529 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2530 "\n\nDependency path:%s\n\n"+
2531 "Consider adding %q to 'apex_available' property of %q",
2532 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002533 // Visit this module's dependencies to check and report any issues with their availability.
2534 return true
2535 })
2536}
2537
Jiyong Park192600a2021-08-03 07:52:17 +00002538// checkStaticExecutable ensures that executables in an APEX are not static.
2539func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002540 // No need to run this for host APEXes
2541 if ctx.Host() {
2542 return
2543 }
2544
Jiyong Park192600a2021-08-03 07:52:17 +00002545 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2546 if ctx.OtherModuleDependencyTag(module) != executableTag {
2547 return
2548 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002549
2550 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002551 apex := a.ApexVariationName()
2552 exec := ctx.OtherModuleName(module)
2553 if isStaticExecutableAllowed(apex, exec) {
2554 return
2555 }
2556 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2557 }
2558 })
2559}
2560
2561// A small list of exceptions where static executables are allowed in APEXes.
2562func isStaticExecutableAllowed(apex string, exec string) bool {
2563 m := map[string][]string{
2564 "com.android.runtime": []string{
2565 "linker",
2566 "linkerconfig",
2567 },
2568 }
2569 execNames, ok := m[apex]
2570 return ok && android.InList(exec, execNames)
2571}
2572
braleeb0c1f0c2021-06-07 22:49:13 +08002573// Collect information for opening IDE project files in java/jdeps.go.
2574func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2575 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2576 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2577 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2578 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2579}
2580
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002581var (
2582 apexAvailBaseline = makeApexAvailableBaseline()
2583 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2584)
2585
Colin Cross440e0d02020-06-11 11:32:11 -07002586func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002587 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002588 moduleName = normalizeModuleName(moduleName)
2589
Colin Cross440e0d02020-06-11 11:32:11 -07002590 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002591 return true
2592 }
2593
2594 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002595 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002596 return true
2597 }
2598
2599 return false
2600}
2601
2602func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002603 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2604 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002605 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002606 if strings.HasPrefix(moduleName, "libclang_rt.") {
2607 // This module has many arch variants that depend on the product being built.
2608 // We don't want to list them all
2609 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002610 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002611 if strings.HasPrefix(moduleName, "androidx.") {
2612 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2613 moduleName = "androidx"
2614 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002615 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002616}
2617
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002618// Transform the map of apex -> modules to module -> apexes.
2619func invertApexBaseline(m map[string][]string) map[string][]string {
2620 r := make(map[string][]string)
2621 for apex, modules := range m {
2622 for _, module := range modules {
2623 r[module] = append(r[module], apex)
2624 }
2625 }
2626 return r
2627}
2628
2629// Retrieve the baseline of apexes to which the supplied module belongs.
2630func BaselineApexAvailable(moduleName string) []string {
2631 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2632}
2633
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002634// This is a map from apex to modules, which overrides the apex_available setting for that
2635// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002636// TODO(b/147364041): remove this
2637func makeApexAvailableBaseline() map[string][]string {
2638 // The "Module separator"s below are employed to minimize merge conflicts.
2639 m := make(map[string][]string)
2640 //
2641 // Module separator
2642 //
2643 m["com.android.appsearch"] = []string{
2644 "icing-java-proto-lite",
2645 "libprotobuf-java-lite",
2646 }
2647 //
2648 // Module separator
2649 //
2650 m["com.android.bluetooth.updatable"] = []string{
2651 "android.hardware.audio.common@5.0",
2652 "android.hardware.bluetooth.a2dp@1.0",
2653 "android.hardware.bluetooth.audio@2.0",
2654 "android.hardware.bluetooth@1.0",
2655 "android.hardware.bluetooth@1.1",
2656 "android.hardware.graphics.bufferqueue@1.0",
2657 "android.hardware.graphics.bufferqueue@2.0",
2658 "android.hardware.graphics.common@1.0",
2659 "android.hardware.graphics.common@1.1",
2660 "android.hardware.graphics.common@1.2",
2661 "android.hardware.media@1.0",
2662 "android.hidl.safe_union@1.0",
2663 "android.hidl.token@1.0",
2664 "android.hidl.token@1.0-utils",
2665 "avrcp-target-service",
2666 "avrcp_headers",
2667 "bluetooth-protos-lite",
2668 "bluetooth.mapsapi",
2669 "com.android.vcard",
2670 "dnsresolver_aidl_interface-V2-java",
2671 "ipmemorystore-aidl-interfaces-V5-java",
2672 "ipmemorystore-aidl-interfaces-java",
2673 "internal_include_headers",
2674 "lib-bt-packets",
2675 "lib-bt-packets-avrcp",
2676 "lib-bt-packets-base",
2677 "libFraunhoferAAC",
2678 "libaudio-a2dp-hw-utils",
2679 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002680 "libbluetooth",
2681 "libbluetooth-types",
2682 "libbluetooth-types-header",
2683 "libbluetooth_gd",
2684 "libbluetooth_headers",
2685 "libbluetooth_jni",
2686 "libbt-audio-hal-interface",
2687 "libbt-bta",
2688 "libbt-common",
2689 "libbt-hci",
2690 "libbt-platform-protos-lite",
2691 "libbt-protos-lite",
2692 "libbt-sbc-decoder",
2693 "libbt-sbc-encoder",
2694 "libbt-stack",
2695 "libbt-utils",
2696 "libbtcore",
2697 "libbtdevice",
2698 "libbte",
2699 "libbtif",
2700 "libchrome",
2701 "libevent",
2702 "libfmq",
2703 "libg722codec",
2704 "libgui_headers",
2705 "libmedia_headers",
2706 "libmodpb64",
2707 "libosi",
2708 "libstagefright_foundation_headers",
2709 "libstagefright_headers",
2710 "libstatslog",
2711 "libstatssocket",
2712 "libtinyxml2",
2713 "libudrv-uipc",
2714 "libz",
2715 "media_plugin_headers",
2716 "net-utils-services-common",
2717 "netd_aidl_interface-unstable-java",
2718 "netd_event_listener_interface-java",
2719 "netlink-client",
2720 "networkstack-client",
2721 "sap-api-java-static",
2722 "services.net",
2723 }
2724 //
2725 // Module separator
2726 //
2727 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2728 //
2729 // Module separator
2730 //
2731 m["com.android.extservices"] = []string{
2732 "error_prone_annotations",
2733 "ExtServices-core",
2734 "ExtServices",
2735 "libtextclassifier-java",
2736 "libz_current",
2737 "textclassifier-statsd",
2738 "TextClassifierNotificationLibNoManifest",
2739 "TextClassifierServiceLibNoManifest",
2740 }
2741 //
2742 // Module separator
2743 //
2744 m["com.android.neuralnetworks"] = []string{
2745 "android.hardware.neuralnetworks@1.0",
2746 "android.hardware.neuralnetworks@1.1",
2747 "android.hardware.neuralnetworks@1.2",
2748 "android.hardware.neuralnetworks@1.3",
2749 "android.hidl.allocator@1.0",
2750 "android.hidl.memory.token@1.0",
2751 "android.hidl.memory@1.0",
2752 "android.hidl.safe_union@1.0",
2753 "libarect",
2754 "libbuildversion",
2755 "libmath",
2756 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002757 }
2758 //
2759 // Module separator
2760 //
2761 m["com.android.media"] = []string{
2762 "android.frameworks.bufferhub@1.0",
2763 "android.hardware.cas.native@1.0",
2764 "android.hardware.cas@1.0",
2765 "android.hardware.configstore-utils",
2766 "android.hardware.configstore@1.0",
2767 "android.hardware.configstore@1.1",
2768 "android.hardware.graphics.allocator@2.0",
2769 "android.hardware.graphics.allocator@3.0",
2770 "android.hardware.graphics.bufferqueue@1.0",
2771 "android.hardware.graphics.bufferqueue@2.0",
2772 "android.hardware.graphics.common@1.0",
2773 "android.hardware.graphics.common@1.1",
2774 "android.hardware.graphics.common@1.2",
2775 "android.hardware.graphics.mapper@2.0",
2776 "android.hardware.graphics.mapper@2.1",
2777 "android.hardware.graphics.mapper@3.0",
2778 "android.hardware.media.omx@1.0",
2779 "android.hardware.media@1.0",
2780 "android.hidl.allocator@1.0",
2781 "android.hidl.memory.token@1.0",
2782 "android.hidl.memory@1.0",
2783 "android.hidl.token@1.0",
2784 "android.hidl.token@1.0-utils",
2785 "bionic_libc_platform_headers",
2786 "exoplayer2-extractor",
2787 "exoplayer2-extractor-annotation-stubs",
2788 "gl_headers",
2789 "jsr305",
2790 "libEGL",
2791 "libEGL_blobCache",
2792 "libEGL_getProcAddress",
2793 "libFLAC",
2794 "libFLAC-config",
2795 "libFLAC-headers",
2796 "libGLESv2",
2797 "libaacextractor",
2798 "libamrextractor",
2799 "libarect",
2800 "libaudio_system_headers",
2801 "libaudioclient",
2802 "libaudioclient_headers",
2803 "libaudiofoundation",
2804 "libaudiofoundation_headers",
2805 "libaudiomanager",
2806 "libaudiopolicy",
2807 "libaudioutils",
2808 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002809 "libbluetooth-types-header",
2810 "libbufferhub",
2811 "libbufferhub_headers",
2812 "libbufferhubqueue",
2813 "libc_malloc_debug_backtrace",
2814 "libcamera_client",
2815 "libcamera_metadata",
2816 "libdvr_headers",
2817 "libexpat",
2818 "libfifo",
2819 "libflacextractor",
2820 "libgrallocusage",
2821 "libgraphicsenv",
2822 "libgui",
2823 "libgui_headers",
2824 "libhardware_headers",
2825 "libinput",
2826 "liblzma",
2827 "libmath",
2828 "libmedia",
2829 "libmedia_codeclist",
2830 "libmedia_headers",
2831 "libmedia_helper",
2832 "libmedia_helper_headers",
2833 "libmedia_midiiowrapper",
2834 "libmedia_omx",
2835 "libmediautils",
2836 "libmidiextractor",
2837 "libmkvextractor",
2838 "libmp3extractor",
2839 "libmp4extractor",
2840 "libmpeg2extractor",
2841 "libnativebase_headers",
2842 "libnativewindow_headers",
2843 "libnblog",
2844 "liboggextractor",
2845 "libpackagelistparser",
2846 "libpdx",
2847 "libpdx_default_transport",
2848 "libpdx_headers",
2849 "libpdx_uds",
2850 "libprocinfo",
2851 "libspeexresampler",
2852 "libspeexresampler",
2853 "libstagefright_esds",
2854 "libstagefright_flacdec",
2855 "libstagefright_flacdec",
2856 "libstagefright_foundation",
2857 "libstagefright_foundation_headers",
2858 "libstagefright_foundation_without_imemory",
2859 "libstagefright_headers",
2860 "libstagefright_id3",
2861 "libstagefright_metadatautils",
2862 "libstagefright_mpeg2extractor",
2863 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002864 "libui",
2865 "libui_headers",
2866 "libunwindstack",
2867 "libvibrator",
2868 "libvorbisidec",
2869 "libwavextractor",
2870 "libwebm",
2871 "media_ndk_headers",
2872 "media_plugin_headers",
2873 "updatable-media",
2874 }
2875 //
2876 // Module separator
2877 //
2878 m["com.android.media.swcodec"] = []string{
2879 "android.frameworks.bufferhub@1.0",
2880 "android.hardware.common-ndk_platform",
2881 "android.hardware.configstore-utils",
2882 "android.hardware.configstore@1.0",
2883 "android.hardware.configstore@1.1",
2884 "android.hardware.graphics.allocator@2.0",
2885 "android.hardware.graphics.allocator@3.0",
2886 "android.hardware.graphics.allocator@4.0",
2887 "android.hardware.graphics.bufferqueue@1.0",
2888 "android.hardware.graphics.bufferqueue@2.0",
2889 "android.hardware.graphics.common-ndk_platform",
2890 "android.hardware.graphics.common@1.0",
2891 "android.hardware.graphics.common@1.1",
2892 "android.hardware.graphics.common@1.2",
2893 "android.hardware.graphics.mapper@2.0",
2894 "android.hardware.graphics.mapper@2.1",
2895 "android.hardware.graphics.mapper@3.0",
2896 "android.hardware.graphics.mapper@4.0",
2897 "android.hardware.media.bufferpool@2.0",
2898 "android.hardware.media.c2@1.0",
2899 "android.hardware.media.c2@1.1",
2900 "android.hardware.media.omx@1.0",
2901 "android.hardware.media@1.0",
2902 "android.hardware.media@1.0",
2903 "android.hidl.memory.token@1.0",
2904 "android.hidl.memory@1.0",
2905 "android.hidl.safe_union@1.0",
2906 "android.hidl.token@1.0",
2907 "android.hidl.token@1.0-utils",
2908 "libEGL",
2909 "libFLAC",
2910 "libFLAC-config",
2911 "libFLAC-headers",
2912 "libFraunhoferAAC",
2913 "libLibGuiProperties",
2914 "libarect",
2915 "libaudio_system_headers",
2916 "libaudioutils",
2917 "libaudioutils",
2918 "libaudioutils_fixedfft",
2919 "libavcdec",
2920 "libavcenc",
2921 "libavservices_minijail",
2922 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002923 "libbinderthreadstateutils",
2924 "libbluetooth-types-header",
2925 "libbufferhub_headers",
2926 "libcodec2",
2927 "libcodec2_headers",
2928 "libcodec2_hidl@1.0",
2929 "libcodec2_hidl@1.1",
2930 "libcodec2_internal",
2931 "libcodec2_soft_aacdec",
2932 "libcodec2_soft_aacenc",
2933 "libcodec2_soft_amrnbdec",
2934 "libcodec2_soft_amrnbenc",
2935 "libcodec2_soft_amrwbdec",
2936 "libcodec2_soft_amrwbenc",
2937 "libcodec2_soft_av1dec_gav1",
2938 "libcodec2_soft_avcdec",
2939 "libcodec2_soft_avcenc",
2940 "libcodec2_soft_common",
2941 "libcodec2_soft_flacdec",
2942 "libcodec2_soft_flacenc",
2943 "libcodec2_soft_g711alawdec",
2944 "libcodec2_soft_g711mlawdec",
2945 "libcodec2_soft_gsmdec",
2946 "libcodec2_soft_h263dec",
2947 "libcodec2_soft_h263enc",
2948 "libcodec2_soft_hevcdec",
2949 "libcodec2_soft_hevcenc",
2950 "libcodec2_soft_mp3dec",
2951 "libcodec2_soft_mpeg2dec",
2952 "libcodec2_soft_mpeg4dec",
2953 "libcodec2_soft_mpeg4enc",
2954 "libcodec2_soft_opusdec",
2955 "libcodec2_soft_opusenc",
2956 "libcodec2_soft_rawdec",
2957 "libcodec2_soft_vorbisdec",
2958 "libcodec2_soft_vp8dec",
2959 "libcodec2_soft_vp8enc",
2960 "libcodec2_soft_vp9dec",
2961 "libcodec2_soft_vp9enc",
2962 "libcodec2_vndk",
2963 "libdvr_headers",
2964 "libfmq",
2965 "libfmq",
2966 "libgav1",
2967 "libgralloctypes",
2968 "libgrallocusage",
2969 "libgraphicsenv",
2970 "libgsm",
2971 "libgui_bufferqueue_static",
2972 "libgui_headers",
2973 "libhardware",
2974 "libhardware_headers",
2975 "libhevcdec",
2976 "libhevcenc",
2977 "libion",
2978 "libjpeg",
2979 "liblzma",
2980 "libmath",
2981 "libmedia_codecserviceregistrant",
2982 "libmedia_headers",
2983 "libmpeg2dec",
2984 "libnativebase_headers",
2985 "libnativewindow_headers",
2986 "libpdx_headers",
2987 "libscudo_wrapper",
2988 "libsfplugin_ccodec_utils",
2989 "libspeexresampler",
2990 "libstagefright_amrnb_common",
2991 "libstagefright_amrnbdec",
2992 "libstagefright_amrnbenc",
2993 "libstagefright_amrwbdec",
2994 "libstagefright_amrwbenc",
2995 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002996 "libstagefright_enc_common",
2997 "libstagefright_flacdec",
2998 "libstagefright_foundation",
2999 "libstagefright_foundation_headers",
3000 "libstagefright_headers",
3001 "libstagefright_m4vh263dec",
3002 "libstagefright_m4vh263enc",
3003 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003004 "libui",
3005 "libui_headers",
3006 "libunwindstack",
3007 "libvorbisidec",
3008 "libvpx",
3009 "libyuv",
3010 "libyuv_static",
3011 "media_ndk_headers",
3012 "media_plugin_headers",
3013 "mediaswcodec",
3014 }
3015 //
3016 // Module separator
3017 //
3018 m["com.android.mediaprovider"] = []string{
3019 "MediaProvider",
3020 "MediaProviderGoogle",
3021 "fmtlib_ndk",
3022 "libbase_ndk",
3023 "libfuse",
3024 "libfuse_jni",
3025 }
3026 //
3027 // Module separator
3028 //
3029 m["com.android.permission"] = []string{
3030 "car-ui-lib",
3031 "iconloader",
3032 "kotlin-annotations",
3033 "kotlin-stdlib",
3034 "kotlin-stdlib-jdk7",
3035 "kotlin-stdlib-jdk8",
3036 "kotlinx-coroutines-android",
3037 "kotlinx-coroutines-android-nodeps",
3038 "kotlinx-coroutines-core",
3039 "kotlinx-coroutines-core-nodeps",
3040 "permissioncontroller-statsd",
3041 "GooglePermissionController",
3042 "PermissionController",
3043 "SettingsLibActionBarShadow",
3044 "SettingsLibAppPreference",
3045 "SettingsLibBarChartPreference",
3046 "SettingsLibLayoutPreference",
3047 "SettingsLibProgressBar",
3048 "SettingsLibSearchWidget",
3049 "SettingsLibSettingsTheme",
3050 "SettingsLibRestrictedLockUtils",
3051 "SettingsLibHelpUtils",
3052 }
3053 //
3054 // Module separator
3055 //
3056 m["com.android.runtime"] = []string{
3057 "bionic_libc_platform_headers",
3058 "libarm-optimized-routines-math",
3059 "libc_aeabi",
3060 "libc_bionic",
3061 "libc_bionic_ndk",
3062 "libc_bootstrap",
3063 "libc_common",
3064 "libc_common_shared",
3065 "libc_common_static",
3066 "libc_dns",
3067 "libc_dynamic_dispatch",
3068 "libc_fortify",
3069 "libc_freebsd",
3070 "libc_freebsd_large_stack",
3071 "libc_gdtoa",
3072 "libc_init_dynamic",
3073 "libc_init_static",
3074 "libc_jemalloc_wrapper",
3075 "libc_netbsd",
3076 "libc_nomalloc",
3077 "libc_nopthread",
3078 "libc_openbsd",
3079 "libc_openbsd_large_stack",
3080 "libc_openbsd_ndk",
3081 "libc_pthread",
3082 "libc_static_dispatch",
3083 "libc_syscalls",
3084 "libc_tzcode",
3085 "libc_unwind_static",
3086 "libdebuggerd",
3087 "libdebuggerd_common_headers",
3088 "libdebuggerd_handler_core",
3089 "libdebuggerd_handler_fallback",
3090 "libdl_static",
3091 "libjemalloc5",
3092 "liblinker_main",
3093 "liblinker_malloc",
3094 "liblz4",
3095 "liblzma",
3096 "libprocinfo",
3097 "libpropertyinfoparser",
3098 "libscudo",
3099 "libstdc++",
3100 "libsystemproperties",
3101 "libtombstoned_client_static",
3102 "libunwindstack",
3103 "libz",
3104 "libziparchive",
3105 }
3106 //
3107 // Module separator
3108 //
3109 m["com.android.tethering"] = []string{
3110 "android.hardware.tetheroffload.config-V1.0-java",
3111 "android.hardware.tetheroffload.control-V1.0-java",
3112 "android.hidl.base-V1.0-java",
3113 "libcgrouprc",
3114 "libcgrouprc_format",
3115 "libtetherutilsjni",
3116 "libvndksupport",
3117 "net-utils-framework-common",
3118 "netd_aidl_interface-V3-java",
3119 "netlink-client",
3120 "networkstack-aidl-interfaces-java",
3121 "tethering-aidl-interfaces-java",
3122 "TetheringApiCurrentLib",
3123 }
3124 //
3125 // Module separator
3126 //
3127 m["com.android.wifi"] = []string{
3128 "PlatformProperties",
3129 "android.hardware.wifi-V1.0-java",
3130 "android.hardware.wifi-V1.0-java-constants",
3131 "android.hardware.wifi-V1.1-java",
3132 "android.hardware.wifi-V1.2-java",
3133 "android.hardware.wifi-V1.3-java",
3134 "android.hardware.wifi-V1.4-java",
3135 "android.hardware.wifi.hostapd-V1.0-java",
3136 "android.hardware.wifi.hostapd-V1.1-java",
3137 "android.hardware.wifi.hostapd-V1.2-java",
3138 "android.hardware.wifi.supplicant-V1.0-java",
3139 "android.hardware.wifi.supplicant-V1.1-java",
3140 "android.hardware.wifi.supplicant-V1.2-java",
3141 "android.hardware.wifi.supplicant-V1.3-java",
3142 "android.hidl.base-V1.0-java",
3143 "android.hidl.manager-V1.0-java",
3144 "android.hidl.manager-V1.1-java",
3145 "android.hidl.manager-V1.2-java",
3146 "bouncycastle-unbundled",
3147 "dnsresolver_aidl_interface-V2-java",
3148 "error_prone_annotations",
3149 "framework-wifi-pre-jarjar",
3150 "framework-wifi-util-lib",
3151 "ipmemorystore-aidl-interfaces-V3-java",
3152 "ipmemorystore-aidl-interfaces-java",
3153 "ksoap2",
3154 "libnanohttpd",
3155 "libwifi-jni",
3156 "net-utils-services-common",
3157 "netd_aidl_interface-V2-java",
3158 "netd_aidl_interface-unstable-java",
3159 "netd_event_listener_interface-java",
3160 "netlink-client",
3161 "networkstack-client",
3162 "services.net",
3163 "wifi-lite-protos",
3164 "wifi-nano-protos",
3165 "wifi-service-pre-jarjar",
3166 "wifi-service-resources",
3167 }
3168 //
3169 // Module separator
3170 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003171 m["com.android.os.statsd"] = []string{
3172 "libstatssocket",
3173 }
3174 //
3175 // Module separator
3176 //
3177 m[android.AvailableToAnyApex] = []string{
3178 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3179 "androidx",
3180 "androidx-constraintlayout_constraintlayout",
3181 "androidx-constraintlayout_constraintlayout-nodeps",
3182 "androidx-constraintlayout_constraintlayout-solver",
3183 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3184 "com.google.android.material_material",
3185 "com.google.android.material_material-nodeps",
3186
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003187 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003188 "libprofile-clang-extras",
3189 "libprofile-clang-extras_ndk",
3190 "libprofile-extras",
3191 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003192 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003193 }
3194 return m
3195}
3196
3197func init() {
3198 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3199 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3200}
3201
3202func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3203 rules := make([]android.Rule, 0, len(modules_packages))
3204 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003205 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003206 BootclasspathJar().
3207 With("apex_available", module_name).
3208 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003209 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003210 Because("jars that are part of the " + module_name +
3211 " module may only allow these packages: " + strings.Join(module_packages, ",") +
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003212 " with min_sdk < T. Please jarjar or move code around.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003213 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003214 }
3215 return rules
3216}
3217
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003218// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on Q/R/S.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003219// Adding code to the bootclasspath in new packages will cause issues on module update.
3220func qModulesPackages() map[string][]string {
3221 return map[string][]string{
3222 "com.android.conscrypt": []string{
3223 "android.net.ssl",
3224 "com.android.org.conscrypt",
3225 },
3226 "com.android.media": []string{
3227 "android.media",
3228 },
3229 }
3230}
3231
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003232// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on R/S.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003233// Adding code to the bootclasspath in new packages will cause issues on module update.
3234func rModulesPackages() map[string][]string {
3235 return map[string][]string{
3236 "com.android.mediaprovider": []string{
3237 "android.provider",
3238 },
3239 "com.android.permission": []string{
3240 "android.permission",
3241 "android.app.role",
3242 "com.android.permission",
3243 "com.android.role",
3244 },
3245 "com.android.sdkext": []string{
3246 "android.os.ext",
3247 },
3248 "com.android.os.statsd": []string{
3249 "android.app",
3250 "android.os",
3251 "android.util",
3252 "com.android.internal.statsd",
3253 "com.android.server.stats",
3254 },
3255 "com.android.wifi": []string{
3256 "com.android.server.wifi",
3257 "com.android.wifi.x",
3258 "android.hardware.wifi",
3259 "android.net.wifi",
3260 },
3261 "com.android.tethering": []string{
3262 "android.net",
3263 },
3264 }
3265}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003266
3267// For Bazel / bp2build
3268
3269type bazelApexBundleAttributes struct {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003270 Manifest bazel.LabelAttribute
3271 Android_manifest bazel.LabelAttribute
3272 File_contexts bazel.LabelAttribute
3273 Key bazel.LabelAttribute
3274 Certificate bazel.LabelAttribute
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003275 Min_sdk_version *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003276 Updatable bazel.BoolAttribute
3277 Installable bazel.BoolAttribute
3278 Native_shared_libs bazel.LabelListAttribute
Jingwen Chenb07c9012021-12-08 10:05:45 +00003279 Binaries bazel.LabelListAttribute
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003280 Prebuilts bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003281}
3282
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003283// ConvertWithBp2build performs bp2build conversion of an apex
3284func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3285 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003286 if ctx.ModuleType() != "apex" {
3287 return
3288 }
3289
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003290 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003291 if a.properties.Manifest != nil {
3292 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003293 }
3294
3295 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003296 if a.properties.AndroidManifest != nil {
3297 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003298 }
3299
3300 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003301 if a.properties.File_contexts != nil {
3302 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003303 }
3304
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003305 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003306 if a.properties.Min_sdk_version != nil {
3307 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003308 }
3309
3310 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003311 if a.overridableProperties.Key != nil {
3312 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003313 }
3314
3315 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003316 if a.overridableProperties.Certificate != nil {
3317 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003318 }
3319
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003320 nativeSharedLibs := a.properties.ApexNativeDependencies.Native_shared_libs
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003321 nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
3322 nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
3323
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003324 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003325 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3326 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3327
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003328 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003329 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003330
3331 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003332 if a.properties.Updatable != nil {
3333 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003334 }
3335
3336 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003337 if a.properties.Installable != nil {
3338 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003339 }
3340
3341 attrs := &bazelApexBundleAttributes{
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003342 Manifest: manifestLabelAttribute,
3343 Android_manifest: androidManifestLabelAttribute,
3344 File_contexts: fileContextsLabelAttribute,
3345 Min_sdk_version: minSdkVersion,
3346 Key: keyLabelAttribute,
3347 Certificate: certificateLabelAttribute,
3348 Updatable: updatableAttribute,
3349 Installable: installableAttribute,
3350 Native_shared_libs: nativeSharedLibsLabelListAttribute,
Jingwen Chenb07c9012021-12-08 10:05:45 +00003351 Binaries: binariesLabelListAttribute,
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003352 Prebuilts: prebuiltsLabelListAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003353 }
3354
3355 props := bazel.BazelTargetModuleProperties{
3356 Rule_class: "apex",
3357 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3358 }
3359
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003360 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003361}