blob: 56313714d10329b16ca4dae122f07d37fc1bcb13 [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
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900417 // Struct holding the merged notice file paths in different formats
418 mergedNotices android.NoticeOutputs
419
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.
490 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 {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900531 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 Das66773252022-01-15 00:23:18 +00001026 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1027 lintable.SetStrictUpdatabilityLinting(true)
1028 }
1029 // visit transitive deps
1030 return true
1031 })
1032 }
1033}
1034
Spandan Das08c911f2022-01-21 22:07:26 +00001035// TODO: b/215736885 Whittle the denylist
1036// Transitive deps of certain mainline modules baseline NewApi errors
1037// Skip these mainline modules for now
1038var (
1039 skipStrictUpdatabilityLintAllowlist = []string{
1040 "com.android.art",
1041 "com.android.art.debug",
1042 "com.android.conscrypt",
1043 "com.android.media",
1044 // test apexes
1045 "test_com.android.art",
1046 "test_com.android.conscrypt",
1047 "test_com.android.media",
1048 "test_jitzygote_com.android.art",
1049 }
1050)
1051
1052func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1053 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1054}
1055
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001056// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1057// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1058// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001059func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1060 if !mctx.Module().Enabled() {
1061 return
1062 }
1063 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001064 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1065 }
1066}
1067
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001068// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1069// the apex in order to retrieve its contents later.
1070// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001071func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1072 if !mctx.Module().Enabled() {
1073 return
1074 }
Colin Cross56a83212020-09-15 18:30:11 -07001075 if am, ok := mctx.Module().(android.ApexModule); ok {
1076 if testFor := am.TestFor(); len(testFor) > 0 {
1077 mctx.AddFarVariationDependencies([]blueprint.Variation{
1078 {Mutator: "os", Variation: am.Target().OsVariation()},
1079 {"arch", "common"},
1080 }, testForTag, testFor...)
1081 }
1082 }
1083}
1084
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001085// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001086func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1087 if !mctx.Module().Enabled() {
1088 return
1089 }
Colin Cross56a83212020-09-15 18:30:11 -07001090 if _, ok := mctx.Module().(android.ApexModule); ok {
1091 var contents []*android.ApexContents
1092 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1093 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1094 contents = append(contents, abInfo.Contents)
1095 }
1096 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1097 ApexContents: contents,
1098 })
Colin Crossaede88c2020-08-11 12:17:01 -07001099 }
1100}
1101
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001102// markPlatformAvailability marks whether or not a module can be available to platform. A module
1103// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1104// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1105// be) available to platform
1106// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001107func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1108 // Host and recovery are not considered as platform
1109 if mctx.Host() || mctx.Module().InstallInRecovery() {
1110 return
1111 }
1112
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001113 am, ok := mctx.Module().(android.ApexModule)
1114 if !ok {
1115 return
1116 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001117
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001118 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001119
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001120 // If any of the dep is not available to platform, this module is also considered as being
1121 // not available to platform even if it has "//apex_available:platform"
1122 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001123 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001124 // if the dependency crosses apex boundary, don't consider it
1125 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001126 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001127 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1128 availableToPlatform = false
1129 // TODO(b/154889534) trigger an error when 'am' has
1130 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001131 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001132 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001133
Paul Duffinb5769c12021-05-12 16:16:51 +01001134 // Exception 1: check to see if the module always requires it.
1135 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001136 availableToPlatform = true
1137 }
1138
1139 // Exception 2: bootstrap bionic libraries are also always available to platform
1140 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1141 availableToPlatform = true
1142 }
1143
1144 if !availableToPlatform {
1145 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001146 }
1147}
1148
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001149// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001150// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001151func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001152 if !mctx.Module().Enabled() {
1153 return
1154 }
Colin Cross56a83212020-09-15 18:30:11 -07001155
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001156 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001157 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001158 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001159 return
1160 }
1161
1162 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001163 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1164 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001165 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001166 if strings.HasPrefix(apexBundleName, "com.android.art") {
1167 // Create an alias from the platform variant. This is done to make
1168 // test_for dependencies work for modules that are split by the APEX
1169 // mutator, since test_for dependencies always go to the platform variant.
1170 // This doesn't happen for normal APEXes that are disjunct, so only do
1171 // this for the overlapping ART APEXes.
1172 // TODO(b/183882457): Remove this if the test_for functionality is
1173 // refactored to depend on the proper APEX variants instead of platform.
1174 mctx.CreateAliasVariation("", apexBundleName)
1175 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001176 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1177 apexBundleName := o.GetOverriddenModuleName()
1178 if apexBundleName == "" {
1179 mctx.ModuleErrorf("base property is not set")
1180 return
1181 }
1182 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001183 if strings.HasPrefix(apexBundleName, "com.android.art") {
1184 // TODO(b/183882457): See note for CreateAliasVariation above.
1185 mctx.CreateAliasVariation("", apexBundleName)
1186 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001187 }
1188}
Sundong Ahne9b55722019-09-06 17:37:42 +09001189
Paul Duffin6717d882021-06-15 19:09:41 +01001190// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1191// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001192func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001193 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001194 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001195 return !a.vndkApex
1196 }
1197
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001198 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001199}
1200
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001201// See android.UpdateDirectlyInAnyApex
1202// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001203func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1204 if !mctx.Module().Enabled() {
1205 return
1206 }
1207 if am, ok := mctx.Module().(android.ApexModule); ok {
1208 android.UpdateDirectlyInAnyApex(mctx, am)
1209 }
1210}
1211
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001212// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001213type apexPackaging int
1214
1215const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001216 // imageApex is a packaging method where contents are included in a filesystem image which
1217 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001218 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001219
1220 // zipApex is a packaging method where contents are directly included in the zip container.
1221 // This is used for host-side testing - because the contents are easily accessible by
1222 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001223 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001224
1225 // flattendApex is a packaging method where contents are not included in the APEX file, but
1226 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1227 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001228 flattenedApex
1229)
1230
1231const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001232 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001233 imageApexSuffix = ".apex"
1234 imageCapexSuffix = ".capex"
1235 zipApexSuffix = ".zipapex"
1236 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001237
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001238 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001239 imageApexType = "image"
1240 zipApexType = "zip"
1241 flattenedApexType = "flattened"
1242
Dan Willemsen47e1a752021-10-16 18:36:13 -07001243 ext4FsType = "ext4"
1244 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001245 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001246)
1247
1248// The suffix for the output "file", not the module
1249func (a apexPackaging) suffix() string {
1250 switch a {
1251 case imageApex:
1252 return imageApexSuffix
1253 case zipApex:
1254 return zipApexSuffix
1255 default:
1256 panic(fmt.Errorf("unknown APEX type %d", a))
1257 }
1258}
1259
1260func (a apexPackaging) name() string {
1261 switch a {
1262 case imageApex:
1263 return imageApexType
1264 case zipApex:
1265 return zipApexType
1266 default:
1267 panic(fmt.Errorf("unknown APEX type %d", a))
1268 }
1269}
1270
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001271// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1272// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001273func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001274 if !mctx.Module().Enabled() {
1275 return
1276 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001277 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001278 var variants []string
1279 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1280 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001281 // This is the normal case. Note that both image and flattend APEXes are
1282 // created. The image type is installed to the system partition, while the
1283 // flattened APEX is (optionally) installed to the system_ext partition.
1284 // This is mostly for GSI which has to support wide range of devices. If GSI
1285 // is installed on a newer (APEX-capable) device, the image APEX in the
1286 // system will be used. However, if the same GSI is installed on an old
1287 // device which can't support image APEX, the flattened APEX in the
1288 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001289 variants = append(variants, imageApexType, flattenedApexType)
1290 case "zip":
1291 variants = append(variants, zipApexType)
1292 case "both":
1293 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1294 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001295 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001296 return
1297 }
1298
1299 modules := mctx.CreateLocalVariations(variants...)
1300
1301 for i, v := range variants {
1302 switch v {
1303 case imageApexType:
1304 modules[i].(*apexBundle).properties.ApexType = imageApex
1305 case zipApexType:
1306 modules[i].(*apexBundle).properties.ApexType = zipApex
1307 case flattenedApexType:
1308 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001309 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001310 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001311 modules[i].(*apexBundle).MakeAsSystemExt()
1312 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001313 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001314 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001315 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001316 // payload_type is forcibly overridden to "image"
1317 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001318 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001319 }
1320}
1321
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001322var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001323
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001324// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001325func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1326 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001327 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001328 return true
1329}
1330
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001331var _ android.OutputFileProducer = (*apexBundle)(nil)
1332
1333// Implements android.OutputFileProducer
1334func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1335 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001336 case "", android.DefaultDistTag:
1337 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001338 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001339 case imageApexSuffix:
1340 // uncompressed one
1341 if a.outputApexFile != nil {
1342 return android.Paths{a.outputApexFile}, nil
1343 }
1344 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001345 default:
1346 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1347 }
1348}
1349
1350var _ cc.Coverage = (*apexBundle)(nil)
1351
1352// Implements cc.Coverage
1353func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1354 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1355}
1356
1357// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001358func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001359 a.properties.PreventInstall = true
1360}
1361
1362// Implements cc.Coverage
1363func (a *apexBundle) HideFromMake() {
1364 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001365 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1366 // TODO(ccross): untangle these
1367 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001368}
1369
1370// Implements cc.Coverage
1371func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1372 a.properties.IsCoverageVariant = coverage
1373}
1374
1375// Implements cc.Coverage
1376func (a *apexBundle) EnableCoverageIfNeeded() {}
1377
1378var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1379
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001380// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001381func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001382 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001383}
1384
Jiyong Parkf4020582021-11-29 12:37:10 +09001385func (a *apexBundle) FutureUpdatable() bool {
1386 return proptools.BoolDefault(a.properties.Future_updatable, false)
1387}
1388
Jiyong Park1bc84122021-06-22 20:23:05 +09001389func (a *apexBundle) UsePlatformApis() bool {
1390 return proptools.BoolDefault(a.properties.Platform_apis, false)
1391}
1392
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001393// getCertString returns the name of the cert that should be used to sign this APEX. This is
1394// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001395func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001396 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1398 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1399 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001400 if a.vndkApex {
1401 moduleName = vndkApexName
1402 }
1403 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001404 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001405 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001406 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001407 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001408}
1409
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001410// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001411func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001412 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001413}
1414
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001415// See the generate_hashtree property
1416func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001417 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001418}
1419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001420// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001421func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1422 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1423}
1424
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001425// See the test_only_force_compression property
1426func (a *apexBundle) testOnlyShouldForceCompression() bool {
1427 return proptools.Bool(a.properties.Test_only_force_compression)
1428}
1429
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001430// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1431// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1432// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001433
Jiyong Parkf97782b2019-02-13 20:28:58 +09001434func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1435 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1436 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1437 }
1438}
1439
Jiyong Park388ef3f2019-01-28 19:47:32 +09001440func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001441 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1442 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001443 }
1444
1445 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001446 globalSanitizerNames := []string{}
1447 if a.Host() {
1448 globalSanitizerNames = ctx.Config().SanitizeHost()
1449 } else {
1450 arches := ctx.Config().SanitizeDeviceArch()
1451 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1452 globalSanitizerNames = ctx.Config().SanitizeDevice()
1453 }
1454 }
1455 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001456}
1457
Jooyung Han8ce8db92020-05-15 19:05:05 +09001458func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001459 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1460 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001461 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001462 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001463 for _, target := range ctx.MultiTargets() {
1464 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001465 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Cross4c4c1be2022-02-10 11:41:18 -08001466 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001467 Tests: nil,
1468 Jni_libs: nil,
1469 Binaries: nil,
1470 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001471 break
1472 }
1473 }
1474 }
1475}
1476
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001477// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1478// returned apexFile saves information about the Soong module that will be used for creating the
1479// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001480func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001481 // Decide the APEX-local directory by the multilib of the library In the future, we may
1482 // query this to the module.
1483 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001484 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001485 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001486 case "lib32":
1487 dirInApex = "lib"
1488 case "lib64":
1489 dirInApex = "lib64"
1490 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001491 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001492 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001493 }
Jooyung Han35155c42020-02-06 17:33:20 +09001494 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001495 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001496 // Special case for Bionic libs and other libs installed with them. This is to
1497 // prevent those libs from being included in the search path
1498 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1499 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1500 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1501 // will be loaded into the default linker namespace (aka "platform" namespace). If
1502 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1503 // be loaded again into the runtime linker namespace, which will result in double
1504 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001505 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001506 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001507
Jiyong Parkf653b052019-11-18 15:39:01 +09001508 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001509 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1510 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001511}
1512
Jiyong Park1833cef2019-12-13 13:28:36 +09001513func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001514 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001515 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001516 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001517 }
Jooyung Han35155c42020-02-06 17:33:20 +09001518 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001519 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001520 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1521 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001522 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001523 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001524 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001525}
1526
Jiyong Park99644e92020-11-17 22:21:02 +09001527func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1528 dirInApex := "bin"
1529 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1530 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1531 }
1532 fileToCopy := rustm.OutputFile().Path()
1533 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1534 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1535 return af
1536}
1537
1538func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1539 // Decide the APEX-local directory by the multilib of the library
1540 // In the future, we may query this to the module.
1541 var dirInApex string
1542 switch rustm.Arch().ArchType.Multilib {
1543 case "lib32":
1544 dirInApex = "lib"
1545 case "lib64":
1546 dirInApex = "lib64"
1547 }
1548 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1549 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1550 }
1551 fileToCopy := rustm.OutputFile().Path()
1552 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1553 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1554}
1555
Jiyong Park1833cef2019-12-13 13:28:36 +09001556func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001557 dirInApex := "bin"
1558 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001559 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001560}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001561
Jiyong Park1833cef2019-12-13 13:28:36 +09001562func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001563 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001564 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001565 // NB: Since go binaries are static we don't need the module for anything here, which is
1566 // good since the go tool is a blueprint.Module not an android.Module like we would
1567 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001568 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001569}
1570
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001571func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001572 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001573 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1574 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1575 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001576 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001577 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001578 af.symlinks = sh.Symlinks()
1579 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001580}
1581
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001582func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001583 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001584 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001585 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001586}
1587
atrost6e126252020-01-27 17:01:16 +00001588func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1589 dirInApex := filepath.Join("etc", config.SubDir())
1590 fileToCopy := config.CompatConfig()
1591 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1592}
1593
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001594// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1595// way.
1596type javaModule interface {
1597 android.Module
1598 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001599 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001600 JacocoReportClassesFile() android.Path
1601 LintDepSets() java.LintDepSets
1602 Stem() string
1603}
1604
1605var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001606var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001607var _ javaModule = (*java.SdkLibrary)(nil)
1608var _ javaModule = (*java.DexImport)(nil)
1609var _ javaModule = (*java.SdkLibraryImport)(nil)
1610
Paul Duffin190fdef2021-04-26 10:33:59 +01001611// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001612func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001613 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001614}
1615
1616// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1617func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001618 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001619 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001620 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1621 af.lintDepSets = module.LintDepSets()
1622 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001623 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1624 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1625 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1626 }
1627 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001628 return af
1629}
1630
1631// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1632// the same way.
1633type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001634 android.Module
1635 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001636 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001637 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001638 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001639 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001640 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001641 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001642}
1643
1644var _ androidApp = (*java.AndroidApp)(nil)
1645var _ androidApp = (*java.AndroidAppImport)(nil)
1646
1647func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001648 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001649 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001650 appDir = "priv-app"
1651 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001652 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001653 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001654 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001655 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001656 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001657 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001658
1659 if app, ok := aapp.(interface {
1660 OverriddenManifestPackageName() string
1661 }); ok {
1662 af.overriddenPackageName = app.OverriddenManifestPackageName()
1663 }
Jiyong Park618922e2020-01-08 13:35:43 +09001664 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001665}
1666
Jiyong Park69aeba92020-04-24 21:16:36 +09001667func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1668 rroDir := "overlay"
1669 dirInApex := filepath.Join(rroDir, rro.Theme())
1670 fileToCopy := rro.OutputFile()
1671 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1672 af.certificate = rro.Certificate()
1673
1674 if a, ok := rro.(interface {
1675 OverriddenManifestPackageName() string
1676 }); ok {
1677 af.overriddenPackageName = a.OverriddenManifestPackageName()
1678 }
1679 return af
1680}
1681
Ken Chenfad7f9d2021-11-10 22:02:57 +08001682func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1683 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001684 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1685}
1686
Jiyong Park12a719c2021-01-07 15:31:24 +09001687func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1688 dirInApex := filepath.Join("etc", "fs")
1689 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1690}
1691
Paul Duffin064b70c2020-11-02 17:32:38 +00001692// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001693// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1694// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1695// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001696func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001697 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001698 am, ok := child.(android.ApexModule)
1699 if !ok || !am.CanHaveApexVariants() {
1700 return false
1701 }
1702
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001703 // Filter-out unwanted depedendencies
1704 depTag := ctx.OtherModuleDependencyTag(child)
1705 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1706 return false
1707 }
1708 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001709 return false
1710 }
1711
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001712 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001713 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001714
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001715 // Visit actually
1716 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001717 })
1718}
1719
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001720// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1721type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001722
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001723const (
1724 ext4 fsType = iota
1725 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001726 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001727)
Artur Satayev849f8442020-04-28 14:57:42 +01001728
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001729func (f fsType) string() string {
1730 switch f {
1731 case ext4:
1732 return ext4FsType
1733 case f2fs:
1734 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001735 case erofs:
1736 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001737 default:
1738 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001739 }
1740}
1741
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001742// Creates build rules for an APEX. It consists of the following major steps:
1743//
1744// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1745// 2) traverse the dependency tree to collect apexFile structs from them.
1746// 3) some fields in apexBundle struct are configured
1747// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001748func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001749 ////////////////////////////////////////////////////////////////////////////////////////////
1750 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001751 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001752 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001753 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001754 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001755 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001756 if len(a.properties.Tests) > 0 && !a.testApex {
1757 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1758 return
1759 }
Jiyong Park678c8812020-02-07 17:25:49 +09001760
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001761 ////////////////////////////////////////////////////////////////////////////////////////////
1762 // 2) traverse the dependency tree to collect apexFile structs from them.
1763
1764 // all the files that will be included in this APEX
1765 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001766
Jooyung Hane1633032019-08-01 17:41:43 +09001767 // native lib dependencies
1768 var provideNativeLibs []string
1769 var requireNativeLibs []string
1770
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001771 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1772
braleeb0c1f0c2021-06-07 22:49:13 +08001773 // Collect the module directory for IDE info in java/jdeps.go.
1774 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1775
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001776 // TODO(jiyong): do this using WalkPayloadDeps
1777 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001778 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001779 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001780 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1781 return false
1782 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001783 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1784 return false
1785 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001786 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001787 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001788 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001789 case sharedLibTag, jniLibTag:
1790 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001791 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001792 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1793 fi.isJniLib = isJniLib
1794 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001795 // Collect the list of stub-providing libs except:
1796 // - VNDK libs are only for vendors
1797 // - bootstrap bionic libs are treated as provided by system
1798 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001799 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001800 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001801 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001802 } else if r, ok := child.(*rust.Module); ok {
1803 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001804 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001805 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001806 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001807 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001808 propertyName := "native_shared_libs"
1809 if isJniLib {
1810 propertyName = "jni_libs"
1811 }
1812 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001813 }
1814 case executableTag:
1815 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001816 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001817 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001818 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001819 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001820 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001821 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001822 } else if rust, ok := child.(*rust.Module); ok {
1823 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1824 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001825 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001826 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1827 }
1828 case shBinaryTag:
1829 if sh, ok := child.(*sh.ShBinary); ok {
1830 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1831 } else {
1832 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001833 }
Paul Duffin94f19632021-04-20 12:40:07 +01001834 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001835 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001836 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1837 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001838 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001839 return false
1840 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001841
Paul Duffincc33ec82021-04-25 23:14:55 +01001842 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1843 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001844 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1845 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1846 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001847 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001848 }
satayev333a1732021-05-17 21:35:26 +01001849 case sscpfTag:
1850 {
1851 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1852 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1853 return false
1854 }
satayevb98371c2021-06-15 16:49:50 +01001855 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1856 filesInfo = append(filesInfo, *af)
1857 }
satayev333a1732021-05-17 21:35:26 +01001858 return true
1859 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001860 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001861 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001862 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001863 af := apexFileForJavaModule(ctx, child.(javaModule))
1864 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001865 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1866 return false
1867 }
1868 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001869 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001870 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001871 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001872 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001873 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001874 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001875 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001876 return true // track transitive dependencies
1877 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001878 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001879 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001880 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001881 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1882 appDir := "app"
1883 if ap.Privileged() {
1884 appDir = "priv-app"
1885 }
Yo Chiange8128052020-07-23 20:09:18 +08001886 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001887 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1888 af.certificate = java.PresignedCertificate
1889 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001890 } else {
1891 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1892 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001893 case rroTag:
1894 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1895 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1896 } else {
1897 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1898 }
markchien2f59ec92020-09-02 16:23:38 +08001899 case bpfTag:
1900 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1901 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001902 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001903 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001904 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001905 }
1906 } else {
1907 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1908 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001909 case fsTag:
1910 if fs, ok := child.(filesystem.Filesystem); ok {
1911 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1912 } else {
1913 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1914 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001915 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001916 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001917 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001918 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001919 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001920 }
Paul Duffin0b817782021-03-17 15:02:19 +00001921 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001922 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1923 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1924 } else {
1925 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1926 }
Roland Levillain630846d2019-06-26 12:48:34 +01001927 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001928 if ccTest, ok := child.(*cc.Module); ok {
1929 if ccTest.IsTestPerSrcAllTestsVariation() {
1930 // Multiple-output test module (where `test_per_src: true`).
1931 //
1932 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1933 // We do not add this variation to `filesInfo`, as it has no output;
1934 // however, we do add the other variations of this module as indirect
1935 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001936 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001937 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001938 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 af.class = nativeTest
1940 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001941 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001942 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001943 } else {
1944 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1945 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001946 case keyTag:
1947 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001948 a.privateKeyFile = key.privateKeyFile
1949 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001950 } else {
1951 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001952 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001953 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001954 case certificateTag:
1955 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001956 a.containerCertificateFile = dep.Certificate.Pem
1957 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001958 } else {
1959 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1960 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001961 case android.PrebuiltDepTag:
1962 // If the prebuilt is force disabled, remember to delete the prebuilt file
1963 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001964 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001965 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1966 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001967 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001968 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001969 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001970 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001971 // We cannot use a switch statement on `depTag` here as the checked
1972 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001973 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001974 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001975 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001976 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001977 return false
1978 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001979 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1980 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001981
1982 // Always track transitive dependencies for host.
1983 if a.Host() {
1984 filesInfo = append(filesInfo, af)
1985 return true
1986 }
1987
Colin Cross56a83212020-09-15 18:30:11 -07001988 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001989 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001990 // If the dependency is a stubs lib, don't include it in this APEX,
1991 // but make sure that the lib is installed on the device.
1992 // In case no APEX is having the lib, the lib is installed to the system
1993 // partition.
1994 //
1995 // Always include if we are a host-apex however since those won't have any
1996 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001997 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001998 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001999 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002000 if !android.InList(name, a.requiredDeps) {
2001 a.requiredDeps = append(a.requiredDeps, name)
2002 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002003 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002004 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002005 // Don't track further
2006 return false
2007 }
Jiyong Parke3867542020-12-03 17:28:25 +09002008
2009 // If the dep is not considered to be in the same
2010 // apex, don't add it to filesInfo so that it is not
2011 // included in this APEX.
2012 // TODO(jiyong): move this to at the top of the
2013 // else-if clause for the indirect dependencies.
2014 // Currently, that's impossible because we would
2015 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002016 // DepIsInSameAPex is false. We also shouldn't do
2017 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002018 //
2019 // TODO(jiyong): explain why the same module is passed in twice.
2020 // Switching the first am to parent breaks lots of tests.
2021 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002022 return false
2023 }
2024
Jiyong Parkf653b052019-11-18 15:39:01 +09002025 filesInfo = append(filesInfo, af)
2026 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002027 } else if rm, ok := child.(*rust.Module); ok {
2028 af := apexFileForRustLibrary(ctx, rm)
2029 af.transitiveDep = true
2030 filesInfo = append(filesInfo, af)
2031 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002032 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002033 } else if cc.IsTestPerSrcDepTag(depTag) {
2034 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002035 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002036 // Handle modules created as `test_per_src` variations of a single test module:
2037 // use the name of the generated test binary (`fileToCopy`) instead of the name
2038 // of the original test module (`depName`, shared by all `test_per_src`
2039 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002040 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002041 // these are not considered transitive dep
2042 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002043 filesInfo = append(filesInfo, af)
2044 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002045 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002046 } else if cc.IsHeaderDepTag(depTag) {
2047 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002048 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002049 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2050 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002051 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002052 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002053 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2054 }
Jiyong Park99644e92020-11-17 22:21:02 +09002055 } else if rust.IsDylibDepTag(depTag) {
2056 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2057 af := apexFileForRustLibrary(ctx, rustm)
2058 af.transitiveDep = true
2059 filesInfo = append(filesInfo, af)
2060 return true // track transitive dependencies
2061 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002062 } else if rust.IsRlibDepTag(depTag) {
2063 // Rlib is statically linked, but it might have shared lib
2064 // dependencies. Track them.
2065 return true
Paul Duffin65898052021-04-20 22:47:03 +01002066 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002067 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002068 switch child.(type) {
2069 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002070 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002071 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002072 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002073 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002074 return false
2075 }
2076 filesInfo = append(filesInfo, af)
2077 return true // track transitive dependencies
2078 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002079 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 +00002080 }
satayev333a1732021-05-17 21:35:26 +01002081 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2082 // Add the contents of the systemserverclasspath fragment to the apex.
2083 switch child.(type) {
2084 case *java.Library, *java.SdkLibrary:
2085 af := apexFileForJavaModule(ctx, child.(javaModule))
2086 filesInfo = append(filesInfo, af)
2087 return true // track transitive dependencies
2088 default:
2089 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2090 }
Colin Cross56a83212020-09-15 18:30:11 -07002091 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2092 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002093 } else if depTag == android.DarwinUniversalVariantTag {
2094 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002095 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002096 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002097 }
2098 }
2099 }
2100 return false
2101 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002102 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002103 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002104 return
2105 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002106
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002107 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002108 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002109 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002110 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002111 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002112 if e, ok := encountered[dest]; !ok {
2113 encountered[dest] = f
2114 } else {
2115 // If a module is directly included and also transitively depended on
2116 // consider it as directly included.
2117 e.transitiveDep = e.transitiveDep && f.transitiveDep
2118 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002119 }
2120 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002121 var result []apexFile
2122 for _, v := range encountered {
2123 result = append(result, v)
2124 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002125 return result
2126 }
2127 filesInfo = removeDup(filesInfo)
2128
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002129 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002130 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002131 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2132 // changes.
2133 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002134 })
2135
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002136 ////////////////////////////////////////////////////////////////////////////////////////////
2137 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002138 a.installDir = android.PathForModuleInstall(ctx, "apex")
2139 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002140
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002141 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002142 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002143 switch a.properties.ApexType {
2144 case imageApex:
2145 if buildFlattenedAsDefault {
2146 a.suffix = imageApexSuffix
2147 } else {
2148 a.suffix = ""
2149 a.primaryApexType = true
2150
2151 if ctx.Config().InstallExtraFlattenedApexes() {
2152 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2153 }
2154 }
2155 case zipApex:
2156 if proptools.String(a.properties.Payload_type) == "zip" {
2157 a.suffix = ""
2158 a.primaryApexType = true
2159 } else {
2160 a.suffix = zipApexSuffix
2161 }
2162 case flattenedApex:
2163 if buildFlattenedAsDefault {
2164 a.suffix = ""
2165 a.primaryApexType = true
2166 } else {
2167 a.suffix = flattenedSuffix
2168 }
2169 }
2170
Theotime Combes4ba38c12020-06-12 12:46:59 +00002171 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2172 case ext4FsType:
2173 a.payloadFsType = ext4
2174 case f2fsFsType:
2175 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002176 case erofsFsType:
2177 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002178 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002179 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 +00002180 }
2181
Jiyong Park7cd10e32020-01-14 09:22:18 +09002182 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2183 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2184 // the same library in the system partition, thus effectively sharing the same libraries
2185 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2186 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002187 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002188
Jooyung Han85d61762020-06-24 23:50:26 +09002189 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2190 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002191 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002192 a.linkToSystemLib = false
2193 }
2194
Jiyong Park4da07972021-01-05 21:01:11 +09002195 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002196 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002197
Jiyong Park9d677202020-02-19 16:29:35 +09002198 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002199 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002200 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002201 a.linkToSystemLib = false
2202 }
2203
Jiyong Park638d30e2020-02-26 18:27:19 +09002204 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2205 if ctx.Host() {
2206 a.linkToSystemLib = false
2207 }
2208
Colin Cross6340ea52021-11-04 12:01:18 -07002209 if a.properties.ApexType != zipApex {
2210 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2211 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002212
2213 ////////////////////////////////////////////////////////////////////////////////////////////
2214 // 4) generate the build rules to create the APEX. This is done in builder.go.
2215 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002216 if a.properties.ApexType == flattenedApex {
2217 a.buildFlattenedApex(ctx)
2218 } else {
2219 a.buildUnflattenedApex(ctx)
2220 }
Jiyong Park956305c2020-01-09 12:32:06 +09002221 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002222 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002223
2224 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2225 if a.installable() {
2226 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2227 // along with other ordinary files. (Note that this is done by apexer for
2228 // non-flattened APEXes)
2229 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2230
2231 // Place the public key as apex_pubkey. This is also done by apexer for
2232 // non-flattened APEXes case.
2233 // TODO(jiyong): Why do we need this CP rule?
2234 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2235 ctx.Build(pctx, android.BuildParams{
2236 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002237 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002238 Output: copiedPubkey,
2239 })
2240 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2241 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002242}
2243
Paul Duffincc33ec82021-04-25 23:14:55 +01002244// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2245// the bootclasspath_fragment contributes to the apex.
2246func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2247 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2248 var filesToAdd []apexFile
2249
2250 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002251 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2252 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2253 dirInApex := filepath.Join("javalib", arch.String())
2254 for _, f := range files {
2255 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2256 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2257 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2258 filesToAdd = append(filesToAdd, af)
2259 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002260 }
2261 }
2262
satayev3db35472021-05-06 23:59:58 +01002263 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002264 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2265 filesToAdd = append(filesToAdd, *af)
2266 }
satayev3db35472021-05-06 23:59:58 +01002267
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002268 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2269 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2270 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2271
2272 if pathOnHost != nil {
2273 // We need to copy the profile to a temporary path with the right filename because the apexer
2274 // will take the filename as is.
2275 ctx.Build(pctx, android.BuildParams{
2276 Rule: android.Cp,
2277 Input: pathOnHost,
2278 Output: tempPath,
2279 })
2280 } else {
2281 // At this point, the boot image profile cannot be generated. It is probably because the boot
2282 // image profile source file does not exist on the branch, or it is not available for the
2283 // current build target.
2284 // However, we cannot enforce the boot image profile to be generated because some build
2285 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2286 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2287 // only if the APEX is being built.
2288 ctx.Build(pctx, android.BuildParams{
2289 Rule: android.ErrorRule,
2290 Output: tempPath,
2291 Args: map[string]string{
2292 "error": "Boot image profile cannot be generated",
2293 },
2294 })
2295 }
2296
2297 androidMkModuleName := filepath.Base(pathInApex)
2298 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2299 filesToAdd = append(filesToAdd, af)
2300 }
2301
Paul Duffincc33ec82021-04-25 23:14:55 +01002302 return filesToAdd
2303}
2304
satayevb98371c2021-06-15 16:49:50 +01002305// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2306// the module contributes to the apex; or nil if the proto config was not generated.
2307func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2308 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2309 if !info.ClasspathFragmentProtoGenerated {
2310 return nil
2311 }
2312 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2313 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2314 return &af
satayev14e49132021-05-17 21:03:07 +01002315}
2316
Paul Duffincc33ec82021-04-25 23:14:55 +01002317// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2318// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002319func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2320 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2321
2322 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2323 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002324 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2325 if err != nil {
2326 ctx.ModuleErrorf("%s", err)
2327 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002328
2329 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2330 // bootclasspath_fragment.
2331 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2332 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002333}
2334
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002335///////////////////////////////////////////////////////////////////////////////////////////////////
2336// Factory functions
2337//
2338
2339func newApexBundle() *apexBundle {
2340 module := &apexBundle{}
2341
2342 module.AddProperties(&module.properties)
2343 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002344 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002345 module.AddProperties(&module.overridableProperties)
2346
2347 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2348 android.InitDefaultableModule(module)
2349 android.InitSdkAwareModule(module)
2350 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002351 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002352 return module
2353}
2354
Paul Duffineb8051d2021-10-18 17:49:39 +01002355func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002356 bundle := newApexBundle()
2357 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002358 return bundle
2359}
2360
2361// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2362// certain compatibility checks such as apex_available are not done for apex_test.
2363func testApexBundleFactory() android.Module {
2364 bundle := newApexBundle()
2365 bundle.testApex = true
2366 return bundle
2367}
2368
2369// apex packages other modules into an APEX file which is a packaging format for system-level
2370// components like binaries, shared libraries, etc.
2371func BundleFactory() android.Module {
2372 return newApexBundle()
2373}
2374
2375type Defaults struct {
2376 android.ModuleBase
2377 android.DefaultsModuleBase
2378}
2379
2380// apex_defaults provides defaultable properties to other apex modules.
2381func defaultsFactory() android.Module {
2382 return DefaultsFactory()
2383}
2384
2385func DefaultsFactory(props ...interface{}) android.Module {
2386 module := &Defaults{}
2387
2388 module.AddProperties(props...)
2389 module.AddProperties(
2390 &apexBundleProperties{},
2391 &apexTargetBundleProperties{},
2392 &overridableProperties{},
2393 )
2394
2395 android.InitDefaultsModule(module)
2396 return module
2397}
2398
2399type OverrideApex struct {
2400 android.ModuleBase
2401 android.OverrideModuleBase
2402}
2403
2404func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2405 // All the overrides happen in the base module.
2406}
2407
2408// override_apex is used to create an apex module based on another apex module by overriding some of
2409// its properties.
2410func overrideApexFactory() android.Module {
2411 m := &OverrideApex{}
2412
2413 m.AddProperties(&overridableProperties{})
2414
2415 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2416 android.InitOverrideModule(m)
2417 return m
2418}
2419
2420///////////////////////////////////////////////////////////////////////////////////////////////////
2421// Vality check routines
2422//
2423// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2424// certain conditions are not met.
2425//
2426// TODO(jiyong): move these checks to a separate go file.
2427
satayevad991492021-12-03 18:58:32 +00002428var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2429
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002430// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2431// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002432func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002433 if a.testApex || a.vndkApex {
2434 return
2435 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002436 // apexBundle::minSdkVersion reports its own errors.
2437 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002438 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002439}
2440
satayevad991492021-12-03 18:58:32 +00002441func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2442 return android.SdkSpec{
2443 Kind: android.SdkNone,
2444 ApiLevel: a.minSdkVersion(ctx),
2445 Raw: String(a.properties.Min_sdk_version),
2446 }
2447}
2448
2449func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002450 ver := proptools.String(a.properties.Min_sdk_version)
2451 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002452 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002453 }
2454 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2455 if err != nil {
2456 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2457 return android.NoneApiLevel
2458 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002459 return apiLevel
2460}
2461
2462// Ensures that a lib providing stub isn't statically linked
2463func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2464 // Practically, we only care about regular APEXes on the device.
2465 if ctx.Host() || a.testApex || a.vndkApex {
2466 return
2467 }
2468
2469 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2470
2471 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2472 if ccm, ok := to.(*cc.Module); ok {
2473 apexName := ctx.ModuleName()
2474 fromName := ctx.OtherModuleName(from)
2475 toName := ctx.OtherModuleName(to)
2476
2477 // If `to` is not actually in the same APEX as `from` then it does not need
2478 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002479 //
2480 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002481 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2482 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2483 return false
2484 }
2485
2486 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2487 // exception to this rule. It can't make the static dependencies dynamic
2488 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002489 // Same rule should be applied to linkerconfig, because it should be executed
2490 // only with static linked libraries before linker is available with ld.config.txt
2491 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002492 return false
2493 }
2494
2495 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2496 if isStubLibraryFromOtherApex && !externalDep {
2497 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2498 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2499 }
2500
2501 }
2502 return true
2503 })
2504}
2505
satayevb98371c2021-06-15 16:49:50 +01002506// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002507func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2508 if a.Updatable() {
2509 if String(a.properties.Min_sdk_version) == "" {
2510 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2511 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002512 if a.UsePlatformApis() {
2513 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2514 }
Daniel Norman69109112021-12-02 12:52:42 -08002515 if a.SocSpecific() || a.DeviceSpecific() {
2516 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2517 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002518 if a.FutureUpdatable() {
2519 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2520 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002521 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002522 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002523 }
2524}
2525
satayevb98371c2021-06-15 16:49:50 +01002526// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2527func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2528 ctx.VisitDirectDeps(func(module android.Module) {
2529 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2530 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2531 if !info.ClasspathFragmentProtoGenerated {
2532 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2533 }
2534 }
2535 })
2536}
2537
2538// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002539func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002540 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2541 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002542 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2543 tag := ctx.OtherModuleDependencyTag(module)
2544 switch tag {
2545 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002546 if m, ok := module.(interface {
2547 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2548 }); ok {
2549 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002550 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2551 }
2552 }
2553 }
2554 })
2555}
2556
satayevb98371c2021-06-15 16:49:50 +01002557// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002558func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2559 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2560 if ctx.Host() || a.testApex || a.vndkApex {
2561 return
2562 }
2563
2564 // Because APEXes targeting other than system/system_ext partitions can't set
2565 // apex_available, we skip checks for these APEXes
2566 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2567 return
2568 }
2569
2570 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2571 // Requiring them and their transitive depencies with apex_available is not right
2572 // because they just add noise.
2573 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2574 return
2575 }
2576
2577 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2578 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2579 if externalDep {
2580 return false
2581 }
2582
2583 apexName := ctx.ModuleName()
2584 fromName := ctx.OtherModuleName(from)
2585 toName := ctx.OtherModuleName(to)
2586
2587 // If `to` is not actually in the same APEX as `from` then it does not need
2588 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002589 //
2590 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002591 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2592 // As soon as the dependency graph crosses the APEX boundary, don't go
2593 // further.
2594 return false
2595 }
2596
2597 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2598 return true
2599 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002600 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2601 "\n\nDependency path:%s\n\n"+
2602 "Consider adding %q to 'apex_available' property of %q",
2603 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002604 // Visit this module's dependencies to check and report any issues with their availability.
2605 return true
2606 })
2607}
2608
Jiyong Park192600a2021-08-03 07:52:17 +00002609// checkStaticExecutable ensures that executables in an APEX are not static.
2610func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002611 // No need to run this for host APEXes
2612 if ctx.Host() {
2613 return
2614 }
2615
Jiyong Park192600a2021-08-03 07:52:17 +00002616 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2617 if ctx.OtherModuleDependencyTag(module) != executableTag {
2618 return
2619 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002620
2621 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002622 apex := a.ApexVariationName()
2623 exec := ctx.OtherModuleName(module)
2624 if isStaticExecutableAllowed(apex, exec) {
2625 return
2626 }
2627 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2628 }
2629 })
2630}
2631
2632// A small list of exceptions where static executables are allowed in APEXes.
2633func isStaticExecutableAllowed(apex string, exec string) bool {
2634 m := map[string][]string{
2635 "com.android.runtime": []string{
2636 "linker",
2637 "linkerconfig",
2638 },
2639 }
2640 execNames, ok := m[apex]
2641 return ok && android.InList(exec, execNames)
2642}
2643
braleeb0c1f0c2021-06-07 22:49:13 +08002644// Collect information for opening IDE project files in java/jdeps.go.
2645func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Remi NGUYEN VANbe901722022-03-02 21:00:33 +09002646 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
2647 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
2648 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002649 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2650}
2651
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002652var (
2653 apexAvailBaseline = makeApexAvailableBaseline()
2654 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2655)
2656
Colin Cross440e0d02020-06-11 11:32:11 -07002657func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002658 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002659 moduleName = normalizeModuleName(moduleName)
2660
Colin Cross440e0d02020-06-11 11:32:11 -07002661 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002662 return true
2663 }
2664
2665 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002666 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002667 return true
2668 }
2669
2670 return false
2671}
2672
2673func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002674 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2675 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002676 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002677 if strings.HasPrefix(moduleName, "libclang_rt.") {
2678 // This module has many arch variants that depend on the product being built.
2679 // We don't want to list them all
2680 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002681 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002682 if strings.HasPrefix(moduleName, "androidx.") {
2683 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2684 moduleName = "androidx"
2685 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002686 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002687}
2688
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002689// Transform the map of apex -> modules to module -> apexes.
2690func invertApexBaseline(m map[string][]string) map[string][]string {
2691 r := make(map[string][]string)
2692 for apex, modules := range m {
2693 for _, module := range modules {
2694 r[module] = append(r[module], apex)
2695 }
2696 }
2697 return r
2698}
2699
2700// Retrieve the baseline of apexes to which the supplied module belongs.
2701func BaselineApexAvailable(moduleName string) []string {
2702 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2703}
2704
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002705// This is a map from apex to modules, which overrides the apex_available setting for that
2706// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002707// TODO(b/147364041): remove this
2708func makeApexAvailableBaseline() map[string][]string {
2709 // The "Module separator"s below are employed to minimize merge conflicts.
2710 m := make(map[string][]string)
2711 //
2712 // Module separator
2713 //
2714 m["com.android.appsearch"] = []string{
2715 "icing-java-proto-lite",
2716 "libprotobuf-java-lite",
2717 }
2718 //
2719 // Module separator
2720 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002721 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002722 "android.hardware.audio.common@5.0",
2723 "android.hardware.bluetooth.a2dp@1.0",
2724 "android.hardware.bluetooth.audio@2.0",
2725 "android.hardware.bluetooth@1.0",
2726 "android.hardware.bluetooth@1.1",
2727 "android.hardware.graphics.bufferqueue@1.0",
2728 "android.hardware.graphics.bufferqueue@2.0",
2729 "android.hardware.graphics.common@1.0",
2730 "android.hardware.graphics.common@1.1",
2731 "android.hardware.graphics.common@1.2",
2732 "android.hardware.media@1.0",
2733 "android.hidl.safe_union@1.0",
2734 "android.hidl.token@1.0",
2735 "android.hidl.token@1.0-utils",
2736 "avrcp-target-service",
2737 "avrcp_headers",
2738 "bluetooth-protos-lite",
2739 "bluetooth.mapsapi",
2740 "com.android.vcard",
2741 "dnsresolver_aidl_interface-V2-java",
2742 "ipmemorystore-aidl-interfaces-V5-java",
2743 "ipmemorystore-aidl-interfaces-java",
2744 "internal_include_headers",
2745 "lib-bt-packets",
2746 "lib-bt-packets-avrcp",
2747 "lib-bt-packets-base",
2748 "libFraunhoferAAC",
2749 "libaudio-a2dp-hw-utils",
2750 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002751 "libbluetooth",
2752 "libbluetooth-types",
2753 "libbluetooth-types-header",
2754 "libbluetooth_gd",
2755 "libbluetooth_headers",
2756 "libbluetooth_jni",
2757 "libbt-audio-hal-interface",
2758 "libbt-bta",
2759 "libbt-common",
2760 "libbt-hci",
2761 "libbt-platform-protos-lite",
2762 "libbt-protos-lite",
2763 "libbt-sbc-decoder",
2764 "libbt-sbc-encoder",
2765 "libbt-stack",
2766 "libbt-utils",
2767 "libbtcore",
2768 "libbtdevice",
2769 "libbte",
2770 "libbtif",
2771 "libchrome",
2772 "libevent",
2773 "libfmq",
2774 "libg722codec",
2775 "libgui_headers",
2776 "libmedia_headers",
2777 "libmodpb64",
2778 "libosi",
2779 "libstagefright_foundation_headers",
2780 "libstagefright_headers",
2781 "libstatslog",
2782 "libstatssocket",
2783 "libtinyxml2",
2784 "libudrv-uipc",
2785 "libz",
2786 "media_plugin_headers",
2787 "net-utils-services-common",
2788 "netd_aidl_interface-unstable-java",
2789 "netd_event_listener_interface-java",
2790 "netlink-client",
2791 "networkstack-client",
2792 "sap-api-java-static",
2793 "services.net",
2794 }
2795 //
2796 // Module separator
2797 //
2798 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2799 //
2800 // Module separator
2801 //
2802 m["com.android.extservices"] = []string{
2803 "error_prone_annotations",
2804 "ExtServices-core",
2805 "ExtServices",
2806 "libtextclassifier-java",
2807 "libz_current",
2808 "textclassifier-statsd",
2809 "TextClassifierNotificationLibNoManifest",
2810 "TextClassifierServiceLibNoManifest",
2811 }
2812 //
2813 // Module separator
2814 //
2815 m["com.android.neuralnetworks"] = []string{
2816 "android.hardware.neuralnetworks@1.0",
2817 "android.hardware.neuralnetworks@1.1",
2818 "android.hardware.neuralnetworks@1.2",
2819 "android.hardware.neuralnetworks@1.3",
2820 "android.hidl.allocator@1.0",
2821 "android.hidl.memory.token@1.0",
2822 "android.hidl.memory@1.0",
2823 "android.hidl.safe_union@1.0",
2824 "libarect",
2825 "libbuildversion",
2826 "libmath",
2827 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002828 }
2829 //
2830 // Module separator
2831 //
2832 m["com.android.media"] = []string{
2833 "android.frameworks.bufferhub@1.0",
2834 "android.hardware.cas.native@1.0",
2835 "android.hardware.cas@1.0",
2836 "android.hardware.configstore-utils",
2837 "android.hardware.configstore@1.0",
2838 "android.hardware.configstore@1.1",
2839 "android.hardware.graphics.allocator@2.0",
2840 "android.hardware.graphics.allocator@3.0",
2841 "android.hardware.graphics.bufferqueue@1.0",
2842 "android.hardware.graphics.bufferqueue@2.0",
2843 "android.hardware.graphics.common@1.0",
2844 "android.hardware.graphics.common@1.1",
2845 "android.hardware.graphics.common@1.2",
2846 "android.hardware.graphics.mapper@2.0",
2847 "android.hardware.graphics.mapper@2.1",
2848 "android.hardware.graphics.mapper@3.0",
2849 "android.hardware.media.omx@1.0",
2850 "android.hardware.media@1.0",
2851 "android.hidl.allocator@1.0",
2852 "android.hidl.memory.token@1.0",
2853 "android.hidl.memory@1.0",
2854 "android.hidl.token@1.0",
2855 "android.hidl.token@1.0-utils",
2856 "bionic_libc_platform_headers",
2857 "exoplayer2-extractor",
2858 "exoplayer2-extractor-annotation-stubs",
2859 "gl_headers",
2860 "jsr305",
2861 "libEGL",
2862 "libEGL_blobCache",
2863 "libEGL_getProcAddress",
2864 "libFLAC",
2865 "libFLAC-config",
2866 "libFLAC-headers",
2867 "libGLESv2",
2868 "libaacextractor",
2869 "libamrextractor",
2870 "libarect",
2871 "libaudio_system_headers",
2872 "libaudioclient",
2873 "libaudioclient_headers",
2874 "libaudiofoundation",
2875 "libaudiofoundation_headers",
2876 "libaudiomanager",
2877 "libaudiopolicy",
2878 "libaudioutils",
2879 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002880 "libbluetooth-types-header",
2881 "libbufferhub",
2882 "libbufferhub_headers",
2883 "libbufferhubqueue",
2884 "libc_malloc_debug_backtrace",
2885 "libcamera_client",
2886 "libcamera_metadata",
2887 "libdvr_headers",
2888 "libexpat",
2889 "libfifo",
2890 "libflacextractor",
2891 "libgrallocusage",
2892 "libgraphicsenv",
2893 "libgui",
2894 "libgui_headers",
2895 "libhardware_headers",
2896 "libinput",
2897 "liblzma",
2898 "libmath",
2899 "libmedia",
2900 "libmedia_codeclist",
2901 "libmedia_headers",
2902 "libmedia_helper",
2903 "libmedia_helper_headers",
2904 "libmedia_midiiowrapper",
2905 "libmedia_omx",
2906 "libmediautils",
2907 "libmidiextractor",
2908 "libmkvextractor",
2909 "libmp3extractor",
2910 "libmp4extractor",
2911 "libmpeg2extractor",
2912 "libnativebase_headers",
2913 "libnativewindow_headers",
2914 "libnblog",
2915 "liboggextractor",
2916 "libpackagelistparser",
2917 "libpdx",
2918 "libpdx_default_transport",
2919 "libpdx_headers",
2920 "libpdx_uds",
2921 "libprocinfo",
2922 "libspeexresampler",
2923 "libspeexresampler",
2924 "libstagefright_esds",
2925 "libstagefright_flacdec",
2926 "libstagefright_flacdec",
2927 "libstagefright_foundation",
2928 "libstagefright_foundation_headers",
2929 "libstagefright_foundation_without_imemory",
2930 "libstagefright_headers",
2931 "libstagefright_id3",
2932 "libstagefright_metadatautils",
2933 "libstagefright_mpeg2extractor",
2934 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002935 "libui",
2936 "libui_headers",
2937 "libunwindstack",
2938 "libvibrator",
2939 "libvorbisidec",
2940 "libwavextractor",
2941 "libwebm",
2942 "media_ndk_headers",
2943 "media_plugin_headers",
2944 "updatable-media",
2945 }
2946 //
2947 // Module separator
2948 //
2949 m["com.android.media.swcodec"] = []string{
2950 "android.frameworks.bufferhub@1.0",
2951 "android.hardware.common-ndk_platform",
2952 "android.hardware.configstore-utils",
2953 "android.hardware.configstore@1.0",
2954 "android.hardware.configstore@1.1",
2955 "android.hardware.graphics.allocator@2.0",
2956 "android.hardware.graphics.allocator@3.0",
2957 "android.hardware.graphics.allocator@4.0",
2958 "android.hardware.graphics.bufferqueue@1.0",
2959 "android.hardware.graphics.bufferqueue@2.0",
2960 "android.hardware.graphics.common-ndk_platform",
2961 "android.hardware.graphics.common@1.0",
2962 "android.hardware.graphics.common@1.1",
2963 "android.hardware.graphics.common@1.2",
2964 "android.hardware.graphics.mapper@2.0",
2965 "android.hardware.graphics.mapper@2.1",
2966 "android.hardware.graphics.mapper@3.0",
2967 "android.hardware.graphics.mapper@4.0",
2968 "android.hardware.media.bufferpool@2.0",
2969 "android.hardware.media.c2@1.0",
2970 "android.hardware.media.c2@1.1",
2971 "android.hardware.media.omx@1.0",
2972 "android.hardware.media@1.0",
2973 "android.hardware.media@1.0",
2974 "android.hidl.memory.token@1.0",
2975 "android.hidl.memory@1.0",
2976 "android.hidl.safe_union@1.0",
2977 "android.hidl.token@1.0",
2978 "android.hidl.token@1.0-utils",
2979 "libEGL",
2980 "libFLAC",
2981 "libFLAC-config",
2982 "libFLAC-headers",
2983 "libFraunhoferAAC",
2984 "libLibGuiProperties",
2985 "libarect",
2986 "libaudio_system_headers",
2987 "libaudioutils",
2988 "libaudioutils",
2989 "libaudioutils_fixedfft",
2990 "libavcdec",
2991 "libavcenc",
2992 "libavservices_minijail",
2993 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002994 "libbinderthreadstateutils",
2995 "libbluetooth-types-header",
2996 "libbufferhub_headers",
2997 "libcodec2",
2998 "libcodec2_headers",
2999 "libcodec2_hidl@1.0",
3000 "libcodec2_hidl@1.1",
3001 "libcodec2_internal",
3002 "libcodec2_soft_aacdec",
3003 "libcodec2_soft_aacenc",
3004 "libcodec2_soft_amrnbdec",
3005 "libcodec2_soft_amrnbenc",
3006 "libcodec2_soft_amrwbdec",
3007 "libcodec2_soft_amrwbenc",
3008 "libcodec2_soft_av1dec_gav1",
3009 "libcodec2_soft_avcdec",
3010 "libcodec2_soft_avcenc",
3011 "libcodec2_soft_common",
3012 "libcodec2_soft_flacdec",
3013 "libcodec2_soft_flacenc",
3014 "libcodec2_soft_g711alawdec",
3015 "libcodec2_soft_g711mlawdec",
3016 "libcodec2_soft_gsmdec",
3017 "libcodec2_soft_h263dec",
3018 "libcodec2_soft_h263enc",
3019 "libcodec2_soft_hevcdec",
3020 "libcodec2_soft_hevcenc",
3021 "libcodec2_soft_mp3dec",
3022 "libcodec2_soft_mpeg2dec",
3023 "libcodec2_soft_mpeg4dec",
3024 "libcodec2_soft_mpeg4enc",
3025 "libcodec2_soft_opusdec",
3026 "libcodec2_soft_opusenc",
3027 "libcodec2_soft_rawdec",
3028 "libcodec2_soft_vorbisdec",
3029 "libcodec2_soft_vp8dec",
3030 "libcodec2_soft_vp8enc",
3031 "libcodec2_soft_vp9dec",
3032 "libcodec2_soft_vp9enc",
3033 "libcodec2_vndk",
3034 "libdvr_headers",
3035 "libfmq",
3036 "libfmq",
3037 "libgav1",
3038 "libgralloctypes",
3039 "libgrallocusage",
3040 "libgraphicsenv",
3041 "libgsm",
3042 "libgui_bufferqueue_static",
3043 "libgui_headers",
3044 "libhardware",
3045 "libhardware_headers",
3046 "libhevcdec",
3047 "libhevcenc",
3048 "libion",
3049 "libjpeg",
3050 "liblzma",
3051 "libmath",
3052 "libmedia_codecserviceregistrant",
3053 "libmedia_headers",
3054 "libmpeg2dec",
3055 "libnativebase_headers",
3056 "libnativewindow_headers",
3057 "libpdx_headers",
3058 "libscudo_wrapper",
3059 "libsfplugin_ccodec_utils",
3060 "libspeexresampler",
3061 "libstagefright_amrnb_common",
3062 "libstagefright_amrnbdec",
3063 "libstagefright_amrnbenc",
3064 "libstagefright_amrwbdec",
3065 "libstagefright_amrwbenc",
3066 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003067 "libstagefright_enc_common",
3068 "libstagefright_flacdec",
3069 "libstagefright_foundation",
3070 "libstagefright_foundation_headers",
3071 "libstagefright_headers",
3072 "libstagefright_m4vh263dec",
3073 "libstagefright_m4vh263enc",
3074 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003075 "libui",
3076 "libui_headers",
3077 "libunwindstack",
3078 "libvorbisidec",
3079 "libvpx",
3080 "libyuv",
3081 "libyuv_static",
3082 "media_ndk_headers",
3083 "media_plugin_headers",
3084 "mediaswcodec",
3085 }
3086 //
3087 // Module separator
3088 //
3089 m["com.android.mediaprovider"] = []string{
3090 "MediaProvider",
3091 "MediaProviderGoogle",
3092 "fmtlib_ndk",
3093 "libbase_ndk",
3094 "libfuse",
3095 "libfuse_jni",
3096 }
3097 //
3098 // Module separator
3099 //
3100 m["com.android.permission"] = []string{
3101 "car-ui-lib",
3102 "iconloader",
3103 "kotlin-annotations",
3104 "kotlin-stdlib",
3105 "kotlin-stdlib-jdk7",
3106 "kotlin-stdlib-jdk8",
3107 "kotlinx-coroutines-android",
3108 "kotlinx-coroutines-android-nodeps",
3109 "kotlinx-coroutines-core",
3110 "kotlinx-coroutines-core-nodeps",
3111 "permissioncontroller-statsd",
3112 "GooglePermissionController",
3113 "PermissionController",
3114 "SettingsLibActionBarShadow",
3115 "SettingsLibAppPreference",
3116 "SettingsLibBarChartPreference",
3117 "SettingsLibLayoutPreference",
3118 "SettingsLibProgressBar",
3119 "SettingsLibSearchWidget",
3120 "SettingsLibSettingsTheme",
3121 "SettingsLibRestrictedLockUtils",
3122 "SettingsLibHelpUtils",
3123 }
3124 //
3125 // Module separator
3126 //
3127 m["com.android.runtime"] = []string{
3128 "bionic_libc_platform_headers",
3129 "libarm-optimized-routines-math",
3130 "libc_aeabi",
3131 "libc_bionic",
3132 "libc_bionic_ndk",
3133 "libc_bootstrap",
3134 "libc_common",
3135 "libc_common_shared",
3136 "libc_common_static",
3137 "libc_dns",
3138 "libc_dynamic_dispatch",
3139 "libc_fortify",
3140 "libc_freebsd",
3141 "libc_freebsd_large_stack",
3142 "libc_gdtoa",
3143 "libc_init_dynamic",
3144 "libc_init_static",
3145 "libc_jemalloc_wrapper",
3146 "libc_netbsd",
3147 "libc_nomalloc",
3148 "libc_nopthread",
3149 "libc_openbsd",
3150 "libc_openbsd_large_stack",
3151 "libc_openbsd_ndk",
3152 "libc_pthread",
3153 "libc_static_dispatch",
3154 "libc_syscalls",
3155 "libc_tzcode",
3156 "libc_unwind_static",
3157 "libdebuggerd",
3158 "libdebuggerd_common_headers",
3159 "libdebuggerd_handler_core",
3160 "libdebuggerd_handler_fallback",
3161 "libdl_static",
3162 "libjemalloc5",
3163 "liblinker_main",
3164 "liblinker_malloc",
3165 "liblz4",
3166 "liblzma",
3167 "libprocinfo",
3168 "libpropertyinfoparser",
3169 "libscudo",
3170 "libstdc++",
3171 "libsystemproperties",
3172 "libtombstoned_client_static",
3173 "libunwindstack",
3174 "libz",
3175 "libziparchive",
3176 }
3177 //
3178 // Module separator
3179 //
3180 m["com.android.tethering"] = []string{
3181 "android.hardware.tetheroffload.config-V1.0-java",
3182 "android.hardware.tetheroffload.control-V1.0-java",
3183 "android.hidl.base-V1.0-java",
3184 "libcgrouprc",
3185 "libcgrouprc_format",
3186 "libtetherutilsjni",
3187 "libvndksupport",
3188 "net-utils-framework-common",
3189 "netd_aidl_interface-V3-java",
3190 "netlink-client",
3191 "networkstack-aidl-interfaces-java",
3192 "tethering-aidl-interfaces-java",
3193 "TetheringApiCurrentLib",
3194 }
3195 //
3196 // Module separator
3197 //
3198 m["com.android.wifi"] = []string{
3199 "PlatformProperties",
3200 "android.hardware.wifi-V1.0-java",
3201 "android.hardware.wifi-V1.0-java-constants",
3202 "android.hardware.wifi-V1.1-java",
3203 "android.hardware.wifi-V1.2-java",
3204 "android.hardware.wifi-V1.3-java",
3205 "android.hardware.wifi-V1.4-java",
3206 "android.hardware.wifi.hostapd-V1.0-java",
3207 "android.hardware.wifi.hostapd-V1.1-java",
3208 "android.hardware.wifi.hostapd-V1.2-java",
3209 "android.hardware.wifi.supplicant-V1.0-java",
3210 "android.hardware.wifi.supplicant-V1.1-java",
3211 "android.hardware.wifi.supplicant-V1.2-java",
3212 "android.hardware.wifi.supplicant-V1.3-java",
3213 "android.hidl.base-V1.0-java",
3214 "android.hidl.manager-V1.0-java",
3215 "android.hidl.manager-V1.1-java",
3216 "android.hidl.manager-V1.2-java",
3217 "bouncycastle-unbundled",
3218 "dnsresolver_aidl_interface-V2-java",
3219 "error_prone_annotations",
3220 "framework-wifi-pre-jarjar",
3221 "framework-wifi-util-lib",
3222 "ipmemorystore-aidl-interfaces-V3-java",
3223 "ipmemorystore-aidl-interfaces-java",
3224 "ksoap2",
3225 "libnanohttpd",
3226 "libwifi-jni",
3227 "net-utils-services-common",
3228 "netd_aidl_interface-V2-java",
3229 "netd_aidl_interface-unstable-java",
3230 "netd_event_listener_interface-java",
3231 "netlink-client",
3232 "networkstack-client",
3233 "services.net",
3234 "wifi-lite-protos",
3235 "wifi-nano-protos",
3236 "wifi-service-pre-jarjar",
3237 "wifi-service-resources",
3238 }
3239 //
3240 // Module separator
3241 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003242 m["com.android.os.statsd"] = []string{
3243 "libstatssocket",
3244 }
3245 //
3246 // Module separator
3247 //
3248 m[android.AvailableToAnyApex] = []string{
3249 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3250 "androidx",
3251 "androidx-constraintlayout_constraintlayout",
3252 "androidx-constraintlayout_constraintlayout-nodeps",
3253 "androidx-constraintlayout_constraintlayout-solver",
3254 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3255 "com.google.android.material_material",
3256 "com.google.android.material_material-nodeps",
3257
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003258 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003259 "libprofile-clang-extras",
3260 "libprofile-clang-extras_ndk",
3261 "libprofile-extras",
3262 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003263 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003264 }
3265 return m
3266}
3267
3268func init() {
3269 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3270 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3271}
3272
3273func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3274 rules := make([]android.Rule, 0, len(modules_packages))
3275 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003276 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003277 BootclasspathJar().
3278 With("apex_available", module_name).
3279 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003280 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003281 Because("jars that are part of the " + module_name +
Andrei Onead967aee2022-01-19 15:36:40 +00003282 " module may only use these package prefixes: " + strings.Join(module_packages, ",") +
3283 " with min_sdk < T. Please consider the following alternatives:\n" +
3284 " 1. If the offending code is from a statically linked library, consider " +
3285 "removing that dependency and using an alternative already in the " +
3286 "bootclasspath, or perhaps a shared library." +
3287 " 2. Move the offending code into an allowed package.\n" +
3288 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3289 "health implications of bundling that code, particularly if the offending jar " +
3290 "is part of the bootclasspath.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003291 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003292 }
3293 return rules
3294}
3295
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003296// 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 +09003297// Adding code to the bootclasspath in new packages will cause issues on module update.
3298func qModulesPackages() map[string][]string {
3299 return map[string][]string{
3300 "com.android.conscrypt": []string{
3301 "android.net.ssl",
3302 "com.android.org.conscrypt",
3303 },
3304 "com.android.media": []string{
3305 "android.media",
3306 },
3307 }
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 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 rModulesPackages() map[string][]string {
3313 return map[string][]string{
3314 "com.android.mediaprovider": []string{
3315 "android.provider",
3316 },
3317 "com.android.permission": []string{
3318 "android.permission",
3319 "android.app.role",
3320 "com.android.permission",
3321 "com.android.role",
3322 },
3323 "com.android.sdkext": []string{
3324 "android.os.ext",
3325 },
3326 "com.android.os.statsd": []string{
3327 "android.app",
3328 "android.os",
3329 "android.util",
3330 "com.android.internal.statsd",
3331 "com.android.server.stats",
3332 },
3333 "com.android.wifi": []string{
3334 "com.android.server.wifi",
3335 "com.android.wifi.x",
3336 "android.hardware.wifi",
3337 "android.net.wifi",
3338 },
3339 "com.android.tethering": []string{
3340 "android.net",
3341 },
3342 }
3343}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003344
3345// For Bazel / bp2build
3346
3347type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003348 Manifest bazel.LabelAttribute
3349 Android_manifest bazel.LabelAttribute
3350 File_contexts bazel.LabelAttribute
3351 Key bazel.LabelAttribute
3352 Certificate bazel.LabelAttribute
3353 Min_sdk_version *string
3354 Updatable bazel.BoolAttribute
3355 Installable bazel.BoolAttribute
3356 Binaries bazel.LabelListAttribute
3357 Prebuilts bazel.LabelListAttribute
3358 Native_shared_libs_32 bazel.LabelListAttribute
3359 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003360 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003361}
3362
3363type convertedNativeSharedLibs struct {
3364 Native_shared_libs_32 bazel.LabelListAttribute
3365 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003366}
3367
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003368// ConvertWithBp2build performs bp2build conversion of an apex
3369func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3370 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003371 if ctx.ModuleType() != "apex" {
3372 return
3373 }
3374
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003375 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003376 if a.properties.Manifest != nil {
3377 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003378 }
3379
3380 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003381 if a.properties.AndroidManifest != nil {
3382 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003383 }
3384
3385 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003386 if a.properties.File_contexts != nil {
3387 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003388 }
3389
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003390 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003391 if a.properties.Min_sdk_version != nil {
3392 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003393 }
3394
3395 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003396 if a.overridableProperties.Key != nil {
3397 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003398 }
3399
3400 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003401 if a.overridableProperties.Certificate != nil {
3402 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003403 }
3404
Yu Liu4ae55d12022-01-05 17:17:23 -08003405 nativeSharedLibs := &convertedNativeSharedLibs{
3406 Native_shared_libs_32: bazel.LabelListAttribute{},
3407 Native_shared_libs_64: bazel.LabelListAttribute{},
3408 }
3409 compileMultilib := "both"
3410 if a.CompileMultilib() != nil {
3411 compileMultilib = *a.CompileMultilib()
3412 }
3413
3414 // properties.Native_shared_libs is treated as "both"
3415 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3416 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3417 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3418 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3419 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003420
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003421 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003422 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3423 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3424
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003425 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003426 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003427
3428 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003429 if a.properties.Updatable != nil {
3430 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003431 }
3432
3433 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003434 if a.properties.Installable != nil {
3435 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003436 }
3437
Wei Lif034cb42022-01-19 15:54:31 -08003438 var compressibleAttribute bazel.BoolAttribute
3439 if a.overridableProperties.Compressible != nil {
3440 compressibleAttribute.Value = a.overridableProperties.Compressible
3441 }
3442
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003443 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003444 Manifest: manifestLabelAttribute,
3445 Android_manifest: androidManifestLabelAttribute,
3446 File_contexts: fileContextsLabelAttribute,
3447 Min_sdk_version: minSdkVersion,
3448 Key: keyLabelAttribute,
3449 Certificate: certificateLabelAttribute,
3450 Updatable: updatableAttribute,
3451 Installable: installableAttribute,
3452 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3453 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3454 Binaries: binariesLabelListAttribute,
3455 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003456 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003457 }
3458
3459 props := bazel.BazelTargetModuleProperties{
3460 Rule_class: "apex",
3461 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3462 }
3463
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003464 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003465}
Yu Liu4ae55d12022-01-05 17:17:23 -08003466
3467// The following conversions are based on this table where the rows are the compile_multilib
3468// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3469// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3470// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3471// should not be compiled.
3472// multib/compile_multilib, 32, 64, both, first
3473// 32, 32/32, none/none, 32/32, none/32
3474// 64, none/none, 64/none, 64/none, 64/none
3475// both, 32/32, 64/none, 32&64/32, 64/32
3476// first, 32/32, 64/none, 64/32, 64/32
3477
3478func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3479 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3480 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3481 switch compileMultilb {
3482 case "both", "32":
3483 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3484 case "first":
3485 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3486 case "64":
3487 // Incompatible, ignore
3488 default:
3489 invalidCompileMultilib(ctx, compileMultilb)
3490 }
3491}
3492
3493func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3494 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3495 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3496 switch compileMultilb {
3497 case "both", "64", "first":
3498 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3499 case "32":
3500 // Incompatible, ignore
3501 default:
3502 invalidCompileMultilib(ctx, compileMultilb)
3503 }
3504}
3505
3506func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3507 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3508 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3509 switch compileMultilb {
3510 case "both":
3511 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3512 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3513 case "first":
3514 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3515 case "32":
3516 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3517 case "64":
3518 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3519 default:
3520 invalidCompileMultilib(ctx, compileMultilb)
3521 }
3522}
3523
3524func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3525 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3526 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3527 switch compileMultilb {
3528 case "both", "first":
3529 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3530 case "32":
3531 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3532 case "64":
3533 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3534 default:
3535 invalidCompileMultilib(ctx, compileMultilb)
3536 }
3537}
3538
3539func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3540 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3541 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3542}
3543
3544func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3545 list := bazel.LabelListAttribute{}
3546 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3547 nativeSharedLibs.Native_shared_libs_32.Append(list)
3548}
3549
3550func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3551 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3552 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3553}
3554
3555func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3556 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3557 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3558}
3559
3560func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3561 labelListAttr *bazel.LabelListAttribute) {
3562 list := bazel.LabelListAttribute{}
3563 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3564 labelListAttr.Append(list)
3565}
3566
3567func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3568 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3569}