blob: 6d8a67a5ca807f0ae6c4c1dd8ded9d14dc7ec586 [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()
Spandan Das66773252022-01-15 00:23:18 +000079 // Register after apex_info mutator so that it can use ApexVariationName
80 ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090081}
82
83type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090084 // Json manifest file describing meta info of this APEX bundle. Refer to
85 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090086 Manifest *string `android:"path"`
87
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090088 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
89 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090090 AndroidManifest *string `android:"path"`
91
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090092 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
93 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090094 Apex_name *string
95
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090096 // Determines the file contexts file for setting the security contexts to files in this APEX
97 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
98 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090099 File_contexts *string `android:"path"`
100
Jiyong Park038e8522021-12-13 23:56:35 +0900101 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
102 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
103 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
104 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
105 // capability. If this property is not set, or a file is missing in the file, default config
106 // is used.
107 Canned_fs_config *string `android:"path"`
108
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900109 ApexNativeDependencies
110
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900111 Multilib apexMultilibProperties
112
Sundong Ahn80c04892021-11-23 00:57:19 +0000113 // List of sh binaries that are embedded inside this APEX bundle.
114 Sh_binaries []string
115
Paul Duffin3abc1742021-03-15 19:32:23 +0000116 // List of platform_compat_config files that are embedded inside this APEX bundle.
117 Compat_configs []string
118
Jiyong Park12a719c2021-01-07 15:31:24 +0900119 // List of filesystem images that are embedded inside this APEX bundle.
120 Filesystems []string
121
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900122 // The minimum SDK version that this APEX must support at minimum. This is usually set to
123 // the SDK version that the APEX was first introduced.
124 Min_sdk_version *string
125
126 // Whether this APEX is considered updatable or not. When set to true, this will enforce
127 // additional rules for making sure that the APEX is truly updatable. To be updatable,
128 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000129 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900130 Updatable *bool
131
Jiyong Parkf4020582021-11-29 12:37:10 +0900132 // Marks that this APEX is designed to be updatable in the future, although it's not
133 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
134 // updatable APEXes. Currently, this disables the size optimization, so that the size of
135 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
136 // false.
137 Future_updatable *bool
138
Jiyong Park1bc84122021-06-22 20:23:05 +0900139 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
140 // false`. Default is false.
141 Platform_apis *bool
142
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900143 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
144 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900145 Installable *bool
146
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900147 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
148 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
149 Use_vndk_as_stable *bool
150
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000151 // Whether this is multi-installed APEX should skip installing symbol files.
152 // Multi-installed APEXes share the same apex_name and are installed at the same time.
153 // Default is false.
154 //
155 // Should be set to true for all multi-installed APEXes except the singular
156 // default version within the multi-installed group.
157 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
158 // or else conflicting build rules may be created.
159 Multi_install_skip_symbol_files *bool
160
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900161 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
162 // `name#version` or `name` which is an alias for `name#current`. If left empty,
163 // `platform#current` is implied. This value affects all modules included in this APEX. In
164 // other words, they are also built with the SDKs specified here.
165 Uses_sdks []string
166
167 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
168 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
169 // container. When set to zip, contents are stored in a zip container directly. This type is
170 // mostly for host-side debugging. When set to both, the two types are both built. Default
171 // is 'image'.
172 Payload_type *string
173
Huang Jianan13cac632021-08-02 15:02:17 +0800174 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
175 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900176 Payload_fs_type *string
177
178 // For telling the APEX to ignore special handling for system libraries such as bionic.
179 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900180 Ignore_system_library_special_case *bool
181
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100182 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100183 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100184 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900185
186 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
187 // used in tests.
188 Test_only_unsigned_payload *bool
189
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000190 // Whenever apex should be compressed, regardless of product flag used. Should be only
191 // used in tests.
192 Test_only_force_compression *bool
193
Jooyung Han09c11ad2021-10-27 03:45:31 +0900194 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
195 // with the tool to sign payload contents.
196 Custom_sign_tool *string
197
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100198 // Canonical name of this APEX bundle. Used to determine the path to the
199 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
200 // apex mutator variations. For override_apex modules, this is the name of the
201 // overridden base module.
202 ApexVariationName string `blueprint:"mutated"`
203
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900204 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900205
206 // List of sanitizer names that this APEX is enabled for
207 SanitizerNames []string `blueprint:"mutated"`
208
209 PreventInstall bool `blueprint:"mutated"`
210
211 HideFromMake bool `blueprint:"mutated"`
212
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900213 // Internal package method for this APEX. When payload_type is image, this can be either
214 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
215 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900216 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900217}
218
219type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900220 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900221 Native_shared_libs []string
222
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900223 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900224 Jni_libs []string
225
Jiyong Park99644e92020-11-17 22:21:02 +0900226 // List of rust dyn libraries
227 Rust_dyn_libs []string
228
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900229 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900230 Binaries []string
231
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900232 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900233 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900234
235 // List of filesystem images that are embedded inside this APEX bundle.
236 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900237}
238
239type apexMultilibProperties struct {
240 // Native dependencies whose compile_multilib is "first"
241 First ApexNativeDependencies
242
243 // Native dependencies whose compile_multilib is "both"
244 Both ApexNativeDependencies
245
246 // Native dependencies whose compile_multilib is "prefer32"
247 Prefer32 ApexNativeDependencies
248
249 // Native dependencies whose compile_multilib is "32"
250 Lib32 ApexNativeDependencies
251
252 // Native dependencies whose compile_multilib is "64"
253 Lib64 ApexNativeDependencies
254}
255
256type apexTargetBundleProperties struct {
257 Target struct {
258 // Multilib properties only for android.
259 Android struct {
260 Multilib apexMultilibProperties
261 }
262
263 // Multilib properties only for host.
264 Host struct {
265 Multilib apexMultilibProperties
266 }
267
268 // Multilib properties only for host linux_bionic.
269 Linux_bionic struct {
270 Multilib apexMultilibProperties
271 }
272
273 // Multilib properties only for host linux_glibc.
274 Linux_glibc struct {
275 Multilib apexMultilibProperties
276 }
277 }
278}
279
Jiyong Park59140302020-12-14 18:44:04 +0900280type apexArchBundleProperties struct {
281 Arch struct {
282 Arm struct {
283 ApexNativeDependencies
284 }
285 Arm64 struct {
286 ApexNativeDependencies
287 }
288 X86 struct {
289 ApexNativeDependencies
290 }
291 X86_64 struct {
292 ApexNativeDependencies
293 }
294 }
295}
296
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900297// These properties can be used in override_apex to override the corresponding properties in the
298// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900299type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900300 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900301 Apps []string
302
Daniel Norman5a3ce132021-08-26 15:44:43 -0700303 // List of prebuilt files that are embedded inside this APEX bundle.
304 Prebuilts []string
305
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900306 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900307 Rros []string
308
markchien7c803b82021-08-26 22:10:06 +0800309 // List of BPF programs inside this APEX bundle.
310 Bpfs []string
311
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900312 // List of bootclasspath fragments that are embedded inside this APEX bundle.
313 Bootclasspath_fragments []string
314
315 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
316 Systemserverclasspath_fragments []string
317
318 // List of java libraries that are embedded inside this APEX bundle.
319 Java_libs []string
320
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900321 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
322 // Soong). This does not completely prevent installation of the overridden binaries, but if
323 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
324 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900325 Overrides []string
326
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900327 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900328 Logging_parent string
329
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900330 // Apex Container package name. Override value for attribute package:name in
331 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900332 Package_name string
333
334 // A txt file containing list of files that are allowed to be included in this APEX.
335 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700336
337 // Name of the apex_key module that provides the private key to sign this APEX bundle.
338 Key *string
339
340 // Specifies the certificate and the private key to sign the zip container of this APEX. If
341 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
342 // as the certificate and the private key, respectively. If this is ":module", then the
343 // certificate and the private key are provided from the android_app_certificate module
344 // named "module".
345 Certificate *string
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -0400346
347 // Whether this APEX can be compressed or not. Setting this property to false means this
348 // APEX will never be compressed. When set to true, APEX will be compressed if other
349 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
350 // Default: false.
351 Compressible *bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352}
353
354type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900355 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356 android.ModuleBase
357 android.DefaultableModuleBase
358 android.OverridableModuleBase
359 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400360 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363 properties apexBundleProperties
364 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900365 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900366 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900367 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900368
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 ///////////////////////////////////////////////////////////////////////////////////////////
370 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900372 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800373 publicKeyFile android.Path
374 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900375
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800377 containerCertificateFile android.Path
378 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900379
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900380 // Flags for special variants of APEX
381 testApex bool
382 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900384 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
385 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900386 primaryApexType bool
387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900388 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900389 suffix string
390
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900391 // File system type of apex_payload.img
392 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900393
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900394 // Whether to create symlink to the system file instead of having a file inside the apex or
395 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900396 linkToSystemLib bool
397
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900398 // List of files to be included in this APEX. This is filled in the first part of
399 // GenerateAndroidBuildActions.
400 filesInfo []apexFile
401
402 // List of other module names that should be installed when this APEX gets installed.
403 requiredDeps []string
404
405 ///////////////////////////////////////////////////////////////////////////////////////////
406 // Outputs (final and intermediates)
407
408 // Processed apex manifest in JSONson format (for Q)
409 manifestJsonOut android.WritablePath
410
411 // Processed apex manifest in PB format (for R+)
412 manifestPbOut android.WritablePath
413
414 // Processed file_contexts files
415 fileContexts android.WritablePath
416
Wei Sheng Shih77807b32022-04-01 02:05:36 +0000417 // Struct holding the merged notice file paths in different formats
418 mergedNotices android.NoticeOutputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900420 // The built APEX file. This is the main product.
Jooyung Hana6d36672022-02-24 13:58:07 +0900421 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900422 outputFile android.WritablePath
423
Jooyung Hana6d36672022-02-24 13:58:07 +0900424 // The built uncompressed .apex file.
425 outputApexFile android.WritablePath
426
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900427 // The built APEX file in app bundle format. This file is not directly installed to the
428 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
429 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
430 // system) to be merged into a single app bundle file that Play accepts. See
431 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
432 bundleModuleFile android.WritablePath
433
Colin Cross6340ea52021-11-04 12:01:18 -0700434 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900435 installDir android.InstallPath
436
Colin Cross6340ea52021-11-04 12:01:18 -0700437 // Path where this APEX was installed.
438 installedFile android.InstallPath
439
440 // Installed locations of symlinks for backward compatibility.
441 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900442
443 // Text file having the list of individual files that are included in this APEX. Used for
444 // debugging purpose.
445 installedFilesFile android.WritablePath
446
447 // List of module names that this APEX is including (to be shown via *-deps-info target).
448 // Used for debugging purpose.
449 android.ApexBundleDepsInfo
450
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900451 // Optional list of lint report zip files for apexes that contain java or app modules
452 lintReports android.Paths
453
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900454 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000455
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000456 isCompressed bool
457
sophiezc80a2b32020-11-12 16:39:19 +0000458 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700459 nativeApisUsedByModuleFile android.ModuleOutPath
460 nativeApisBackedByModuleFile android.ModuleOutPath
461 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800462
463 // Collect the module directory for IDE info in java/jdeps.go.
464 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900465}
466
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900467// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900468type apexFileClass int
469
Jooyung Han72bd2f82019-10-23 16:46:38 +0900470const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900471 app apexFileClass = iota
472 appSet
473 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900474 goBinary
475 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900476 nativeExecutable
477 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900478 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900479 pyBinary
480 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900481)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900482
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900483// apexFile represents a file in an APEX bundle. This is created during the first half of
484// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
485// of the function, this is used to create commands that copies the files into a staging directory,
486// where they are packaged into the APEX file. This struct is also used for creating Make modules
487// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900488type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900489 // buildFile is put in the installDir inside the APEX.
Wei Sheng Shih77807b32022-04-01 02:05:36 +0000490 builtFile android.Path
491 noticeFiles android.Paths
492 installDir string
493 customStem string
494 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900495
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900496 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
497 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
498 // suffix>]
499 androidMkModuleName string // becomes LOCAL_MODULE
500 class apexFileClass // becomes LOCAL_MODULE_CLASS
501 moduleDir string // becomes LOCAL_PATH
502 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
503 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
504 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
505 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900506
507 jacocoReportClassesFile android.Path // only for javalibs and apps
508 lintDepSets java.LintDepSets // only for javalibs and apps
509 certificate java.Certificate // only for apps
510 overriddenPackageName string // only for apps
511
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900512 transitiveDep bool
513 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900514
Jiyong Park57621b22021-01-20 20:33:11 +0900515 multilib string
516
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900517 // TODO(jiyong): remove this
518 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900519}
520
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900521// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900522func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
523 ret := apexFile{
524 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900525 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900526 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900527 class: class,
528 module: module,
529 }
530 if module != nil {
Wei Sheng Shih77807b32022-04-01 02:05:36 +0000531 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900532 ret.moduleDir = ctx.OtherModuleDir(module)
533 ret.requiredModuleNames = module.RequiredModuleNames()
534 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
535 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900536 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900537 }
538 return ret
539}
540
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900541func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900542 return af.builtFile != nil && af.builtFile.String() != ""
543}
544
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900545// apexRelativePath returns the relative path of the given path from the install directory of this
546// apexFile.
547// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900548func (af *apexFile) apexRelativePath(path string) string {
549 return filepath.Join(af.installDir, path)
550}
551
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900552// path returns path of this apex file relative to the APEX root
553func (af *apexFile) path() string {
554 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900555}
556
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900557// stem returns the base filename of this apex file
558func (af *apexFile) stem() string {
559 if af.customStem != "" {
560 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900561 }
562 return af.builtFile.Base()
563}
564
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900565// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
566func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900567 var ret []string
568 for _, symlink := range af.symlinks {
569 ret = append(ret, af.apexRelativePath(symlink))
570 }
571 return ret
572}
573
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900574// availableToPlatform tests whether this apexFile is from a module that can be installed to the
575// platform.
576func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900577 if af.module == nil {
578 return false
579 }
580 if am, ok := af.module.(android.ApexModule); ok {
581 return am.AvailableFor(android.AvailableToPlatform)
582 }
583 return false
584}
585
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900586////////////////////////////////////////////////////////////////////////////////////////////////////
587// Mutators
588//
589// Brief description about mutators for APEX. The following three mutators are the most important
590// ones.
591//
592// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
593// to the (direct) dependencies of this APEX bundle.
594//
Paul Duffin949abc02020-12-08 10:34:30 +0000595// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900596// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
597// modules are marked as being included in the APEX via BuildForApex().
598//
Paul Duffin949abc02020-12-08 10:34:30 +0000599// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
600// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900601
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900602type dependencyTag struct {
603 blueprint.BaseDependencyTag
604 name string
605
606 // Determines if the dependent will be part of the APEX payload. Can be false for the
607 // dependencies to the signing key module, etc.
608 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000609
610 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
611 // replacement. This is needed because some prebuilt modules do not provide all the information
612 // needed by the apex.
613 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900614}
615
Paul Duffin8c535da2021-03-17 14:51:03 +0000616func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
617 return !d.sourceOnly
618}
619
620var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
621
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900622var (
Paul Duffin0b817782021-03-17 15:02:19 +0000623 androidAppTag = dependencyTag{name: "androidApp", payload: true}
624 bpfTag = dependencyTag{name: "bpf", payload: true}
625 certificateTag = dependencyTag{name: "certificate"}
626 executableTag = dependencyTag{name: "executable", payload: true}
627 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100628 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100629 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000630 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000631 javaLibTag = dependencyTag{name: "javaLib", payload: true}
632 jniLibTag = dependencyTag{name: "jniLib", payload: true}
633 keyTag = dependencyTag{name: "key"}
634 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
635 rroTag = dependencyTag{name: "rro", payload: true}
636 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
637 testForTag = dependencyTag{name: "test for"}
638 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000639 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640)
641
642// TODO(jiyong): shorten this function signature
643func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900644 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900645 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900646 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647
648 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900649 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900650 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
651 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 }
653
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900654 // Use *FarVariation* to be able to depend on modules having conflicting variations with
655 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
656 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900657 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900658 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900659 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
660 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900661 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900662 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900663}
664
665func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900666 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
668 } else {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
670 if ctx.Os().Bionic() {
671 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
672 } else {
673 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
674 }
675 }
676}
677
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900678// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
679// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
680func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
681 deviceConfig := ctx.DeviceConfig()
682 if a.vndkApex {
683 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900684 }
685
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900686 var prefix string
687 var vndkVersion string
688 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000689 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900690 prefix = cc.VendorVariationPrefix
691 vndkVersion = deviceConfig.VndkVersion()
692 } else if a.ProductSpecific() {
693 prefix = cc.ProductVariationPrefix
694 vndkVersion = deviceConfig.ProductVndkVersion()
695 }
696 }
697 if vndkVersion == "current" {
698 vndkVersion = deviceConfig.PlatformVndkVersion()
699 }
700 if vndkVersion != "" {
701 return prefix + vndkVersion
702 }
703
704 return android.CoreVariation // The usual case
705}
706
707func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900708 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
709 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
710 // each target os/architectures, appropriate dependencies are selected by their
711 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900712 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900713 imageVariation := a.getImageVariation(ctx)
714
715 a.combineProperties(ctx)
716
717 has32BitTarget := false
718 for _, target := range targets {
719 if target.Arch.ArchType.Multilib == "lib32" {
720 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000721 }
722 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900723 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900724 // Don't include artifacts for the host cross targets because there is no way for us
725 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900726 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900727 continue
728 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000729
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000731
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900732 // Add native modules targeting both ABIs. When multilib.* is omitted for
733 // native_shared_libs/jni_libs/tests, it implies multilib.both
734 depsList = append(depsList, a.properties.Multilib.Both)
735 depsList = append(depsList, ApexNativeDependencies{
736 Native_shared_libs: a.properties.Native_shared_libs,
737 Tests: a.properties.Tests,
738 Jni_libs: a.properties.Jni_libs,
739 Binaries: nil,
740 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900741
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900742 // Add native modules targeting the first ABI When multilib.* is omitted for
743 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900744 isPrimaryAbi := i == 0
745 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900746 depsList = append(depsList, a.properties.Multilib.First)
747 depsList = append(depsList, ApexNativeDependencies{
748 Native_shared_libs: nil,
749 Tests: nil,
750 Jni_libs: nil,
751 Binaries: a.properties.Binaries,
752 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900753 }
754
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900755 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900756 switch target.Arch.ArchType.Multilib {
757 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900758 depsList = append(depsList, a.properties.Multilib.Lib32)
759 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900762 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900763 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900764 }
765 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900766
Jiyong Park59140302020-12-14 18:44:04 +0900767 // Add native modules targeting a specific arch variant
768 switch target.Arch.ArchType {
769 case android.Arm:
770 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
771 case android.Arm64:
772 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
773 case android.X86:
774 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
775 case android.X86_64:
776 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
777 default:
778 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
779 }
780
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900781 for _, d := range depsList {
782 addDependenciesForNativeModules(ctx, d, target, imageVariation)
783 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000784 ctx.AddFarVariationDependencies([]blueprint.Variation{
785 {Mutator: "os", Variation: target.OsVariation()},
786 {Mutator: "arch", Variation: target.ArchVariation()},
787 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900788 }
789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900790 // Common-arch dependencies come next
791 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Jiyong Park12a719c2021-01-07 15:31:24 +0900792 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000793 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900794
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900795 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
796 // This field currently isn't used.
797 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900798 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
799 if len(a.properties.Uses_sdks) > 0 {
800 sdkRefs := []android.SdkRef{}
801 for _, str := range a.properties.Uses_sdks {
802 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
803 sdkRefs = append(sdkRefs, parsed)
804 }
805 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100806 }
807}
808
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900809// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900810func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
811 if a.overridableProperties.Allowed_files != nil {
812 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100813 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900814
815 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
816 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800817 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900818 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900819 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.overridableProperties.Bootclasspath_fragments...)
820 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.overridableProperties.Systemserverclasspath_fragments...)
821 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.overridableProperties.Java_libs...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700822 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
823 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
824 // regardless of the TARGET_PREFER_* setting. See b/144532908
825 arches := ctx.DeviceConfig().Arches()
826 if len(arches) != 0 {
827 archForPrebuiltEtc := arches[0]
828 for _, arch := range arches {
829 // Prefer 64-bit arch if there is any
830 if arch.ArchType.Multilib == "lib64" {
831 archForPrebuiltEtc = arch
832 break
833 }
834 }
835 ctx.AddFarVariationDependencies([]blueprint.Variation{
836 {Mutator: "os", Variation: ctx.Os().String()},
837 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
838 }, prebuiltTag, prebuilts...)
839 }
840 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700841
842 // Dependencies for signing
843 if String(a.overridableProperties.Key) == "" {
844 ctx.PropertyErrorf("key", "missing")
845 return
846 }
847 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
848
849 cert := android.SrcIsModule(a.getCertString(ctx))
850 if cert != "" {
851 ctx.AddDependency(ctx.Module(), certificateTag, cert)
852 // empty cert is not an error. Cert and private keys will be directly found under
853 // PRODUCT_DEFAULT_DEV_CERTIFICATE
854 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100855}
856
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900857type ApexBundleInfo struct {
858 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100859}
860
Paul Duffin949abc02020-12-08 10:34:30 +0000861var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862
Paul Duffina7d6a892020-12-07 17:39:59 +0000863var _ ApexInfoMutator = (*apexBundle)(nil)
864
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100865func (a *apexBundle) ApexVariationName() string {
866 return a.properties.ApexVariationName
867}
868
Paul Duffina7d6a892020-12-07 17:39:59 +0000869// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900870// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
871// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
872// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
873// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000874//
875// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
876// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
877// The apexMutator uses that list to create module variants for the apexes to which it belongs.
878// The relationship between module variants and apexes is not one-to-one as variants will be
879// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000880func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900881
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900882 // The VNDK APEX is special. For the APEX, the membership is described in a very different
883 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
884 // libraries are self-identified by their vndk.enabled properties. There is no need to run
885 // this mutator for the APEX as nothing will be collected. So, let's return fast.
886 if a.vndkApex {
887 return
888 }
889
890 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
891 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
892 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
893 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
894 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900895 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
896 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900897 if proptools.Bool(a.properties.Use_vndk_as_stable) {
898 if !useVndk {
899 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
900 }
901 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
902 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
903 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
904 }
905 })
906 if mctx.Failed() {
907 return
908 }
Jooyung Handf78e212020-07-22 15:54:47 +0900909 }
910
Colin Cross56a83212020-09-15 18:30:11 -0700911 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900912 am, ok := child.(android.ApexModule)
913 if !ok || !am.CanHaveApexVariants() {
914 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900915 }
Paul Duffin573989d2021-03-17 13:25:29 +0000916 depTag := mctx.OtherModuleDependencyTag(child)
917
918 // Check to see if the tag always requires that the child module has an apex variant for every
919 // apex variant of the parent module. If it does not then it is still possible for something
920 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
921 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
922 return true
923 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000924 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900925 return false
926 }
Jooyung Handf78e212020-07-22 15:54:47 +0900927 if excludeVndkLibs {
928 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
929 return false
930 }
931 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900932 // By default, all the transitive dependencies are collected, unless filtered out
933 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700934 return true
935 }
936
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900937 // Records whether a certain module is included in this apexBundle via direct dependency or
938 // inndirect dependency.
939 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700940 mctx.WalkDeps(func(child, parent android.Module) bool {
941 if !continueApexDepsWalk(child, parent) {
942 return false
943 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900944 // If the parent is apexBundle, this child is directly depended.
945 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900946 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700947 contents[depName] = contents[depName].Add(directDep)
948 return true
949 })
950
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900951 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900952 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700953 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
954 Contents: apexContents,
955 })
956
Jooyung Haned124c32021-01-26 11:43:46 +0900957 minSdkVersion := a.minSdkVersion(mctx)
958 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
959 if minSdkVersion.IsNone() {
960 minSdkVersion = android.FutureApiLevel
961 }
962
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900963 // This is the main part of this mutator. Mark the collected dependencies that they need to
964 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900965
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100966 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
967 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700968 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100969 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900970 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700971 RequiredSdks: a.RequiredSdks(),
972 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900973 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100974 InApexVariants: []string{apexVariationName},
975 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700976 ApexContents: []*android.ApexContents{apexContents},
977 }
Colin Cross56a83212020-09-15 18:30:11 -0700978 mctx.WalkDeps(func(child, parent android.Module) bool {
979 if !continueApexDepsWalk(child, parent) {
980 return false
981 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900982 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900983 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900984 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900985}
986
Paul Duffina7d6a892020-12-07 17:39:59 +0000987type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100988 // ApexVariationName returns the name of the APEX variation to use in the apex
989 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
990 ApexVariationName() string
991
Paul Duffina7d6a892020-12-07 17:39:59 +0000992 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
993 // depended upon by an apex and which require an apex specific variant.
994 ApexInfoMutator(android.TopDownMutatorContext)
995}
996
997// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
998// specific variant to modules that support the ApexInfoMutator.
999func apexInfoMutator(mctx android.TopDownMutatorContext) {
1000 if !mctx.Module().Enabled() {
1001 return
1002 }
1003
1004 if a, ok := mctx.Module().(ApexInfoMutator); ok {
1005 a.ApexInfoMutator(mctx)
1006 return
1007 }
1008}
1009
Spandan Das66773252022-01-15 00:23:18 +00001010// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
1011// This check is enforced for updatable modules
1012func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
1013 if !mctx.Module().Enabled() {
1014 return
1015 }
Spandan Das08c911f2022-01-21 22:07:26 +00001016 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +00001017 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001018 // b/208656169 Do not propagate strict updatability linting to libcore/
1019 // These libs are available on the classpath during compilation
1020 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1021 // Only skip libraries defined in libcore root, not subdirectories
1022 if mctx.OtherModuleDir(child) == "libcore" {
1023 // Do not traverse transitive deps of libcore/ libs
1024 return false
1025 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001026 if android.InList(child.Name(), skipLintJavalibAllowlist) {
1027 return false
1028 }
Spandan Das66773252022-01-15 00:23:18 +00001029 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1030 lintable.SetStrictUpdatabilityLinting(true)
1031 }
1032 // visit transitive deps
1033 return true
1034 })
1035 }
1036}
1037
Spandan Das08c911f2022-01-21 22:07:26 +00001038// TODO: b/215736885 Whittle the denylist
1039// Transitive deps of certain mainline modules baseline NewApi errors
1040// Skip these mainline modules for now
1041var (
1042 skipStrictUpdatabilityLintAllowlist = []string{
1043 "com.android.art",
1044 "com.android.art.debug",
1045 "com.android.conscrypt",
1046 "com.android.media",
1047 // test apexes
1048 "test_com.android.art",
1049 "test_com.android.conscrypt",
1050 "test_com.android.media",
1051 "test_jitzygote_com.android.art",
1052 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001053
1054 // TODO: b/215736885 Remove this list
1055 skipLintJavalibAllowlist = []string{
1056 "conscrypt.module.platform.api.stubs",
1057 "conscrypt.module.public.api.stubs",
1058 "conscrypt.module.public.api.stubs.system",
1059 "conscrypt.module.public.api.stubs.module_lib",
1060 "framework-media.stubs",
1061 "framework-media.stubs.system",
1062 "framework-media.stubs.module_lib",
1063 }
Spandan Das08c911f2022-01-21 22:07:26 +00001064)
1065
1066func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1067 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1068}
1069
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001070// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1071// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1072// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001073func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1074 if !mctx.Module().Enabled() {
1075 return
1076 }
1077 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001078 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1079 }
1080}
1081
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001082// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1083// the apex in order to retrieve its contents later.
1084// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001085func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1086 if !mctx.Module().Enabled() {
1087 return
1088 }
Colin Cross56a83212020-09-15 18:30:11 -07001089 if am, ok := mctx.Module().(android.ApexModule); ok {
1090 if testFor := am.TestFor(); len(testFor) > 0 {
1091 mctx.AddFarVariationDependencies([]blueprint.Variation{
1092 {Mutator: "os", Variation: am.Target().OsVariation()},
1093 {"arch", "common"},
1094 }, testForTag, testFor...)
1095 }
1096 }
1097}
1098
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001099// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001100func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1101 if !mctx.Module().Enabled() {
1102 return
1103 }
Colin Cross56a83212020-09-15 18:30:11 -07001104 if _, ok := mctx.Module().(android.ApexModule); ok {
1105 var contents []*android.ApexContents
1106 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1107 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1108 contents = append(contents, abInfo.Contents)
1109 }
1110 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1111 ApexContents: contents,
1112 })
Colin Crossaede88c2020-08-11 12:17:01 -07001113 }
1114}
1115
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001116// markPlatformAvailability marks whether or not a module can be available to platform. A module
1117// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1118// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1119// be) available to platform
1120// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001121func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1122 // Host and recovery are not considered as platform
1123 if mctx.Host() || mctx.Module().InstallInRecovery() {
1124 return
1125 }
1126
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001127 am, ok := mctx.Module().(android.ApexModule)
1128 if !ok {
1129 return
1130 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001131
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001132 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001133
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001134 // If any of the dep is not available to platform, this module is also considered as being
1135 // not available to platform even if it has "//apex_available:platform"
1136 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001137 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001138 // if the dependency crosses apex boundary, don't consider it
1139 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001140 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001141 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1142 availableToPlatform = false
1143 // TODO(b/154889534) trigger an error when 'am' has
1144 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001145 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001146 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001147
Paul Duffinb5769c12021-05-12 16:16:51 +01001148 // Exception 1: check to see if the module always requires it.
1149 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001150 availableToPlatform = true
1151 }
1152
1153 // Exception 2: bootstrap bionic libraries are also always available to platform
1154 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1155 availableToPlatform = true
1156 }
1157
1158 if !availableToPlatform {
1159 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001160 }
1161}
1162
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001163// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001164// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001165func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001166 if !mctx.Module().Enabled() {
1167 return
1168 }
Colin Cross56a83212020-09-15 18:30:11 -07001169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001170 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001171 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001172 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001173 return
1174 }
1175
1176 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001177 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1178 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001179 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001180 if strings.HasPrefix(apexBundleName, "com.android.art") {
1181 // Create an alias from the platform variant. This is done to make
1182 // test_for dependencies work for modules that are split by the APEX
1183 // mutator, since test_for dependencies always go to the platform variant.
1184 // This doesn't happen for normal APEXes that are disjunct, so only do
1185 // this for the overlapping ART APEXes.
1186 // TODO(b/183882457): Remove this if the test_for functionality is
1187 // refactored to depend on the proper APEX variants instead of platform.
1188 mctx.CreateAliasVariation("", apexBundleName)
1189 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001190 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1191 apexBundleName := o.GetOverriddenModuleName()
1192 if apexBundleName == "" {
1193 mctx.ModuleErrorf("base property is not set")
1194 return
1195 }
1196 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001197 if strings.HasPrefix(apexBundleName, "com.android.art") {
1198 // TODO(b/183882457): See note for CreateAliasVariation above.
1199 mctx.CreateAliasVariation("", apexBundleName)
1200 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001201 }
1202}
Sundong Ahne9b55722019-09-06 17:37:42 +09001203
Paul Duffin6717d882021-06-15 19:09:41 +01001204// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1205// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001206func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001207 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001208 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001209 return !a.vndkApex
1210 }
1211
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001212 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001213}
1214
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001215// See android.UpdateDirectlyInAnyApex
1216// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001217func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1218 if !mctx.Module().Enabled() {
1219 return
1220 }
1221 if am, ok := mctx.Module().(android.ApexModule); ok {
1222 android.UpdateDirectlyInAnyApex(mctx, am)
1223 }
1224}
1225
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001226// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001227type apexPackaging int
1228
1229const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001230 // imageApex is a packaging method where contents are included in a filesystem image which
1231 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001232 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001233
1234 // zipApex is a packaging method where contents are directly included in the zip container.
1235 // This is used for host-side testing - because the contents are easily accessible by
1236 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001237 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001238
1239 // flattendApex is a packaging method where contents are not included in the APEX file, but
1240 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1241 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001242 flattenedApex
1243)
1244
1245const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001247 imageApexSuffix = ".apex"
1248 imageCapexSuffix = ".capex"
1249 zipApexSuffix = ".zipapex"
1250 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001251
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001252 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001253 imageApexType = "image"
1254 zipApexType = "zip"
1255 flattenedApexType = "flattened"
1256
Dan Willemsen47e1a752021-10-16 18:36:13 -07001257 ext4FsType = "ext4"
1258 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001259 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001260)
1261
1262// The suffix for the output "file", not the module
1263func (a apexPackaging) suffix() string {
1264 switch a {
1265 case imageApex:
1266 return imageApexSuffix
1267 case zipApex:
1268 return zipApexSuffix
1269 default:
1270 panic(fmt.Errorf("unknown APEX type %d", a))
1271 }
1272}
1273
1274func (a apexPackaging) name() string {
1275 switch a {
1276 case imageApex:
1277 return imageApexType
1278 case zipApex:
1279 return zipApexType
1280 default:
1281 panic(fmt.Errorf("unknown APEX type %d", a))
1282 }
1283}
1284
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001285// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1286// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001287func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001288 if !mctx.Module().Enabled() {
1289 return
1290 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001291 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001292 var variants []string
1293 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1294 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001295 // This is the normal case. Note that both image and flattend APEXes are
1296 // created. The image type is installed to the system partition, while the
1297 // flattened APEX is (optionally) installed to the system_ext partition.
1298 // This is mostly for GSI which has to support wide range of devices. If GSI
1299 // is installed on a newer (APEX-capable) device, the image APEX in the
1300 // system will be used. However, if the same GSI is installed on an old
1301 // device which can't support image APEX, the flattened APEX in the
1302 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001303 variants = append(variants, imageApexType, flattenedApexType)
1304 case "zip":
1305 variants = append(variants, zipApexType)
1306 case "both":
1307 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1308 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001309 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001310 return
1311 }
1312
1313 modules := mctx.CreateLocalVariations(variants...)
1314
1315 for i, v := range variants {
1316 switch v {
1317 case imageApexType:
1318 modules[i].(*apexBundle).properties.ApexType = imageApex
1319 case zipApexType:
1320 modules[i].(*apexBundle).properties.ApexType = zipApex
1321 case flattenedApexType:
1322 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001323 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001324 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001325 modules[i].(*apexBundle).MakeAsSystemExt()
1326 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001327 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001328 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001329 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001330 // payload_type is forcibly overridden to "image"
1331 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001332 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001333 }
1334}
1335
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001336var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001337
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001338// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001339func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1340 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001341 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001342 return true
1343}
1344
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001345var _ android.OutputFileProducer = (*apexBundle)(nil)
1346
1347// Implements android.OutputFileProducer
1348func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1349 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001350 case "", android.DefaultDistTag:
1351 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001352 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001353 case imageApexSuffix:
1354 // uncompressed one
1355 if a.outputApexFile != nil {
1356 return android.Paths{a.outputApexFile}, nil
1357 }
1358 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001359 default:
1360 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1361 }
1362}
1363
1364var _ cc.Coverage = (*apexBundle)(nil)
1365
1366// Implements cc.Coverage
1367func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1368 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1369}
1370
1371// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001372func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001373 a.properties.PreventInstall = true
1374}
1375
1376// Implements cc.Coverage
1377func (a *apexBundle) HideFromMake() {
1378 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001379 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1380 // TODO(ccross): untangle these
1381 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001382}
1383
1384// Implements cc.Coverage
1385func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1386 a.properties.IsCoverageVariant = coverage
1387}
1388
1389// Implements cc.Coverage
1390func (a *apexBundle) EnableCoverageIfNeeded() {}
1391
1392var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1393
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001394// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001395func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001396 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397}
1398
Jiyong Parkf4020582021-11-29 12:37:10 +09001399func (a *apexBundle) FutureUpdatable() bool {
1400 return proptools.BoolDefault(a.properties.Future_updatable, false)
1401}
1402
Jiyong Park1bc84122021-06-22 20:23:05 +09001403func (a *apexBundle) UsePlatformApis() bool {
1404 return proptools.BoolDefault(a.properties.Platform_apis, false)
1405}
1406
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001407// getCertString returns the name of the cert that should be used to sign this APEX. This is
1408// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001409func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001410 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001411 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1412 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1413 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001414 if a.vndkApex {
1415 moduleName = vndkApexName
1416 }
1417 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001418 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001419 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001420 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001421 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001422}
1423
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001424// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001425func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001426 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001427}
1428
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001429// See the generate_hashtree property
1430func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001431 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001432}
1433
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001434// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001435func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1436 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1437}
1438
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001439// See the test_only_force_compression property
1440func (a *apexBundle) testOnlyShouldForceCompression() bool {
1441 return proptools.Bool(a.properties.Test_only_force_compression)
1442}
1443
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001444// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1445// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1446// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001447
Jiyong Parkf97782b2019-02-13 20:28:58 +09001448func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1449 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1450 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1451 }
1452}
1453
Jiyong Park388ef3f2019-01-28 19:47:32 +09001454func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001455 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1456 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001457 }
1458
1459 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001460 globalSanitizerNames := []string{}
1461 if a.Host() {
1462 globalSanitizerNames = ctx.Config().SanitizeHost()
1463 } else {
1464 arches := ctx.Config().SanitizeDeviceArch()
1465 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1466 globalSanitizerNames = ctx.Config().SanitizeDevice()
1467 }
1468 }
1469 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001470}
1471
Jooyung Han8ce8db92020-05-15 19:05:05 +09001472func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001473 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1474 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001475 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001476 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001477 for _, target := range ctx.MultiTargets() {
1478 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001479 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Cross4c4c1be2022-02-10 11:41:18 -08001480 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001481 Tests: nil,
1482 Jni_libs: nil,
1483 Binaries: nil,
1484 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001485 break
1486 }
1487 }
1488 }
1489}
1490
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001491// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1492// returned apexFile saves information about the Soong module that will be used for creating the
1493// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001494func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001495 // Decide the APEX-local directory by the multilib of the library In the future, we may
1496 // query this to the module.
1497 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001498 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001499 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001500 case "lib32":
1501 dirInApex = "lib"
1502 case "lib64":
1503 dirInApex = "lib64"
1504 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001505 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001506 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001507 }
Jooyung Han35155c42020-02-06 17:33:20 +09001508 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001509 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001510 // Special case for Bionic libs and other libs installed with them. This is to
1511 // prevent those libs from being included in the search path
1512 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1513 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1514 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1515 // will be loaded into the default linker namespace (aka "platform" namespace). If
1516 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1517 // be loaded again into the runtime linker namespace, which will result in double
1518 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001519 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001520 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001521
Jiyong Parkf653b052019-11-18 15:39:01 +09001522 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001523 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1524 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001525}
1526
Jiyong Park1833cef2019-12-13 13:28:36 +09001527func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001528 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001529 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001530 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001531 }
Jooyung Han35155c42020-02-06 17:33:20 +09001532 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001533 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001534 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1535 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001536 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001537 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001538 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001539}
1540
Jiyong Park99644e92020-11-17 22:21:02 +09001541func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1542 dirInApex := "bin"
1543 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1544 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1545 }
1546 fileToCopy := rustm.OutputFile().Path()
1547 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1548 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1549 return af
1550}
1551
1552func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1553 // Decide the APEX-local directory by the multilib of the library
1554 // In the future, we may query this to the module.
1555 var dirInApex string
1556 switch rustm.Arch().ArchType.Multilib {
1557 case "lib32":
1558 dirInApex = "lib"
1559 case "lib64":
1560 dirInApex = "lib64"
1561 }
1562 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1563 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1564 }
1565 fileToCopy := rustm.OutputFile().Path()
1566 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1567 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1568}
1569
Jiyong Park1833cef2019-12-13 13:28:36 +09001570func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001571 dirInApex := "bin"
1572 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001573 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001574}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001575
Jiyong Park1833cef2019-12-13 13:28:36 +09001576func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001577 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001578 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001579 // NB: Since go binaries are static we don't need the module for anything here, which is
1580 // good since the go tool is a blueprint.Module not an android.Module like we would
1581 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001582 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001583}
1584
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001585func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001586 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001587 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1588 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1589 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001590 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001591 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001592 af.symlinks = sh.Symlinks()
1593 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001594}
1595
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001596func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001597 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001598 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001599 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001600}
1601
atrost6e126252020-01-27 17:01:16 +00001602func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1603 dirInApex := filepath.Join("etc", config.SubDir())
1604 fileToCopy := config.CompatConfig()
1605 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1606}
1607
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001608// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1609// way.
1610type javaModule interface {
1611 android.Module
1612 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001613 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001614 JacocoReportClassesFile() android.Path
1615 LintDepSets() java.LintDepSets
1616 Stem() string
1617}
1618
1619var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001620var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001621var _ javaModule = (*java.SdkLibrary)(nil)
1622var _ javaModule = (*java.DexImport)(nil)
1623var _ javaModule = (*java.SdkLibraryImport)(nil)
1624
Paul Duffin190fdef2021-04-26 10:33:59 +01001625// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001626func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001627 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001628}
1629
1630// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1631func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001633 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001634 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1635 af.lintDepSets = module.LintDepSets()
1636 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001637 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1638 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1639 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1640 }
1641 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001642 return af
1643}
1644
1645// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1646// the same way.
1647type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001648 android.Module
1649 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001650 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001651 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001652 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001653 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001654 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001655 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001656}
1657
1658var _ androidApp = (*java.AndroidApp)(nil)
1659var _ androidApp = (*java.AndroidAppImport)(nil)
1660
1661func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001662 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001664 appDir = "priv-app"
1665 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001666 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001667 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001668 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001669 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001670 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001671 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001672
1673 if app, ok := aapp.(interface {
1674 OverriddenManifestPackageName() string
1675 }); ok {
1676 af.overriddenPackageName = app.OverriddenManifestPackageName()
1677 }
Jiyong Park618922e2020-01-08 13:35:43 +09001678 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001679}
1680
Jiyong Park69aeba92020-04-24 21:16:36 +09001681func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1682 rroDir := "overlay"
1683 dirInApex := filepath.Join(rroDir, rro.Theme())
1684 fileToCopy := rro.OutputFile()
1685 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1686 af.certificate = rro.Certificate()
1687
1688 if a, ok := rro.(interface {
1689 OverriddenManifestPackageName() string
1690 }); ok {
1691 af.overriddenPackageName = a.OverriddenManifestPackageName()
1692 }
1693 return af
1694}
1695
Ken Chenfad7f9d2021-11-10 22:02:57 +08001696func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1697 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001698 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1699}
1700
Jiyong Park12a719c2021-01-07 15:31:24 +09001701func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1702 dirInApex := filepath.Join("etc", "fs")
1703 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1704}
1705
Paul Duffin064b70c2020-11-02 17:32:38 +00001706// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001707// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1708// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1709// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001710func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001711 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001712 am, ok := child.(android.ApexModule)
1713 if !ok || !am.CanHaveApexVariants() {
1714 return false
1715 }
1716
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001717 // Filter-out unwanted depedendencies
1718 depTag := ctx.OtherModuleDependencyTag(child)
1719 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1720 return false
1721 }
1722 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001723 return false
1724 }
1725
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001726 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001727 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001728
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001729 // Visit actually
1730 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001731 })
1732}
1733
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001734// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1735type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001736
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001737const (
1738 ext4 fsType = iota
1739 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001740 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001741)
Artur Satayev849f8442020-04-28 14:57:42 +01001742
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001743func (f fsType) string() string {
1744 switch f {
1745 case ext4:
1746 return ext4FsType
1747 case f2fs:
1748 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001749 case erofs:
1750 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001751 default:
1752 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001753 }
1754}
1755
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001756// Creates build rules for an APEX. It consists of the following major steps:
1757//
1758// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1759// 2) traverse the dependency tree to collect apexFile structs from them.
1760// 3) some fields in apexBundle struct are configured
1761// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001762func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001763 ////////////////////////////////////////////////////////////////////////////////////////////
1764 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001765 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001766 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001767 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001768 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001769 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001770 if len(a.properties.Tests) > 0 && !a.testApex {
1771 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1772 return
1773 }
Jiyong Park678c8812020-02-07 17:25:49 +09001774
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001775 ////////////////////////////////////////////////////////////////////////////////////////////
1776 // 2) traverse the dependency tree to collect apexFile structs from them.
1777
1778 // all the files that will be included in this APEX
1779 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001780
Jooyung Hane1633032019-08-01 17:41:43 +09001781 // native lib dependencies
1782 var provideNativeLibs []string
1783 var requireNativeLibs []string
1784
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001785 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1786
braleeb0c1f0c2021-06-07 22:49:13 +08001787 // Collect the module directory for IDE info in java/jdeps.go.
1788 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001790 // TODO(jiyong): do this using WalkPayloadDeps
1791 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001792 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001793 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001794 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1795 return false
1796 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001797 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1798 return false
1799 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001800 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001801 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001802 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001803 case sharedLibTag, jniLibTag:
1804 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001805 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001806 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1807 fi.isJniLib = isJniLib
1808 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001809 // Collect the list of stub-providing libs except:
1810 // - VNDK libs are only for vendors
1811 // - bootstrap bionic libs are treated as provided by system
1812 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001813 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001814 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001815 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001816 } else if r, ok := child.(*rust.Module); ok {
1817 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001818 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001819 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001820 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001821 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001822 propertyName := "native_shared_libs"
1823 if isJniLib {
1824 propertyName = "jni_libs"
1825 }
1826 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001827 }
1828 case executableTag:
1829 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001830 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001831 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001832 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001833 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001834 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001835 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001836 } else if rust, ok := child.(*rust.Module); ok {
1837 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1838 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001839 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001840 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1841 }
1842 case shBinaryTag:
1843 if sh, ok := child.(*sh.ShBinary); ok {
1844 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1845 } else {
1846 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001847 }
Paul Duffin94f19632021-04-20 12:40:07 +01001848 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001849 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001850 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1851 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001852 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001853 return false
1854 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001855
Paul Duffincc33ec82021-04-25 23:14:55 +01001856 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1857 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001858 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1859 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1860 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001861 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001862 }
satayev333a1732021-05-17 21:35:26 +01001863 case sscpfTag:
1864 {
1865 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1866 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1867 return false
1868 }
satayevb98371c2021-06-15 16:49:50 +01001869 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1870 filesInfo = append(filesInfo, *af)
1871 }
satayev333a1732021-05-17 21:35:26 +01001872 return true
1873 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001874 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001875 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001876 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001877 af := apexFileForJavaModule(ctx, child.(javaModule))
1878 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001879 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1880 return false
1881 }
1882 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001883 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001884 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001885 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001886 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001887 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001888 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001889 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001890 return true // track transitive dependencies
1891 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001892 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001893 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001894 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001895 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1896 appDir := "app"
1897 if ap.Privileged() {
1898 appDir = "priv-app"
1899 }
Yo Chiange8128052020-07-23 20:09:18 +08001900 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001901 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1902 af.certificate = java.PresignedCertificate
1903 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001904 } else {
1905 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1906 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001907 case rroTag:
1908 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1909 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1910 } else {
1911 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1912 }
markchien2f59ec92020-09-02 16:23:38 +08001913 case bpfTag:
1914 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1915 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001916 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001917 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001918 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001919 }
1920 } else {
1921 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1922 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001923 case fsTag:
1924 if fs, ok := child.(filesystem.Filesystem); ok {
1925 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1926 } else {
1927 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1928 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001929 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001930 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001931 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001932 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001933 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001934 }
Paul Duffin0b817782021-03-17 15:02:19 +00001935 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001936 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1937 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1938 } else {
1939 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1940 }
Roland Levillain630846d2019-06-26 12:48:34 +01001941 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001942 if ccTest, ok := child.(*cc.Module); ok {
1943 if ccTest.IsTestPerSrcAllTestsVariation() {
1944 // Multiple-output test module (where `test_per_src: true`).
1945 //
1946 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1947 // We do not add this variation to `filesInfo`, as it has no output;
1948 // however, we do add the other variations of this module as indirect
1949 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001950 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001951 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001952 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001953 af.class = nativeTest
1954 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001955 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001956 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001957 } else {
1958 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1959 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001960 case keyTag:
1961 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001962 a.privateKeyFile = key.privateKeyFile
1963 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001964 } else {
1965 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001966 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001967 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001968 case certificateTag:
1969 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001970 a.containerCertificateFile = dep.Certificate.Pem
1971 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001972 } else {
1973 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1974 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001975 case android.PrebuiltDepTag:
1976 // If the prebuilt is force disabled, remember to delete the prebuilt file
1977 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001978 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001979 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1980 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001981 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001982 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001983 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001984 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001985 // We cannot use a switch statement on `depTag` here as the checked
1986 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001987 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001988 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001989 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001990 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001991 return false
1992 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001993 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1994 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001995
1996 // Always track transitive dependencies for host.
1997 if a.Host() {
1998 filesInfo = append(filesInfo, af)
1999 return true
2000 }
2001
Colin Cross56a83212020-09-15 18:30:11 -07002002 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002003 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002004 // If the dependency is a stubs lib, don't include it in this APEX,
2005 // but make sure that the lib is installed on the device.
2006 // In case no APEX is having the lib, the lib is installed to the system
2007 // partition.
2008 //
2009 // Always include if we are a host-apex however since those won't have any
2010 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002011 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002012 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00002013 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002014 if !android.InList(name, a.requiredDeps) {
2015 a.requiredDeps = append(a.requiredDeps, name)
2016 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002017 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002018 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002019 // Don't track further
2020 return false
2021 }
Jiyong Parke3867542020-12-03 17:28:25 +09002022
2023 // If the dep is not considered to be in the same
2024 // apex, don't add it to filesInfo so that it is not
2025 // included in this APEX.
2026 // TODO(jiyong): move this to at the top of the
2027 // else-if clause for the indirect dependencies.
2028 // Currently, that's impossible because we would
2029 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002030 // DepIsInSameAPex is false. We also shouldn't do
2031 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002032 //
2033 // TODO(jiyong): explain why the same module is passed in twice.
2034 // Switching the first am to parent breaks lots of tests.
2035 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002036 return false
2037 }
2038
Jiyong Parkf653b052019-11-18 15:39:01 +09002039 filesInfo = append(filesInfo, af)
2040 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002041 } else if rm, ok := child.(*rust.Module); ok {
2042 af := apexFileForRustLibrary(ctx, rm)
2043 af.transitiveDep = true
2044 filesInfo = append(filesInfo, af)
2045 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002046 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002047 } else if cc.IsTestPerSrcDepTag(depTag) {
2048 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002049 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002050 // Handle modules created as `test_per_src` variations of a single test module:
2051 // use the name of the generated test binary (`fileToCopy`) instead of the name
2052 // of the original test module (`depName`, shared by all `test_per_src`
2053 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002054 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002055 // these are not considered transitive dep
2056 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002057 filesInfo = append(filesInfo, af)
2058 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002059 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002060 } else if cc.IsHeaderDepTag(depTag) {
2061 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002062 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002063 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2064 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002065 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002066 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002067 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2068 }
Jiyong Park99644e92020-11-17 22:21:02 +09002069 } else if rust.IsDylibDepTag(depTag) {
2070 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2071 af := apexFileForRustLibrary(ctx, rustm)
2072 af.transitiveDep = true
2073 filesInfo = append(filesInfo, af)
2074 return true // track transitive dependencies
2075 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002076 } else if rust.IsRlibDepTag(depTag) {
2077 // Rlib is statically linked, but it might have shared lib
2078 // dependencies. Track them.
2079 return true
Paul Duffin65898052021-04-20 22:47:03 +01002080 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002081 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002082 switch child.(type) {
2083 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002084 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002085 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002086 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002087 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002088 return false
2089 }
2090 filesInfo = append(filesInfo, af)
2091 return true // track transitive dependencies
2092 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002093 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 +00002094 }
satayev333a1732021-05-17 21:35:26 +01002095 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2096 // Add the contents of the systemserverclasspath fragment to the apex.
2097 switch child.(type) {
2098 case *java.Library, *java.SdkLibrary:
2099 af := apexFileForJavaModule(ctx, child.(javaModule))
2100 filesInfo = append(filesInfo, af)
2101 return true // track transitive dependencies
2102 default:
2103 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2104 }
Colin Cross56a83212020-09-15 18:30:11 -07002105 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2106 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002107 } else if depTag == android.DarwinUniversalVariantTag {
2108 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002109 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002110 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002111 }
2112 }
2113 }
2114 return false
2115 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002116 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002117 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002118 return
2119 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002120
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002121 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002123 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002124 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002125 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002126 if e, ok := encountered[dest]; !ok {
2127 encountered[dest] = f
2128 } else {
2129 // If a module is directly included and also transitively depended on
2130 // consider it as directly included.
2131 e.transitiveDep = e.transitiveDep && f.transitiveDep
2132 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002133 }
2134 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002135 var result []apexFile
2136 for _, v := range encountered {
2137 result = append(result, v)
2138 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002139 return result
2140 }
2141 filesInfo = removeDup(filesInfo)
2142
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002143 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002144 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002145 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2146 // changes.
2147 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002148 })
2149
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002150 ////////////////////////////////////////////////////////////////////////////////////////////
2151 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002152 a.installDir = android.PathForModuleInstall(ctx, "apex")
2153 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002154
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002155 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002156 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002157 switch a.properties.ApexType {
2158 case imageApex:
2159 if buildFlattenedAsDefault {
2160 a.suffix = imageApexSuffix
2161 } else {
2162 a.suffix = ""
2163 a.primaryApexType = true
2164
2165 if ctx.Config().InstallExtraFlattenedApexes() {
2166 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2167 }
2168 }
2169 case zipApex:
2170 if proptools.String(a.properties.Payload_type) == "zip" {
2171 a.suffix = ""
2172 a.primaryApexType = true
2173 } else {
2174 a.suffix = zipApexSuffix
2175 }
2176 case flattenedApex:
2177 if buildFlattenedAsDefault {
2178 a.suffix = ""
2179 a.primaryApexType = true
2180 } else {
2181 a.suffix = flattenedSuffix
2182 }
2183 }
2184
Theotime Combes4ba38c12020-06-12 12:46:59 +00002185 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2186 case ext4FsType:
2187 a.payloadFsType = ext4
2188 case f2fsFsType:
2189 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002190 case erofsFsType:
2191 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002192 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002193 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 +00002194 }
2195
Jiyong Park7cd10e32020-01-14 09:22:18 +09002196 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2197 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2198 // the same library in the system partition, thus effectively sharing the same libraries
2199 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2200 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002201 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002202
Jooyung Han85d61762020-06-24 23:50:26 +09002203 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2204 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002205 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002206 a.linkToSystemLib = false
2207 }
2208
Jiyong Park4da07972021-01-05 21:01:11 +09002209 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002210 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002211
Jiyong Park9d677202020-02-19 16:29:35 +09002212 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002213 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002214 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002215 a.linkToSystemLib = false
2216 }
2217
Jiyong Park638d30e2020-02-26 18:27:19 +09002218 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2219 if ctx.Host() {
2220 a.linkToSystemLib = false
2221 }
2222
Colin Cross6340ea52021-11-04 12:01:18 -07002223 if a.properties.ApexType != zipApex {
2224 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2225 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002226
2227 ////////////////////////////////////////////////////////////////////////////////////////////
2228 // 4) generate the build rules to create the APEX. This is done in builder.go.
2229 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002230 if a.properties.ApexType == flattenedApex {
2231 a.buildFlattenedApex(ctx)
2232 } else {
2233 a.buildUnflattenedApex(ctx)
2234 }
Jiyong Park956305c2020-01-09 12:32:06 +09002235 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002236 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002237
2238 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2239 if a.installable() {
2240 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2241 // along with other ordinary files. (Note that this is done by apexer for
2242 // non-flattened APEXes)
2243 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2244
2245 // Place the public key as apex_pubkey. This is also done by apexer for
2246 // non-flattened APEXes case.
2247 // TODO(jiyong): Why do we need this CP rule?
2248 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2249 ctx.Build(pctx, android.BuildParams{
2250 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002251 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002252 Output: copiedPubkey,
2253 })
2254 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2255 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002256}
2257
Paul Duffincc33ec82021-04-25 23:14:55 +01002258// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2259// the bootclasspath_fragment contributes to the apex.
2260func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2261 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2262 var filesToAdd []apexFile
2263
2264 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002265 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2266 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2267 dirInApex := filepath.Join("javalib", arch.String())
2268 for _, f := range files {
2269 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2270 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2271 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2272 filesToAdd = append(filesToAdd, af)
2273 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002274 }
2275 }
2276
satayev3db35472021-05-06 23:59:58 +01002277 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002278 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2279 filesToAdd = append(filesToAdd, *af)
2280 }
satayev3db35472021-05-06 23:59:58 +01002281
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002282 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2283 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2284 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2285
2286 if pathOnHost != nil {
2287 // We need to copy the profile to a temporary path with the right filename because the apexer
2288 // will take the filename as is.
2289 ctx.Build(pctx, android.BuildParams{
2290 Rule: android.Cp,
2291 Input: pathOnHost,
2292 Output: tempPath,
2293 })
2294 } else {
2295 // At this point, the boot image profile cannot be generated. It is probably because the boot
2296 // image profile source file does not exist on the branch, or it is not available for the
2297 // current build target.
2298 // However, we cannot enforce the boot image profile to be generated because some build
2299 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2300 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2301 // only if the APEX is being built.
2302 ctx.Build(pctx, android.BuildParams{
2303 Rule: android.ErrorRule,
2304 Output: tempPath,
2305 Args: map[string]string{
2306 "error": "Boot image profile cannot be generated",
2307 },
2308 })
2309 }
2310
2311 androidMkModuleName := filepath.Base(pathInApex)
2312 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2313 filesToAdd = append(filesToAdd, af)
2314 }
2315
Paul Duffincc33ec82021-04-25 23:14:55 +01002316 return filesToAdd
2317}
2318
satayevb98371c2021-06-15 16:49:50 +01002319// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2320// the module contributes to the apex; or nil if the proto config was not generated.
2321func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2322 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2323 if !info.ClasspathFragmentProtoGenerated {
2324 return nil
2325 }
2326 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2327 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2328 return &af
satayev14e49132021-05-17 21:03:07 +01002329}
2330
Paul Duffincc33ec82021-04-25 23:14:55 +01002331// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2332// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002333func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2334 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2335
2336 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2337 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002338 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2339 if err != nil {
2340 ctx.ModuleErrorf("%s", err)
2341 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002342
2343 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2344 // bootclasspath_fragment.
2345 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2346 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002347}
2348
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002349///////////////////////////////////////////////////////////////////////////////////////////////////
2350// Factory functions
2351//
2352
2353func newApexBundle() *apexBundle {
2354 module := &apexBundle{}
2355
2356 module.AddProperties(&module.properties)
2357 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002358 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002359 module.AddProperties(&module.overridableProperties)
2360
2361 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2362 android.InitDefaultableModule(module)
2363 android.InitSdkAwareModule(module)
2364 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002365 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002366 return module
2367}
2368
Paul Duffineb8051d2021-10-18 17:49:39 +01002369func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002370 bundle := newApexBundle()
2371 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002372 return bundle
2373}
2374
2375// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2376// certain compatibility checks such as apex_available are not done for apex_test.
2377func testApexBundleFactory() android.Module {
2378 bundle := newApexBundle()
2379 bundle.testApex = true
2380 return bundle
2381}
2382
2383// apex packages other modules into an APEX file which is a packaging format for system-level
2384// components like binaries, shared libraries, etc.
2385func BundleFactory() android.Module {
2386 return newApexBundle()
2387}
2388
2389type Defaults struct {
2390 android.ModuleBase
2391 android.DefaultsModuleBase
2392}
2393
2394// apex_defaults provides defaultable properties to other apex modules.
2395func defaultsFactory() android.Module {
2396 return DefaultsFactory()
2397}
2398
2399func DefaultsFactory(props ...interface{}) android.Module {
2400 module := &Defaults{}
2401
2402 module.AddProperties(props...)
2403 module.AddProperties(
2404 &apexBundleProperties{},
2405 &apexTargetBundleProperties{},
2406 &overridableProperties{},
2407 )
2408
2409 android.InitDefaultsModule(module)
2410 return module
2411}
2412
2413type OverrideApex struct {
2414 android.ModuleBase
2415 android.OverrideModuleBase
2416}
2417
2418func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2419 // All the overrides happen in the base module.
2420}
2421
2422// override_apex is used to create an apex module based on another apex module by overriding some of
2423// its properties.
2424func overrideApexFactory() android.Module {
2425 m := &OverrideApex{}
2426
2427 m.AddProperties(&overridableProperties{})
2428
2429 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2430 android.InitOverrideModule(m)
2431 return m
2432}
2433
2434///////////////////////////////////////////////////////////////////////////////////////////////////
2435// Vality check routines
2436//
2437// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2438// certain conditions are not met.
2439//
2440// TODO(jiyong): move these checks to a separate go file.
2441
satayevad991492021-12-03 18:58:32 +00002442var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2443
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002444// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2445// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002446func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002447 if a.testApex || a.vndkApex {
2448 return
2449 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002450 // apexBundle::minSdkVersion reports its own errors.
2451 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002452 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002453}
2454
satayevad991492021-12-03 18:58:32 +00002455func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2456 return android.SdkSpec{
2457 Kind: android.SdkNone,
2458 ApiLevel: a.minSdkVersion(ctx),
2459 Raw: String(a.properties.Min_sdk_version),
2460 }
2461}
2462
2463func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002464 ver := proptools.String(a.properties.Min_sdk_version)
2465 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002466 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002467 }
2468 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2469 if err != nil {
2470 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2471 return android.NoneApiLevel
2472 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002473 return apiLevel
2474}
2475
2476// Ensures that a lib providing stub isn't statically linked
2477func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2478 // Practically, we only care about regular APEXes on the device.
2479 if ctx.Host() || a.testApex || a.vndkApex {
2480 return
2481 }
2482
2483 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2484
2485 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2486 if ccm, ok := to.(*cc.Module); ok {
2487 apexName := ctx.ModuleName()
2488 fromName := ctx.OtherModuleName(from)
2489 toName := ctx.OtherModuleName(to)
2490
2491 // If `to` is not actually in the same APEX as `from` then it does not need
2492 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002493 //
2494 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002495 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2496 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2497 return false
2498 }
2499
2500 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2501 // exception to this rule. It can't make the static dependencies dynamic
2502 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002503 // Same rule should be applied to linkerconfig, because it should be executed
2504 // only with static linked libraries before linker is available with ld.config.txt
2505 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002506 return false
2507 }
2508
2509 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2510 if isStubLibraryFromOtherApex && !externalDep {
2511 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2512 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2513 }
2514
2515 }
2516 return true
2517 })
2518}
2519
satayevb98371c2021-06-15 16:49:50 +01002520// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002521func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2522 if a.Updatable() {
2523 if String(a.properties.Min_sdk_version) == "" {
2524 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2525 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002526 if a.UsePlatformApis() {
2527 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2528 }
Daniel Norman69109112021-12-02 12:52:42 -08002529 if a.SocSpecific() || a.DeviceSpecific() {
2530 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2531 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002532 if a.FutureUpdatable() {
2533 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2534 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002535 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002536 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002537 }
2538}
2539
satayevb98371c2021-06-15 16:49:50 +01002540// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2541func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2542 ctx.VisitDirectDeps(func(module android.Module) {
2543 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2544 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2545 if !info.ClasspathFragmentProtoGenerated {
2546 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2547 }
2548 }
2549 })
2550}
2551
2552// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002553func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002554 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2555 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002556 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2557 tag := ctx.OtherModuleDependencyTag(module)
2558 switch tag {
2559 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002560 if m, ok := module.(interface {
2561 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2562 }); ok {
2563 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002564 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2565 }
2566 }
2567 }
2568 })
2569}
2570
satayevb98371c2021-06-15 16:49:50 +01002571// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002572func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2573 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2574 if ctx.Host() || a.testApex || a.vndkApex {
2575 return
2576 }
2577
2578 // Because APEXes targeting other than system/system_ext partitions can't set
2579 // apex_available, we skip checks for these APEXes
2580 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2581 return
2582 }
2583
2584 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2585 // Requiring them and their transitive depencies with apex_available is not right
2586 // because they just add noise.
2587 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2588 return
2589 }
2590
2591 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2592 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2593 if externalDep {
2594 return false
2595 }
2596
2597 apexName := ctx.ModuleName()
2598 fromName := ctx.OtherModuleName(from)
2599 toName := ctx.OtherModuleName(to)
2600
2601 // If `to` is not actually in the same APEX as `from` then it does not need
2602 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002603 //
2604 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002605 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2606 // As soon as the dependency graph crosses the APEX boundary, don't go
2607 // further.
2608 return false
2609 }
2610
2611 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2612 return true
2613 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002614 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2615 "\n\nDependency path:%s\n\n"+
2616 "Consider adding %q to 'apex_available' property of %q",
2617 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002618 // Visit this module's dependencies to check and report any issues with their availability.
2619 return true
2620 })
2621}
2622
Jiyong Park192600a2021-08-03 07:52:17 +00002623// checkStaticExecutable ensures that executables in an APEX are not static.
2624func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002625 // No need to run this for host APEXes
2626 if ctx.Host() {
2627 return
2628 }
2629
Jiyong Park192600a2021-08-03 07:52:17 +00002630 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2631 if ctx.OtherModuleDependencyTag(module) != executableTag {
2632 return
2633 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002634
2635 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002636 apex := a.ApexVariationName()
2637 exec := ctx.OtherModuleName(module)
2638 if isStaticExecutableAllowed(apex, exec) {
2639 return
2640 }
2641 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2642 }
2643 })
2644}
2645
2646// A small list of exceptions where static executables are allowed in APEXes.
2647func isStaticExecutableAllowed(apex string, exec string) bool {
2648 m := map[string][]string{
2649 "com.android.runtime": []string{
2650 "linker",
2651 "linkerconfig",
2652 },
2653 }
2654 execNames, ok := m[apex]
2655 return ok && android.InList(exec, execNames)
2656}
2657
braleeb0c1f0c2021-06-07 22:49:13 +08002658// Collect information for opening IDE project files in java/jdeps.go.
2659func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Remi NGUYEN VANbe901722022-03-02 21:00:33 +09002660 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
2661 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
2662 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002663 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2664}
2665
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002666var (
2667 apexAvailBaseline = makeApexAvailableBaseline()
2668 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2669)
2670
Colin Cross440e0d02020-06-11 11:32:11 -07002671func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002672 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002673 moduleName = normalizeModuleName(moduleName)
2674
Colin Cross440e0d02020-06-11 11:32:11 -07002675 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002676 return true
2677 }
2678
2679 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002680 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002681 return true
2682 }
2683
2684 return false
2685}
2686
2687func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002688 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2689 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002690 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002691 if strings.HasPrefix(moduleName, "libclang_rt.") {
2692 // This module has many arch variants that depend on the product being built.
2693 // We don't want to list them all
2694 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002695 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002696 if strings.HasPrefix(moduleName, "androidx.") {
2697 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2698 moduleName = "androidx"
2699 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002700 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002701}
2702
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002703// Transform the map of apex -> modules to module -> apexes.
2704func invertApexBaseline(m map[string][]string) map[string][]string {
2705 r := make(map[string][]string)
2706 for apex, modules := range m {
2707 for _, module := range modules {
2708 r[module] = append(r[module], apex)
2709 }
2710 }
2711 return r
2712}
2713
2714// Retrieve the baseline of apexes to which the supplied module belongs.
2715func BaselineApexAvailable(moduleName string) []string {
2716 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2717}
2718
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002719// This is a map from apex to modules, which overrides the apex_available setting for that
2720// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002721// TODO(b/147364041): remove this
2722func makeApexAvailableBaseline() map[string][]string {
2723 // The "Module separator"s below are employed to minimize merge conflicts.
2724 m := make(map[string][]string)
2725 //
2726 // Module separator
2727 //
2728 m["com.android.appsearch"] = []string{
2729 "icing-java-proto-lite",
2730 "libprotobuf-java-lite",
2731 }
2732 //
2733 // Module separator
2734 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002735 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002736 "android.hardware.audio.common@5.0",
2737 "android.hardware.bluetooth.a2dp@1.0",
2738 "android.hardware.bluetooth.audio@2.0",
2739 "android.hardware.bluetooth@1.0",
2740 "android.hardware.bluetooth@1.1",
2741 "android.hardware.graphics.bufferqueue@1.0",
2742 "android.hardware.graphics.bufferqueue@2.0",
2743 "android.hardware.graphics.common@1.0",
2744 "android.hardware.graphics.common@1.1",
2745 "android.hardware.graphics.common@1.2",
2746 "android.hardware.media@1.0",
2747 "android.hidl.safe_union@1.0",
2748 "android.hidl.token@1.0",
2749 "android.hidl.token@1.0-utils",
2750 "avrcp-target-service",
2751 "avrcp_headers",
2752 "bluetooth-protos-lite",
2753 "bluetooth.mapsapi",
2754 "com.android.vcard",
2755 "dnsresolver_aidl_interface-V2-java",
2756 "ipmemorystore-aidl-interfaces-V5-java",
2757 "ipmemorystore-aidl-interfaces-java",
2758 "internal_include_headers",
2759 "lib-bt-packets",
2760 "lib-bt-packets-avrcp",
2761 "lib-bt-packets-base",
2762 "libFraunhoferAAC",
2763 "libaudio-a2dp-hw-utils",
2764 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002765 "libbluetooth",
2766 "libbluetooth-types",
2767 "libbluetooth-types-header",
2768 "libbluetooth_gd",
2769 "libbluetooth_headers",
2770 "libbluetooth_jni",
2771 "libbt-audio-hal-interface",
2772 "libbt-bta",
2773 "libbt-common",
2774 "libbt-hci",
2775 "libbt-platform-protos-lite",
2776 "libbt-protos-lite",
2777 "libbt-sbc-decoder",
2778 "libbt-sbc-encoder",
2779 "libbt-stack",
2780 "libbt-utils",
2781 "libbtcore",
2782 "libbtdevice",
2783 "libbte",
2784 "libbtif",
2785 "libchrome",
2786 "libevent",
2787 "libfmq",
2788 "libg722codec",
2789 "libgui_headers",
2790 "libmedia_headers",
2791 "libmodpb64",
2792 "libosi",
2793 "libstagefright_foundation_headers",
2794 "libstagefright_headers",
2795 "libstatslog",
2796 "libstatssocket",
2797 "libtinyxml2",
2798 "libudrv-uipc",
2799 "libz",
2800 "media_plugin_headers",
2801 "net-utils-services-common",
2802 "netd_aidl_interface-unstable-java",
2803 "netd_event_listener_interface-java",
2804 "netlink-client",
2805 "networkstack-client",
2806 "sap-api-java-static",
2807 "services.net",
2808 }
2809 //
2810 // Module separator
2811 //
2812 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2813 //
2814 // Module separator
2815 //
2816 m["com.android.extservices"] = []string{
2817 "error_prone_annotations",
2818 "ExtServices-core",
2819 "ExtServices",
2820 "libtextclassifier-java",
2821 "libz_current",
2822 "textclassifier-statsd",
2823 "TextClassifierNotificationLibNoManifest",
2824 "TextClassifierServiceLibNoManifest",
2825 }
2826 //
2827 // Module separator
2828 //
2829 m["com.android.neuralnetworks"] = []string{
2830 "android.hardware.neuralnetworks@1.0",
2831 "android.hardware.neuralnetworks@1.1",
2832 "android.hardware.neuralnetworks@1.2",
2833 "android.hardware.neuralnetworks@1.3",
2834 "android.hidl.allocator@1.0",
2835 "android.hidl.memory.token@1.0",
2836 "android.hidl.memory@1.0",
2837 "android.hidl.safe_union@1.0",
2838 "libarect",
2839 "libbuildversion",
2840 "libmath",
2841 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002842 }
2843 //
2844 // Module separator
2845 //
2846 m["com.android.media"] = []string{
2847 "android.frameworks.bufferhub@1.0",
2848 "android.hardware.cas.native@1.0",
2849 "android.hardware.cas@1.0",
2850 "android.hardware.configstore-utils",
2851 "android.hardware.configstore@1.0",
2852 "android.hardware.configstore@1.1",
2853 "android.hardware.graphics.allocator@2.0",
2854 "android.hardware.graphics.allocator@3.0",
2855 "android.hardware.graphics.bufferqueue@1.0",
2856 "android.hardware.graphics.bufferqueue@2.0",
2857 "android.hardware.graphics.common@1.0",
2858 "android.hardware.graphics.common@1.1",
2859 "android.hardware.graphics.common@1.2",
2860 "android.hardware.graphics.mapper@2.0",
2861 "android.hardware.graphics.mapper@2.1",
2862 "android.hardware.graphics.mapper@3.0",
2863 "android.hardware.media.omx@1.0",
2864 "android.hardware.media@1.0",
2865 "android.hidl.allocator@1.0",
2866 "android.hidl.memory.token@1.0",
2867 "android.hidl.memory@1.0",
2868 "android.hidl.token@1.0",
2869 "android.hidl.token@1.0-utils",
2870 "bionic_libc_platform_headers",
2871 "exoplayer2-extractor",
2872 "exoplayer2-extractor-annotation-stubs",
2873 "gl_headers",
2874 "jsr305",
2875 "libEGL",
2876 "libEGL_blobCache",
2877 "libEGL_getProcAddress",
2878 "libFLAC",
2879 "libFLAC-config",
2880 "libFLAC-headers",
2881 "libGLESv2",
2882 "libaacextractor",
2883 "libamrextractor",
2884 "libarect",
2885 "libaudio_system_headers",
2886 "libaudioclient",
2887 "libaudioclient_headers",
2888 "libaudiofoundation",
2889 "libaudiofoundation_headers",
2890 "libaudiomanager",
2891 "libaudiopolicy",
2892 "libaudioutils",
2893 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002894 "libbluetooth-types-header",
2895 "libbufferhub",
2896 "libbufferhub_headers",
2897 "libbufferhubqueue",
2898 "libc_malloc_debug_backtrace",
2899 "libcamera_client",
2900 "libcamera_metadata",
2901 "libdvr_headers",
2902 "libexpat",
2903 "libfifo",
2904 "libflacextractor",
2905 "libgrallocusage",
2906 "libgraphicsenv",
2907 "libgui",
2908 "libgui_headers",
2909 "libhardware_headers",
2910 "libinput",
2911 "liblzma",
2912 "libmath",
2913 "libmedia",
2914 "libmedia_codeclist",
2915 "libmedia_headers",
2916 "libmedia_helper",
2917 "libmedia_helper_headers",
2918 "libmedia_midiiowrapper",
2919 "libmedia_omx",
2920 "libmediautils",
2921 "libmidiextractor",
2922 "libmkvextractor",
2923 "libmp3extractor",
2924 "libmp4extractor",
2925 "libmpeg2extractor",
2926 "libnativebase_headers",
2927 "libnativewindow_headers",
2928 "libnblog",
2929 "liboggextractor",
2930 "libpackagelistparser",
2931 "libpdx",
2932 "libpdx_default_transport",
2933 "libpdx_headers",
2934 "libpdx_uds",
2935 "libprocinfo",
2936 "libspeexresampler",
2937 "libspeexresampler",
2938 "libstagefright_esds",
2939 "libstagefright_flacdec",
2940 "libstagefright_flacdec",
2941 "libstagefright_foundation",
2942 "libstagefright_foundation_headers",
2943 "libstagefright_foundation_without_imemory",
2944 "libstagefright_headers",
2945 "libstagefright_id3",
2946 "libstagefright_metadatautils",
2947 "libstagefright_mpeg2extractor",
2948 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002949 "libui",
2950 "libui_headers",
2951 "libunwindstack",
2952 "libvibrator",
2953 "libvorbisidec",
2954 "libwavextractor",
2955 "libwebm",
2956 "media_ndk_headers",
2957 "media_plugin_headers",
2958 "updatable-media",
2959 }
2960 //
2961 // Module separator
2962 //
2963 m["com.android.media.swcodec"] = []string{
2964 "android.frameworks.bufferhub@1.0",
2965 "android.hardware.common-ndk_platform",
2966 "android.hardware.configstore-utils",
2967 "android.hardware.configstore@1.0",
2968 "android.hardware.configstore@1.1",
2969 "android.hardware.graphics.allocator@2.0",
2970 "android.hardware.graphics.allocator@3.0",
2971 "android.hardware.graphics.allocator@4.0",
2972 "android.hardware.graphics.bufferqueue@1.0",
2973 "android.hardware.graphics.bufferqueue@2.0",
2974 "android.hardware.graphics.common-ndk_platform",
2975 "android.hardware.graphics.common@1.0",
2976 "android.hardware.graphics.common@1.1",
2977 "android.hardware.graphics.common@1.2",
2978 "android.hardware.graphics.mapper@2.0",
2979 "android.hardware.graphics.mapper@2.1",
2980 "android.hardware.graphics.mapper@3.0",
2981 "android.hardware.graphics.mapper@4.0",
2982 "android.hardware.media.bufferpool@2.0",
2983 "android.hardware.media.c2@1.0",
2984 "android.hardware.media.c2@1.1",
2985 "android.hardware.media.omx@1.0",
2986 "android.hardware.media@1.0",
2987 "android.hardware.media@1.0",
2988 "android.hidl.memory.token@1.0",
2989 "android.hidl.memory@1.0",
2990 "android.hidl.safe_union@1.0",
2991 "android.hidl.token@1.0",
2992 "android.hidl.token@1.0-utils",
2993 "libEGL",
2994 "libFLAC",
2995 "libFLAC-config",
2996 "libFLAC-headers",
2997 "libFraunhoferAAC",
2998 "libLibGuiProperties",
2999 "libarect",
3000 "libaudio_system_headers",
3001 "libaudioutils",
3002 "libaudioutils",
3003 "libaudioutils_fixedfft",
3004 "libavcdec",
3005 "libavcenc",
3006 "libavservices_minijail",
3007 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003008 "libbinderthreadstateutils",
3009 "libbluetooth-types-header",
3010 "libbufferhub_headers",
3011 "libcodec2",
3012 "libcodec2_headers",
3013 "libcodec2_hidl@1.0",
3014 "libcodec2_hidl@1.1",
3015 "libcodec2_internal",
3016 "libcodec2_soft_aacdec",
3017 "libcodec2_soft_aacenc",
3018 "libcodec2_soft_amrnbdec",
3019 "libcodec2_soft_amrnbenc",
3020 "libcodec2_soft_amrwbdec",
3021 "libcodec2_soft_amrwbenc",
3022 "libcodec2_soft_av1dec_gav1",
3023 "libcodec2_soft_avcdec",
3024 "libcodec2_soft_avcenc",
3025 "libcodec2_soft_common",
3026 "libcodec2_soft_flacdec",
3027 "libcodec2_soft_flacenc",
3028 "libcodec2_soft_g711alawdec",
3029 "libcodec2_soft_g711mlawdec",
3030 "libcodec2_soft_gsmdec",
3031 "libcodec2_soft_h263dec",
3032 "libcodec2_soft_h263enc",
3033 "libcodec2_soft_hevcdec",
3034 "libcodec2_soft_hevcenc",
3035 "libcodec2_soft_mp3dec",
3036 "libcodec2_soft_mpeg2dec",
3037 "libcodec2_soft_mpeg4dec",
3038 "libcodec2_soft_mpeg4enc",
3039 "libcodec2_soft_opusdec",
3040 "libcodec2_soft_opusenc",
3041 "libcodec2_soft_rawdec",
3042 "libcodec2_soft_vorbisdec",
3043 "libcodec2_soft_vp8dec",
3044 "libcodec2_soft_vp8enc",
3045 "libcodec2_soft_vp9dec",
3046 "libcodec2_soft_vp9enc",
3047 "libcodec2_vndk",
3048 "libdvr_headers",
3049 "libfmq",
3050 "libfmq",
3051 "libgav1",
3052 "libgralloctypes",
3053 "libgrallocusage",
3054 "libgraphicsenv",
3055 "libgsm",
3056 "libgui_bufferqueue_static",
3057 "libgui_headers",
3058 "libhardware",
3059 "libhardware_headers",
3060 "libhevcdec",
3061 "libhevcenc",
3062 "libion",
3063 "libjpeg",
3064 "liblzma",
3065 "libmath",
3066 "libmedia_codecserviceregistrant",
3067 "libmedia_headers",
3068 "libmpeg2dec",
3069 "libnativebase_headers",
3070 "libnativewindow_headers",
3071 "libpdx_headers",
3072 "libscudo_wrapper",
3073 "libsfplugin_ccodec_utils",
3074 "libspeexresampler",
3075 "libstagefright_amrnb_common",
3076 "libstagefright_amrnbdec",
3077 "libstagefright_amrnbenc",
3078 "libstagefright_amrwbdec",
3079 "libstagefright_amrwbenc",
3080 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003081 "libstagefright_enc_common",
3082 "libstagefright_flacdec",
3083 "libstagefright_foundation",
3084 "libstagefright_foundation_headers",
3085 "libstagefright_headers",
3086 "libstagefright_m4vh263dec",
3087 "libstagefright_m4vh263enc",
3088 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003089 "libui",
3090 "libui_headers",
3091 "libunwindstack",
3092 "libvorbisidec",
3093 "libvpx",
3094 "libyuv",
3095 "libyuv_static",
3096 "media_ndk_headers",
3097 "media_plugin_headers",
3098 "mediaswcodec",
3099 }
3100 //
3101 // Module separator
3102 //
3103 m["com.android.mediaprovider"] = []string{
3104 "MediaProvider",
3105 "MediaProviderGoogle",
3106 "fmtlib_ndk",
3107 "libbase_ndk",
3108 "libfuse",
3109 "libfuse_jni",
3110 }
3111 //
3112 // Module separator
3113 //
3114 m["com.android.permission"] = []string{
3115 "car-ui-lib",
3116 "iconloader",
3117 "kotlin-annotations",
3118 "kotlin-stdlib",
3119 "kotlin-stdlib-jdk7",
3120 "kotlin-stdlib-jdk8",
3121 "kotlinx-coroutines-android",
3122 "kotlinx-coroutines-android-nodeps",
3123 "kotlinx-coroutines-core",
3124 "kotlinx-coroutines-core-nodeps",
3125 "permissioncontroller-statsd",
3126 "GooglePermissionController",
3127 "PermissionController",
3128 "SettingsLibActionBarShadow",
3129 "SettingsLibAppPreference",
3130 "SettingsLibBarChartPreference",
3131 "SettingsLibLayoutPreference",
3132 "SettingsLibProgressBar",
3133 "SettingsLibSearchWidget",
3134 "SettingsLibSettingsTheme",
3135 "SettingsLibRestrictedLockUtils",
3136 "SettingsLibHelpUtils",
3137 }
3138 //
3139 // Module separator
3140 //
3141 m["com.android.runtime"] = []string{
3142 "bionic_libc_platform_headers",
3143 "libarm-optimized-routines-math",
3144 "libc_aeabi",
3145 "libc_bionic",
3146 "libc_bionic_ndk",
3147 "libc_bootstrap",
3148 "libc_common",
3149 "libc_common_shared",
3150 "libc_common_static",
3151 "libc_dns",
3152 "libc_dynamic_dispatch",
3153 "libc_fortify",
3154 "libc_freebsd",
3155 "libc_freebsd_large_stack",
3156 "libc_gdtoa",
3157 "libc_init_dynamic",
3158 "libc_init_static",
3159 "libc_jemalloc_wrapper",
3160 "libc_netbsd",
3161 "libc_nomalloc",
3162 "libc_nopthread",
3163 "libc_openbsd",
3164 "libc_openbsd_large_stack",
3165 "libc_openbsd_ndk",
3166 "libc_pthread",
3167 "libc_static_dispatch",
3168 "libc_syscalls",
3169 "libc_tzcode",
3170 "libc_unwind_static",
3171 "libdebuggerd",
3172 "libdebuggerd_common_headers",
3173 "libdebuggerd_handler_core",
3174 "libdebuggerd_handler_fallback",
3175 "libdl_static",
3176 "libjemalloc5",
3177 "liblinker_main",
3178 "liblinker_malloc",
3179 "liblz4",
3180 "liblzma",
3181 "libprocinfo",
3182 "libpropertyinfoparser",
3183 "libscudo",
3184 "libstdc++",
3185 "libsystemproperties",
3186 "libtombstoned_client_static",
3187 "libunwindstack",
3188 "libz",
3189 "libziparchive",
3190 }
3191 //
3192 // Module separator
3193 //
3194 m["com.android.tethering"] = []string{
3195 "android.hardware.tetheroffload.config-V1.0-java",
3196 "android.hardware.tetheroffload.control-V1.0-java",
3197 "android.hidl.base-V1.0-java",
3198 "libcgrouprc",
3199 "libcgrouprc_format",
3200 "libtetherutilsjni",
3201 "libvndksupport",
3202 "net-utils-framework-common",
3203 "netd_aidl_interface-V3-java",
3204 "netlink-client",
3205 "networkstack-aidl-interfaces-java",
3206 "tethering-aidl-interfaces-java",
3207 "TetheringApiCurrentLib",
3208 }
3209 //
3210 // Module separator
3211 //
3212 m["com.android.wifi"] = []string{
3213 "PlatformProperties",
3214 "android.hardware.wifi-V1.0-java",
3215 "android.hardware.wifi-V1.0-java-constants",
3216 "android.hardware.wifi-V1.1-java",
3217 "android.hardware.wifi-V1.2-java",
3218 "android.hardware.wifi-V1.3-java",
3219 "android.hardware.wifi-V1.4-java",
3220 "android.hardware.wifi.hostapd-V1.0-java",
3221 "android.hardware.wifi.hostapd-V1.1-java",
3222 "android.hardware.wifi.hostapd-V1.2-java",
3223 "android.hardware.wifi.supplicant-V1.0-java",
3224 "android.hardware.wifi.supplicant-V1.1-java",
3225 "android.hardware.wifi.supplicant-V1.2-java",
3226 "android.hardware.wifi.supplicant-V1.3-java",
3227 "android.hidl.base-V1.0-java",
3228 "android.hidl.manager-V1.0-java",
3229 "android.hidl.manager-V1.1-java",
3230 "android.hidl.manager-V1.2-java",
3231 "bouncycastle-unbundled",
3232 "dnsresolver_aidl_interface-V2-java",
3233 "error_prone_annotations",
3234 "framework-wifi-pre-jarjar",
3235 "framework-wifi-util-lib",
3236 "ipmemorystore-aidl-interfaces-V3-java",
3237 "ipmemorystore-aidl-interfaces-java",
3238 "ksoap2",
3239 "libnanohttpd",
3240 "libwifi-jni",
3241 "net-utils-services-common",
3242 "netd_aidl_interface-V2-java",
3243 "netd_aidl_interface-unstable-java",
3244 "netd_event_listener_interface-java",
3245 "netlink-client",
3246 "networkstack-client",
3247 "services.net",
3248 "wifi-lite-protos",
3249 "wifi-nano-protos",
3250 "wifi-service-pre-jarjar",
3251 "wifi-service-resources",
3252 }
3253 //
3254 // Module separator
3255 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003256 m["com.android.os.statsd"] = []string{
3257 "libstatssocket",
3258 }
3259 //
3260 // Module separator
3261 //
3262 m[android.AvailableToAnyApex] = []string{
3263 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3264 "androidx",
3265 "androidx-constraintlayout_constraintlayout",
3266 "androidx-constraintlayout_constraintlayout-nodeps",
3267 "androidx-constraintlayout_constraintlayout-solver",
3268 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3269 "com.google.android.material_material",
3270 "com.google.android.material_material-nodeps",
3271
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003272 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003273 "libprofile-clang-extras",
3274 "libprofile-clang-extras_ndk",
3275 "libprofile-extras",
3276 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003277 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003278 }
3279 return m
3280}
3281
3282func init() {
3283 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3284 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3285}
3286
3287func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3288 rules := make([]android.Rule, 0, len(modules_packages))
3289 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003290 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003291 BootclasspathJar().
3292 With("apex_available", module_name).
3293 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003294 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003295 Because("jars that are part of the " + module_name +
Andrei Onead967aee2022-01-19 15:36:40 +00003296 " module may only use these package prefixes: " + strings.Join(module_packages, ",") +
3297 " with min_sdk < T. Please consider the following alternatives:\n" +
3298 " 1. If the offending code is from a statically linked library, consider " +
3299 "removing that dependency and using an alternative already in the " +
3300 "bootclasspath, or perhaps a shared library." +
3301 " 2. Move the offending code into an allowed package.\n" +
3302 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3303 "health implications of bundling that code, particularly if the offending jar " +
3304 "is part of the bootclasspath.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003305 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003306 }
3307 return rules
3308}
3309
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003310// 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 +09003311// Adding code to the bootclasspath in new packages will cause issues on module update.
3312func qModulesPackages() map[string][]string {
3313 return map[string][]string{
3314 "com.android.conscrypt": []string{
3315 "android.net.ssl",
3316 "com.android.org.conscrypt",
3317 },
3318 "com.android.media": []string{
3319 "android.media",
3320 },
3321 }
3322}
3323
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003324// 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 +09003325// Adding code to the bootclasspath in new packages will cause issues on module update.
3326func rModulesPackages() map[string][]string {
3327 return map[string][]string{
3328 "com.android.mediaprovider": []string{
3329 "android.provider",
3330 },
3331 "com.android.permission": []string{
3332 "android.permission",
3333 "android.app.role",
3334 "com.android.permission",
3335 "com.android.role",
3336 },
3337 "com.android.sdkext": []string{
3338 "android.os.ext",
3339 },
3340 "com.android.os.statsd": []string{
3341 "android.app",
3342 "android.os",
3343 "android.util",
3344 "com.android.internal.statsd",
3345 "com.android.server.stats",
3346 },
3347 "com.android.wifi": []string{
3348 "com.android.server.wifi",
3349 "com.android.wifi.x",
3350 "android.hardware.wifi",
3351 "android.net.wifi",
3352 },
3353 "com.android.tethering": []string{
3354 "android.net",
3355 },
3356 }
3357}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003358
3359// For Bazel / bp2build
3360
3361type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003362 Manifest bazel.LabelAttribute
3363 Android_manifest bazel.LabelAttribute
3364 File_contexts bazel.LabelAttribute
3365 Key bazel.LabelAttribute
3366 Certificate bazel.LabelAttribute
3367 Min_sdk_version *string
3368 Updatable bazel.BoolAttribute
3369 Installable bazel.BoolAttribute
3370 Binaries bazel.LabelListAttribute
3371 Prebuilts bazel.LabelListAttribute
3372 Native_shared_libs_32 bazel.LabelListAttribute
3373 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003374 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003375}
3376
3377type convertedNativeSharedLibs struct {
3378 Native_shared_libs_32 bazel.LabelListAttribute
3379 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003380}
3381
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003382// ConvertWithBp2build performs bp2build conversion of an apex
3383func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3384 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003385 if ctx.ModuleType() != "apex" {
3386 return
3387 }
3388
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003389 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003390 if a.properties.Manifest != nil {
3391 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003392 }
3393
3394 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003395 if a.properties.AndroidManifest != nil {
3396 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003397 }
3398
3399 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003400 if a.properties.File_contexts != nil {
3401 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003402 }
3403
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003404 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003405 if a.properties.Min_sdk_version != nil {
3406 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003407 }
3408
3409 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003410 if a.overridableProperties.Key != nil {
3411 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003412 }
3413
3414 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003415 if a.overridableProperties.Certificate != nil {
3416 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003417 }
3418
Yu Liu4ae55d12022-01-05 17:17:23 -08003419 nativeSharedLibs := &convertedNativeSharedLibs{
3420 Native_shared_libs_32: bazel.LabelListAttribute{},
3421 Native_shared_libs_64: bazel.LabelListAttribute{},
3422 }
3423 compileMultilib := "both"
3424 if a.CompileMultilib() != nil {
3425 compileMultilib = *a.CompileMultilib()
3426 }
3427
3428 // properties.Native_shared_libs is treated as "both"
3429 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3430 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3431 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3432 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3433 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003434
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003435 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003436 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3437 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3438
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003439 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003440 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003441
3442 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003443 if a.properties.Updatable != nil {
3444 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003445 }
3446
3447 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003448 if a.properties.Installable != nil {
3449 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003450 }
3451
Wei Lif034cb42022-01-19 15:54:31 -08003452 var compressibleAttribute bazel.BoolAttribute
3453 if a.overridableProperties.Compressible != nil {
3454 compressibleAttribute.Value = a.overridableProperties.Compressible
3455 }
3456
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003457 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003458 Manifest: manifestLabelAttribute,
3459 Android_manifest: androidManifestLabelAttribute,
3460 File_contexts: fileContextsLabelAttribute,
3461 Min_sdk_version: minSdkVersion,
3462 Key: keyLabelAttribute,
3463 Certificate: certificateLabelAttribute,
3464 Updatable: updatableAttribute,
3465 Installable: installableAttribute,
3466 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3467 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3468 Binaries: binariesLabelListAttribute,
3469 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003470 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003471 }
3472
3473 props := bazel.BazelTargetModuleProperties{
3474 Rule_class: "apex",
3475 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3476 }
3477
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003478 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003479}
Yu Liu4ae55d12022-01-05 17:17:23 -08003480
3481// The following conversions are based on this table where the rows are the compile_multilib
3482// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3483// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3484// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3485// should not be compiled.
3486// multib/compile_multilib, 32, 64, both, first
3487// 32, 32/32, none/none, 32/32, none/32
3488// 64, none/none, 64/none, 64/none, 64/none
3489// both, 32/32, 64/none, 32&64/32, 64/32
3490// first, 32/32, 64/none, 64/32, 64/32
3491
3492func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3493 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3494 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3495 switch compileMultilb {
3496 case "both", "32":
3497 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3498 case "first":
3499 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3500 case "64":
3501 // Incompatible, ignore
3502 default:
3503 invalidCompileMultilib(ctx, compileMultilb)
3504 }
3505}
3506
3507func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3508 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3509 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3510 switch compileMultilb {
3511 case "both", "64", "first":
3512 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3513 case "32":
3514 // Incompatible, ignore
3515 default:
3516 invalidCompileMultilib(ctx, compileMultilb)
3517 }
3518}
3519
3520func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3521 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3522 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3523 switch compileMultilb {
3524 case "both":
3525 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3526 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3527 case "first":
3528 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3529 case "32":
3530 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3531 case "64":
3532 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3533 default:
3534 invalidCompileMultilib(ctx, compileMultilb)
3535 }
3536}
3537
3538func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3539 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3540 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3541 switch compileMultilb {
3542 case "both", "first":
3543 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3544 case "32":
3545 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3546 case "64":
3547 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3548 default:
3549 invalidCompileMultilib(ctx, compileMultilb)
3550 }
3551}
3552
3553func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3554 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3555 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3556}
3557
3558func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3559 list := bazel.LabelListAttribute{}
3560 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3561 nativeSharedLibs.Native_shared_libs_32.Append(list)
3562}
3563
3564func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3565 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3566 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3567}
3568
3569func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3570 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3571 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3572}
3573
3574func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3575 labelListAttr *bazel.LabelListAttribute) {
3576 list := bazel.LabelListAttribute{}
3577 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3578 labelListAttr.Append(list)
3579}
3580
3581func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3582 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3583}