blob: 4bcba7e4350f2d7beb0bc492995ce5b4c9393b95 [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
Bob Badourde6a0872022-04-01 18:00:00 +0000417 // Path to notice file in html.gz format.
418 htmlGzNotice android.WritablePath
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900420 // The built APEX file. This is the main product.
Jooyung Hana6d36672022-02-24 13:58:07 +0900421 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900422 outputFile android.WritablePath
423
Jooyung Hana6d36672022-02-24 13:58:07 +0900424 // The built uncompressed .apex file.
425 outputApexFile android.WritablePath
426
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900427 // The built APEX file in app bundle format. This file is not directly installed to the
428 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
429 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
430 // system) to be merged into a single app bundle file that Play accepts. See
431 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
432 bundleModuleFile android.WritablePath
433
Colin Cross6340ea52021-11-04 12:01:18 -0700434 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900435 installDir android.InstallPath
436
Colin Cross6340ea52021-11-04 12:01:18 -0700437 // Path where this APEX was installed.
438 installedFile android.InstallPath
439
440 // Installed locations of symlinks for backward compatibility.
441 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900442
443 // Text file having the list of individual files that are included in this APEX. Used for
444 // debugging purpose.
445 installedFilesFile android.WritablePath
446
447 // List of module names that this APEX is including (to be shown via *-deps-info target).
448 // Used for debugging purpose.
449 android.ApexBundleDepsInfo
450
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900451 // Optional list of lint report zip files for apexes that contain java or app modules
452 lintReports android.Paths
453
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900454 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000455
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000456 isCompressed bool
457
sophiezc80a2b32020-11-12 16:39:19 +0000458 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700459 nativeApisUsedByModuleFile android.ModuleOutPath
460 nativeApisBackedByModuleFile android.ModuleOutPath
461 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800462
463 // Collect the module directory for IDE info in java/jdeps.go.
464 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900465}
466
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900467// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900468type apexFileClass int
469
Jooyung Han72bd2f82019-10-23 16:46:38 +0900470const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900471 app apexFileClass = iota
472 appSet
473 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900474 goBinary
475 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900476 nativeExecutable
477 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900478 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900479 pyBinary
480 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900481)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900482
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900483// apexFile represents a file in an APEX bundle. This is created during the first half of
484// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
485// of the function, this is used to create commands that copies the files into a staging directory,
486// where they are packaged into the APEX file. This struct is also used for creating Make modules
487// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900488type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900489 // buildFile is put in the installDir inside the APEX.
Bob Badourde6a0872022-04-01 18:00:00 +0000490 builtFile android.Path
491 installDir string
492 customStem string
493 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900494
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900495 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
496 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
497 // suffix>]
498 androidMkModuleName string // becomes LOCAL_MODULE
499 class apexFileClass // becomes LOCAL_MODULE_CLASS
500 moduleDir string // becomes LOCAL_PATH
501 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
502 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
503 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
504 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900505
506 jacocoReportClassesFile android.Path // only for javalibs and apps
507 lintDepSets java.LintDepSets // only for javalibs and apps
508 certificate java.Certificate // only for apps
509 overriddenPackageName string // only for apps
510
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900511 transitiveDep bool
512 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900513
Jiyong Park57621b22021-01-20 20:33:11 +0900514 multilib string
515
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900516 // TODO(jiyong): remove this
517 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900518}
519
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900520// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
522 ret := apexFile{
523 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900524 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900525 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900526 class: class,
527 module: module,
528 }
529 if module != nil {
530 ret.moduleDir = ctx.OtherModuleDir(module)
531 ret.requiredModuleNames = module.RequiredModuleNames()
532 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
533 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900534 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900535 }
536 return ret
537}
538
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900539func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900540 return af.builtFile != nil && af.builtFile.String() != ""
541}
542
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900543// apexRelativePath returns the relative path of the given path from the install directory of this
544// apexFile.
545// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900546func (af *apexFile) apexRelativePath(path string) string {
547 return filepath.Join(af.installDir, path)
548}
549
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900550// path returns path of this apex file relative to the APEX root
551func (af *apexFile) path() string {
552 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900553}
554
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900555// stem returns the base filename of this apex file
556func (af *apexFile) stem() string {
557 if af.customStem != "" {
558 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900559 }
560 return af.builtFile.Base()
561}
562
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900563// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
564func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900565 var ret []string
566 for _, symlink := range af.symlinks {
567 ret = append(ret, af.apexRelativePath(symlink))
568 }
569 return ret
570}
571
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900572// availableToPlatform tests whether this apexFile is from a module that can be installed to the
573// platform.
574func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900575 if af.module == nil {
576 return false
577 }
578 if am, ok := af.module.(android.ApexModule); ok {
579 return am.AvailableFor(android.AvailableToPlatform)
580 }
581 return false
582}
583
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900584////////////////////////////////////////////////////////////////////////////////////////////////////
585// Mutators
586//
587// Brief description about mutators for APEX. The following three mutators are the most important
588// ones.
589//
590// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
591// to the (direct) dependencies of this APEX bundle.
592//
Paul Duffin949abc02020-12-08 10:34:30 +0000593// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900594// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
595// modules are marked as being included in the APEX via BuildForApex().
596//
Paul Duffin949abc02020-12-08 10:34:30 +0000597// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
598// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900599
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900600type dependencyTag struct {
601 blueprint.BaseDependencyTag
602 name string
603
604 // Determines if the dependent will be part of the APEX payload. Can be false for the
605 // dependencies to the signing key module, etc.
606 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000607
608 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
609 // replacement. This is needed because some prebuilt modules do not provide all the information
610 // needed by the apex.
611 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900612}
613
Paul Duffin8c535da2021-03-17 14:51:03 +0000614func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
615 return !d.sourceOnly
616}
617
618var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
619
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900620var (
Paul Duffin0b817782021-03-17 15:02:19 +0000621 androidAppTag = dependencyTag{name: "androidApp", payload: true}
622 bpfTag = dependencyTag{name: "bpf", payload: true}
623 certificateTag = dependencyTag{name: "certificate"}
624 executableTag = dependencyTag{name: "executable", payload: true}
625 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100626 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100627 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000628 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000629 javaLibTag = dependencyTag{name: "javaLib", payload: true}
630 jniLibTag = dependencyTag{name: "jniLib", payload: true}
631 keyTag = dependencyTag{name: "key"}
632 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
633 rroTag = dependencyTag{name: "rro", payload: true}
634 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
635 testForTag = dependencyTag{name: "test for"}
636 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000637 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900638)
639
640// TODO(jiyong): shorten this function signature
641func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900642 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900643 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900644 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900645
646 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900647 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900648 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
649 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900650 }
651
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900652 // Use *FarVariation* to be able to depend on modules having conflicting variations with
653 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
654 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900655 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900656 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900657 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
658 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900659 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900660 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900661}
662
663func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900664 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900665 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
666 } else {
667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
668 if ctx.Os().Bionic() {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
670 } else {
671 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
672 }
673 }
674}
675
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900676// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
677// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
678func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
679 deviceConfig := ctx.DeviceConfig()
680 if a.vndkApex {
681 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900682 }
683
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900684 var prefix string
685 var vndkVersion string
686 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000687 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900688 prefix = cc.VendorVariationPrefix
689 vndkVersion = deviceConfig.VndkVersion()
690 } else if a.ProductSpecific() {
691 prefix = cc.ProductVariationPrefix
692 vndkVersion = deviceConfig.ProductVndkVersion()
693 }
694 }
695 if vndkVersion == "current" {
696 vndkVersion = deviceConfig.PlatformVndkVersion()
697 }
698 if vndkVersion != "" {
699 return prefix + vndkVersion
700 }
701
702 return android.CoreVariation // The usual case
703}
704
705func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900706 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
707 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
708 // each target os/architectures, appropriate dependencies are selected by their
709 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900710 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900711 imageVariation := a.getImageVariation(ctx)
712
713 a.combineProperties(ctx)
714
715 has32BitTarget := false
716 for _, target := range targets {
717 if target.Arch.ArchType.Multilib == "lib32" {
718 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000719 }
720 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900721 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900722 // Don't include artifacts for the host cross targets because there is no way for us
723 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900724 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900725 continue
726 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000727
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900728 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000729
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 // Add native modules targeting both ABIs. When multilib.* is omitted for
731 // native_shared_libs/jni_libs/tests, it implies multilib.both
732 depsList = append(depsList, a.properties.Multilib.Both)
733 depsList = append(depsList, ApexNativeDependencies{
734 Native_shared_libs: a.properties.Native_shared_libs,
735 Tests: a.properties.Tests,
736 Jni_libs: a.properties.Jni_libs,
737 Binaries: nil,
738 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900739
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900740 // Add native modules targeting the first ABI When multilib.* is omitted for
741 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900742 isPrimaryAbi := i == 0
743 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900744 depsList = append(depsList, a.properties.Multilib.First)
745 depsList = append(depsList, ApexNativeDependencies{
746 Native_shared_libs: nil,
747 Tests: nil,
748 Jni_libs: nil,
749 Binaries: a.properties.Binaries,
750 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900751 }
752
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900753 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900754 switch target.Arch.ArchType.Multilib {
755 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900756 depsList = append(depsList, a.properties.Multilib.Lib32)
757 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900758 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900759 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900762 }
763 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900764
Jiyong Park59140302020-12-14 18:44:04 +0900765 // Add native modules targeting a specific arch variant
766 switch target.Arch.ArchType {
767 case android.Arm:
768 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
769 case android.Arm64:
770 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
771 case android.X86:
772 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
773 case android.X86_64:
774 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
775 default:
776 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
777 }
778
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900779 for _, d := range depsList {
780 addDependenciesForNativeModules(ctx, d, target, imageVariation)
781 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000782 ctx.AddFarVariationDependencies([]blueprint.Variation{
783 {Mutator: "os", Variation: target.OsVariation()},
784 {Mutator: "arch", Variation: target.ArchVariation()},
785 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900786 }
787
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900788 // Common-arch dependencies come next
789 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Jiyong Park12a719c2021-01-07 15:31:24 +0900790 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000791 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900792
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900793 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
794 // This field currently isn't used.
795 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900796 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
797 if len(a.properties.Uses_sdks) > 0 {
798 sdkRefs := []android.SdkRef{}
799 for _, str := range a.properties.Uses_sdks {
800 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
801 sdkRefs = append(sdkRefs, parsed)
802 }
803 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100804 }
805}
806
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900807// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900808func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
809 if a.overridableProperties.Allowed_files != nil {
810 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100811 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900812
813 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
814 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800815 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900816 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900817 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.overridableProperties.Bootclasspath_fragments...)
818 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.overridableProperties.Systemserverclasspath_fragments...)
819 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.overridableProperties.Java_libs...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700820 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
821 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
822 // regardless of the TARGET_PREFER_* setting. See b/144532908
823 arches := ctx.DeviceConfig().Arches()
824 if len(arches) != 0 {
825 archForPrebuiltEtc := arches[0]
826 for _, arch := range arches {
827 // Prefer 64-bit arch if there is any
828 if arch.ArchType.Multilib == "lib64" {
829 archForPrebuiltEtc = arch
830 break
831 }
832 }
833 ctx.AddFarVariationDependencies([]blueprint.Variation{
834 {Mutator: "os", Variation: ctx.Os().String()},
835 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
836 }, prebuiltTag, prebuilts...)
837 }
838 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700839
840 // Dependencies for signing
841 if String(a.overridableProperties.Key) == "" {
842 ctx.PropertyErrorf("key", "missing")
843 return
844 }
845 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
846
847 cert := android.SrcIsModule(a.getCertString(ctx))
848 if cert != "" {
849 ctx.AddDependency(ctx.Module(), certificateTag, cert)
850 // empty cert is not an error. Cert and private keys will be directly found under
851 // PRODUCT_DEFAULT_DEV_CERTIFICATE
852 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100853}
854
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900855type ApexBundleInfo struct {
856 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100857}
858
Paul Duffin949abc02020-12-08 10:34:30 +0000859var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900860
Paul Duffina7d6a892020-12-07 17:39:59 +0000861var _ ApexInfoMutator = (*apexBundle)(nil)
862
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100863func (a *apexBundle) ApexVariationName() string {
864 return a.properties.ApexVariationName
865}
866
Paul Duffina7d6a892020-12-07 17:39:59 +0000867// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900868// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
869// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
870// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
871// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000872//
873// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
874// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
875// The apexMutator uses that list to create module variants for the apexes to which it belongs.
876// The relationship between module variants and apexes is not one-to-one as variants will be
877// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000878func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900879
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900880 // The VNDK APEX is special. For the APEX, the membership is described in a very different
881 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
882 // libraries are self-identified by their vndk.enabled properties. There is no need to run
883 // this mutator for the APEX as nothing will be collected. So, let's return fast.
884 if a.vndkApex {
885 return
886 }
887
888 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
889 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
890 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
891 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
892 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900893 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
894 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900895 if proptools.Bool(a.properties.Use_vndk_as_stable) {
896 if !useVndk {
897 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
898 }
899 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
900 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
901 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
902 }
903 })
904 if mctx.Failed() {
905 return
906 }
Jooyung Handf78e212020-07-22 15:54:47 +0900907 }
908
Colin Cross56a83212020-09-15 18:30:11 -0700909 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900910 am, ok := child.(android.ApexModule)
911 if !ok || !am.CanHaveApexVariants() {
912 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900913 }
Paul Duffin573989d2021-03-17 13:25:29 +0000914 depTag := mctx.OtherModuleDependencyTag(child)
915
916 // Check to see if the tag always requires that the child module has an apex variant for every
917 // apex variant of the parent module. If it does not then it is still possible for something
918 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
919 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
920 return true
921 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000922 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900923 return false
924 }
Jooyung Handf78e212020-07-22 15:54:47 +0900925 if excludeVndkLibs {
926 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
927 return false
928 }
929 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900930 // By default, all the transitive dependencies are collected, unless filtered out
931 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700932 return true
933 }
934
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900935 // Records whether a certain module is included in this apexBundle via direct dependency or
936 // inndirect dependency.
937 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700938 mctx.WalkDeps(func(child, parent android.Module) bool {
939 if !continueApexDepsWalk(child, parent) {
940 return false
941 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900942 // If the parent is apexBundle, this child is directly depended.
943 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900944 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700945 contents[depName] = contents[depName].Add(directDep)
946 return true
947 })
948
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900949 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900950 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700951 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
952 Contents: apexContents,
953 })
954
Jooyung Haned124c32021-01-26 11:43:46 +0900955 minSdkVersion := a.minSdkVersion(mctx)
956 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
957 if minSdkVersion.IsNone() {
958 minSdkVersion = android.FutureApiLevel
959 }
960
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900961 // This is the main part of this mutator. Mark the collected dependencies that they need to
962 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900963
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100964 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
965 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700966 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100967 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900968 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700969 RequiredSdks: a.RequiredSdks(),
970 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900971 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100972 InApexVariants: []string{apexVariationName},
973 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700974 ApexContents: []*android.ApexContents{apexContents},
975 }
Colin Cross56a83212020-09-15 18:30:11 -0700976 mctx.WalkDeps(func(child, parent android.Module) bool {
977 if !continueApexDepsWalk(child, parent) {
978 return false
979 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900980 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900981 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900982 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900983}
984
Paul Duffina7d6a892020-12-07 17:39:59 +0000985type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100986 // ApexVariationName returns the name of the APEX variation to use in the apex
987 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
988 ApexVariationName() string
989
Paul Duffina7d6a892020-12-07 17:39:59 +0000990 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
991 // depended upon by an apex and which require an apex specific variant.
992 ApexInfoMutator(android.TopDownMutatorContext)
993}
994
995// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
996// specific variant to modules that support the ApexInfoMutator.
Spandan Das42e89502022-05-06 22:12:55 +0000997// It also propagates updatable=true to apps of updatable apexes
Paul Duffina7d6a892020-12-07 17:39:59 +0000998func apexInfoMutator(mctx android.TopDownMutatorContext) {
999 if !mctx.Module().Enabled() {
1000 return
1001 }
1002
1003 if a, ok := mctx.Module().(ApexInfoMutator); ok {
1004 a.ApexInfoMutator(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +00001005 }
Spandan Das42e89502022-05-06 22:12:55 +00001006 enforceAppUpdatability(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +00001007}
1008
Spandan Das66773252022-01-15 00:23:18 +00001009// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
1010// This check is enforced for updatable modules
1011func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
1012 if !mctx.Module().Enabled() {
1013 return
1014 }
Spandan Das08c911f2022-01-21 22:07:26 +00001015 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +00001016 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001017 // b/208656169 Do not propagate strict updatability linting to libcore/
1018 // These libs are available on the classpath during compilation
1019 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1020 // Only skip libraries defined in libcore root, not subdirectories
1021 if mctx.OtherModuleDir(child) == "libcore" {
1022 // Do not traverse transitive deps of libcore/ libs
1023 return false
1024 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001025 if android.InList(child.Name(), skipLintJavalibAllowlist) {
1026 return false
1027 }
Spandan Das66773252022-01-15 00:23:18 +00001028 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1029 lintable.SetStrictUpdatabilityLinting(true)
1030 }
1031 // visit transitive deps
1032 return true
1033 })
1034 }
1035}
1036
Spandan Das42e89502022-05-06 22:12:55 +00001037// enforceAppUpdatability propagates updatable=true to apps of updatable apexes
1038func enforceAppUpdatability(mctx android.TopDownMutatorContext) {
1039 if !mctx.Module().Enabled() {
1040 return
1041 }
1042 if apex, ok := mctx.Module().(*apexBundle); ok && apex.Updatable() {
1043 // checking direct deps is sufficient since apex->apk is a direct edge, even when inherited via apex_defaults
1044 mctx.VisitDirectDeps(func(module android.Module) {
1045 // ignore android_test_app
1046 if app, ok := module.(*java.AndroidApp); ok {
1047 app.SetUpdatable(true)
1048 }
1049 })
1050 }
1051}
1052
Spandan Das08c911f2022-01-21 22:07:26 +00001053// TODO: b/215736885 Whittle the denylist
1054// Transitive deps of certain mainline modules baseline NewApi errors
1055// Skip these mainline modules for now
1056var (
1057 skipStrictUpdatabilityLintAllowlist = []string{
1058 "com.android.art",
1059 "com.android.art.debug",
1060 "com.android.conscrypt",
1061 "com.android.media",
1062 // test apexes
1063 "test_com.android.art",
1064 "test_com.android.conscrypt",
1065 "test_com.android.media",
1066 "test_jitzygote_com.android.art",
1067 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001068
1069 // TODO: b/215736885 Remove this list
1070 skipLintJavalibAllowlist = []string{
1071 "conscrypt.module.platform.api.stubs",
1072 "conscrypt.module.public.api.stubs",
1073 "conscrypt.module.public.api.stubs.system",
1074 "conscrypt.module.public.api.stubs.module_lib",
1075 "framework-media.stubs",
1076 "framework-media.stubs.system",
1077 "framework-media.stubs.module_lib",
1078 }
Spandan Das08c911f2022-01-21 22:07:26 +00001079)
1080
1081func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1082 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1083}
1084
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001085// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1086// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1087// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001088func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1089 if !mctx.Module().Enabled() {
1090 return
1091 }
1092 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001093 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1094 }
1095}
1096
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001097// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1098// the apex in order to retrieve its contents later.
1099// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001100func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1101 if !mctx.Module().Enabled() {
1102 return
1103 }
Colin Cross56a83212020-09-15 18:30:11 -07001104 if am, ok := mctx.Module().(android.ApexModule); ok {
1105 if testFor := am.TestFor(); len(testFor) > 0 {
1106 mctx.AddFarVariationDependencies([]blueprint.Variation{
1107 {Mutator: "os", Variation: am.Target().OsVariation()},
1108 {"arch", "common"},
1109 }, testForTag, testFor...)
1110 }
1111 }
1112}
1113
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001114// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001115func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1116 if !mctx.Module().Enabled() {
1117 return
1118 }
Colin Cross56a83212020-09-15 18:30:11 -07001119 if _, ok := mctx.Module().(android.ApexModule); ok {
1120 var contents []*android.ApexContents
1121 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1122 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1123 contents = append(contents, abInfo.Contents)
1124 }
1125 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1126 ApexContents: contents,
1127 })
Colin Crossaede88c2020-08-11 12:17:01 -07001128 }
1129}
1130
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001131// markPlatformAvailability marks whether or not a module can be available to platform. A module
1132// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1133// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1134// be) available to platform
1135// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001136func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1137 // Host and recovery are not considered as platform
1138 if mctx.Host() || mctx.Module().InstallInRecovery() {
1139 return
1140 }
1141
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001142 am, ok := mctx.Module().(android.ApexModule)
1143 if !ok {
1144 return
1145 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001146
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001147 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001148
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001149 // If any of the dep is not available to platform, this module is also considered as being
1150 // not available to platform even if it has "//apex_available:platform"
1151 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001152 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001153 // if the dependency crosses apex boundary, don't consider it
1154 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001155 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001156 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1157 availableToPlatform = false
1158 // TODO(b/154889534) trigger an error when 'am' has
1159 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001160 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001161 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001162
Paul Duffinb5769c12021-05-12 16:16:51 +01001163 // Exception 1: check to see if the module always requires it.
1164 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001165 availableToPlatform = true
1166 }
1167
1168 // Exception 2: bootstrap bionic libraries are also always available to platform
1169 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1170 availableToPlatform = true
1171 }
1172
1173 if !availableToPlatform {
1174 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001175 }
1176}
1177
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001178// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001179// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001180func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001181 if !mctx.Module().Enabled() {
1182 return
1183 }
Colin Cross56a83212020-09-15 18:30:11 -07001184
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001185 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001186 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001187 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001188 return
1189 }
1190
1191 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001192 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1193 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001194 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001195 if strings.HasPrefix(apexBundleName, "com.android.art") {
1196 // Create an alias from the platform variant. This is done to make
1197 // test_for dependencies work for modules that are split by the APEX
1198 // mutator, since test_for dependencies always go to the platform variant.
1199 // This doesn't happen for normal APEXes that are disjunct, so only do
1200 // this for the overlapping ART APEXes.
1201 // TODO(b/183882457): Remove this if the test_for functionality is
1202 // refactored to depend on the proper APEX variants instead of platform.
1203 mctx.CreateAliasVariation("", apexBundleName)
1204 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001205 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1206 apexBundleName := o.GetOverriddenModuleName()
1207 if apexBundleName == "" {
1208 mctx.ModuleErrorf("base property is not set")
1209 return
1210 }
1211 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001212 if strings.HasPrefix(apexBundleName, "com.android.art") {
1213 // TODO(b/183882457): See note for CreateAliasVariation above.
1214 mctx.CreateAliasVariation("", apexBundleName)
1215 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001216 }
1217}
Sundong Ahne9b55722019-09-06 17:37:42 +09001218
Paul Duffin6717d882021-06-15 19:09:41 +01001219// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1220// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001221func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001222 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001223 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001224 return !a.vndkApex
1225 }
1226
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001227 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001228}
1229
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001230// See android.UpdateDirectlyInAnyApex
1231// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001232func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1233 if !mctx.Module().Enabled() {
1234 return
1235 }
1236 if am, ok := mctx.Module().(android.ApexModule); ok {
1237 android.UpdateDirectlyInAnyApex(mctx, am)
1238 }
1239}
1240
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001241// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001242type apexPackaging int
1243
1244const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001245 // imageApex is a packaging method where contents are included in a filesystem image which
1246 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001247 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001248
1249 // zipApex is a packaging method where contents are directly included in the zip container.
1250 // This is used for host-side testing - because the contents are easily accessible by
1251 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001252 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001253
1254 // flattendApex is a packaging method where contents are not included in the APEX file, but
1255 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1256 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001257 flattenedApex
1258)
1259
1260const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001261 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001262 imageApexSuffix = ".apex"
1263 imageCapexSuffix = ".capex"
1264 zipApexSuffix = ".zipapex"
1265 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001266
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001267 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001268 imageApexType = "image"
1269 zipApexType = "zip"
1270 flattenedApexType = "flattened"
1271
Dan Willemsen47e1a752021-10-16 18:36:13 -07001272 ext4FsType = "ext4"
1273 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001274 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001275)
1276
1277// The suffix for the output "file", not the module
1278func (a apexPackaging) suffix() string {
1279 switch a {
1280 case imageApex:
1281 return imageApexSuffix
1282 case zipApex:
1283 return zipApexSuffix
1284 default:
1285 panic(fmt.Errorf("unknown APEX type %d", a))
1286 }
1287}
1288
1289func (a apexPackaging) name() string {
1290 switch a {
1291 case imageApex:
1292 return imageApexType
1293 case zipApex:
1294 return zipApexType
1295 default:
1296 panic(fmt.Errorf("unknown APEX type %d", a))
1297 }
1298}
1299
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001300// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1301// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001302func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001303 if !mctx.Module().Enabled() {
1304 return
1305 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001306 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001307 var variants []string
1308 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1309 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001310 // This is the normal case. Note that both image and flattend APEXes are
1311 // created. The image type is installed to the system partition, while the
1312 // flattened APEX is (optionally) installed to the system_ext partition.
1313 // This is mostly for GSI which has to support wide range of devices. If GSI
1314 // is installed on a newer (APEX-capable) device, the image APEX in the
1315 // system will be used. However, if the same GSI is installed on an old
1316 // device which can't support image APEX, the flattened APEX in the
1317 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001318 variants = append(variants, imageApexType, flattenedApexType)
1319 case "zip":
1320 variants = append(variants, zipApexType)
1321 case "both":
1322 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1323 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001324 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001325 return
1326 }
1327
1328 modules := mctx.CreateLocalVariations(variants...)
1329
1330 for i, v := range variants {
1331 switch v {
1332 case imageApexType:
1333 modules[i].(*apexBundle).properties.ApexType = imageApex
1334 case zipApexType:
1335 modules[i].(*apexBundle).properties.ApexType = zipApex
1336 case flattenedApexType:
1337 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001338 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001339 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001340 modules[i].(*apexBundle).MakeAsSystemExt()
1341 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001342 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001343 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001344 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001345 // payload_type is forcibly overridden to "image"
1346 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001347 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001348 }
1349}
1350
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001351var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001352
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001353// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001354func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1355 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001356 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001357 return true
1358}
1359
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001360var _ android.OutputFileProducer = (*apexBundle)(nil)
1361
1362// Implements android.OutputFileProducer
1363func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1364 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001365 case "", android.DefaultDistTag:
1366 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001367 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001368 case imageApexSuffix:
1369 // uncompressed one
1370 if a.outputApexFile != nil {
1371 return android.Paths{a.outputApexFile}, nil
1372 }
1373 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001374 default:
1375 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1376 }
1377}
1378
1379var _ cc.Coverage = (*apexBundle)(nil)
1380
1381// Implements cc.Coverage
1382func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1383 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1384}
1385
1386// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001387func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001388 a.properties.PreventInstall = true
1389}
1390
1391// Implements cc.Coverage
1392func (a *apexBundle) HideFromMake() {
1393 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001394 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1395 // TODO(ccross): untangle these
1396 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397}
1398
1399// Implements cc.Coverage
1400func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1401 a.properties.IsCoverageVariant = coverage
1402}
1403
1404// Implements cc.Coverage
1405func (a *apexBundle) EnableCoverageIfNeeded() {}
1406
1407var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1408
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001409// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001410func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001411 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001412}
1413
Jiyong Parkf4020582021-11-29 12:37:10 +09001414func (a *apexBundle) FutureUpdatable() bool {
1415 return proptools.BoolDefault(a.properties.Future_updatable, false)
1416}
1417
Jiyong Park1bc84122021-06-22 20:23:05 +09001418func (a *apexBundle) UsePlatformApis() bool {
1419 return proptools.BoolDefault(a.properties.Platform_apis, false)
1420}
1421
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001422// getCertString returns the name of the cert that should be used to sign this APEX. This is
1423// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001424func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001425 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001426 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1427 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1428 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001429 if a.vndkApex {
1430 moduleName = vndkApexName
1431 }
1432 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001433 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001434 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001435 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001436 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001437}
1438
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001439// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001440func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001441 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001442}
1443
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001444// See the generate_hashtree property
1445func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001446 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001447}
1448
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001449// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001450func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1451 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1452}
1453
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001454// See the test_only_force_compression property
1455func (a *apexBundle) testOnlyShouldForceCompression() bool {
1456 return proptools.Bool(a.properties.Test_only_force_compression)
1457}
1458
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001459// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1460// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1461// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001462
Jiyong Parkf97782b2019-02-13 20:28:58 +09001463func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1464 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1465 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1466 }
1467}
1468
Jiyong Park388ef3f2019-01-28 19:47:32 +09001469func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001470 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1471 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001472 }
1473
1474 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001475 globalSanitizerNames := []string{}
1476 if a.Host() {
1477 globalSanitizerNames = ctx.Config().SanitizeHost()
1478 } else {
1479 arches := ctx.Config().SanitizeDeviceArch()
1480 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1481 globalSanitizerNames = ctx.Config().SanitizeDevice()
1482 }
1483 }
1484 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001485}
1486
Jooyung Han8ce8db92020-05-15 19:05:05 +09001487func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001488 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1489 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001490 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001491 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001492 for _, target := range ctx.MultiTargets() {
1493 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001494 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Cross4c4c1be2022-02-10 11:41:18 -08001495 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001496 Tests: nil,
1497 Jni_libs: nil,
1498 Binaries: nil,
1499 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001500 break
1501 }
1502 }
1503 }
1504}
1505
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001506// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1507// returned apexFile saves information about the Soong module that will be used for creating the
1508// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001509func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001510 // Decide the APEX-local directory by the multilib of the library In the future, we may
1511 // query this to the module.
1512 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001513 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001514 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001515 case "lib32":
1516 dirInApex = "lib"
1517 case "lib64":
1518 dirInApex = "lib64"
1519 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001520 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001521 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001522 }
Jooyung Han35155c42020-02-06 17:33:20 +09001523 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001524 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001525 // Special case for Bionic libs and other libs installed with them. This is to
1526 // prevent those libs from being included in the search path
1527 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1528 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1529 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1530 // will be loaded into the default linker namespace (aka "platform" namespace). If
1531 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1532 // be loaded again into the runtime linker namespace, which will result in double
1533 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001534 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001535 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001536
Jiyong Parkf653b052019-11-18 15:39:01 +09001537 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001538 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1539 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001540}
1541
Jiyong Park1833cef2019-12-13 13:28:36 +09001542func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001543 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001544 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001545 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001546 }
Jooyung Han35155c42020-02-06 17:33:20 +09001547 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001548 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001549 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1550 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001551 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001552 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001553 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001554}
1555
Jiyong Park99644e92020-11-17 22:21:02 +09001556func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1557 dirInApex := "bin"
1558 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1559 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1560 }
1561 fileToCopy := rustm.OutputFile().Path()
1562 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1563 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1564 return af
1565}
1566
1567func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1568 // Decide the APEX-local directory by the multilib of the library
1569 // In the future, we may query this to the module.
1570 var dirInApex string
1571 switch rustm.Arch().ArchType.Multilib {
1572 case "lib32":
1573 dirInApex = "lib"
1574 case "lib64":
1575 dirInApex = "lib64"
1576 }
1577 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1578 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1579 }
1580 fileToCopy := rustm.OutputFile().Path()
1581 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1582 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1583}
1584
Jiyong Park1833cef2019-12-13 13:28:36 +09001585func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001586 dirInApex := "bin"
1587 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001588 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001589}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001590
Jiyong Park1833cef2019-12-13 13:28:36 +09001591func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001592 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001593 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001594 // NB: Since go binaries are static we don't need the module for anything here, which is
1595 // good since the go tool is a blueprint.Module not an android.Module like we would
1596 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001597 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001598}
1599
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001600func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001601 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001602 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1603 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1604 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001605 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001606 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001607 af.symlinks = sh.Symlinks()
1608 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001609}
1610
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001611func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001612 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001613 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001614 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001615}
1616
atrost6e126252020-01-27 17:01:16 +00001617func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1618 dirInApex := filepath.Join("etc", config.SubDir())
1619 fileToCopy := config.CompatConfig()
1620 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1621}
1622
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001623// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1624// way.
1625type javaModule interface {
1626 android.Module
1627 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001628 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001629 JacocoReportClassesFile() android.Path
1630 LintDepSets() java.LintDepSets
1631 Stem() string
1632}
1633
1634var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001635var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001636var _ javaModule = (*java.SdkLibrary)(nil)
1637var _ javaModule = (*java.DexImport)(nil)
1638var _ javaModule = (*java.SdkLibraryImport)(nil)
1639
Paul Duffin190fdef2021-04-26 10:33:59 +01001640// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001641func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001642 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001643}
1644
1645// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1646func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001647 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001648 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001649 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1650 af.lintDepSets = module.LintDepSets()
1651 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001652 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1653 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1654 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1655 }
1656 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001657 return af
1658}
1659
1660// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1661// the same way.
1662type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 android.Module
1664 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001665 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001667 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001668 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001669 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001670 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001671}
1672
1673var _ androidApp = (*java.AndroidApp)(nil)
1674var _ androidApp = (*java.AndroidAppImport)(nil)
1675
1676func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001677 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001679 appDir = "priv-app"
1680 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001681 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001682 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001683 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001684 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001685 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001686 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001687
1688 if app, ok := aapp.(interface {
1689 OverriddenManifestPackageName() string
1690 }); ok {
1691 af.overriddenPackageName = app.OverriddenManifestPackageName()
1692 }
Jiyong Park618922e2020-01-08 13:35:43 +09001693 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001694}
1695
Jiyong Park69aeba92020-04-24 21:16:36 +09001696func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1697 rroDir := "overlay"
1698 dirInApex := filepath.Join(rroDir, rro.Theme())
1699 fileToCopy := rro.OutputFile()
1700 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1701 af.certificate = rro.Certificate()
1702
1703 if a, ok := rro.(interface {
1704 OverriddenManifestPackageName() string
1705 }); ok {
1706 af.overriddenPackageName = a.OverriddenManifestPackageName()
1707 }
1708 return af
1709}
1710
Ken Chenfad7f9d2021-11-10 22:02:57 +08001711func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1712 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001713 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1714}
1715
Jiyong Park12a719c2021-01-07 15:31:24 +09001716func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1717 dirInApex := filepath.Join("etc", "fs")
1718 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1719}
1720
Paul Duffin064b70c2020-11-02 17:32:38 +00001721// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001722// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1723// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1724// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001725func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001726 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001727 am, ok := child.(android.ApexModule)
1728 if !ok || !am.CanHaveApexVariants() {
1729 return false
1730 }
1731
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001732 // Filter-out unwanted depedendencies
1733 depTag := ctx.OtherModuleDependencyTag(child)
1734 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1735 return false
1736 }
1737 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001738 return false
1739 }
1740
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001741 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001742 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001743
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001744 // Visit actually
1745 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001746 })
1747}
1748
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001749// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1750type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001751
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001752const (
1753 ext4 fsType = iota
1754 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001755 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001756)
Artur Satayev849f8442020-04-28 14:57:42 +01001757
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001758func (f fsType) string() string {
1759 switch f {
1760 case ext4:
1761 return ext4FsType
1762 case f2fs:
1763 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001764 case erofs:
1765 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001766 default:
1767 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001768 }
1769}
1770
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001771// Creates build rules for an APEX. It consists of the following major steps:
1772//
1773// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1774// 2) traverse the dependency tree to collect apexFile structs from them.
1775// 3) some fields in apexBundle struct are configured
1776// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001777func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001778 ////////////////////////////////////////////////////////////////////////////////////////////
1779 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001780 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001781 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001782 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001783 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001784 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001785 if len(a.properties.Tests) > 0 && !a.testApex {
1786 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1787 return
1788 }
Jiyong Park678c8812020-02-07 17:25:49 +09001789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001790 ////////////////////////////////////////////////////////////////////////////////////////////
1791 // 2) traverse the dependency tree to collect apexFile structs from them.
1792
1793 // all the files that will be included in this APEX
1794 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001795
Jooyung Hane1633032019-08-01 17:41:43 +09001796 // native lib dependencies
1797 var provideNativeLibs []string
1798 var requireNativeLibs []string
1799
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001800 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1801
braleeb0c1f0c2021-06-07 22:49:13 +08001802 // Collect the module directory for IDE info in java/jdeps.go.
1803 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1804
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001805 // TODO(jiyong): do this using WalkPayloadDeps
1806 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001807 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001808 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001809 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1810 return false
1811 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001812 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1813 return false
1814 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001815 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001816 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001817 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001818 case sharedLibTag, jniLibTag:
1819 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001820 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001821 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1822 fi.isJniLib = isJniLib
1823 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001824 // Collect the list of stub-providing libs except:
1825 // - VNDK libs are only for vendors
1826 // - bootstrap bionic libs are treated as provided by system
1827 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001828 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001829 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001830 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001831 } else if r, ok := child.(*rust.Module); ok {
1832 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001833 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001834 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001835 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001836 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001837 propertyName := "native_shared_libs"
1838 if isJniLib {
1839 propertyName = "jni_libs"
1840 }
1841 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001842 }
1843 case executableTag:
1844 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001845 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001847 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001848 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001849 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001850 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001851 } else if rust, ok := child.(*rust.Module); ok {
1852 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1853 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001854 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001855 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1856 }
1857 case shBinaryTag:
1858 if sh, ok := child.(*sh.ShBinary); ok {
1859 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1860 } else {
1861 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001862 }
Paul Duffin94f19632021-04-20 12:40:07 +01001863 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001864 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001865 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1866 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001867 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001868 return false
1869 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001870
Paul Duffincc33ec82021-04-25 23:14:55 +01001871 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1872 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001873 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1874 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1875 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001876 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001877 }
satayev333a1732021-05-17 21:35:26 +01001878 case sscpfTag:
1879 {
1880 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1881 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1882 return false
1883 }
satayevb98371c2021-06-15 16:49:50 +01001884 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1885 filesInfo = append(filesInfo, *af)
1886 }
satayev333a1732021-05-17 21:35:26 +01001887 return true
1888 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001889 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001890 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001891 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001892 af := apexFileForJavaModule(ctx, child.(javaModule))
1893 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001894 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1895 return false
1896 }
1897 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001898 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001899 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001900 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001901 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001902 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001904 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001905 return true // track transitive dependencies
1906 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001907 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001908 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001909 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001910 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1911 appDir := "app"
1912 if ap.Privileged() {
1913 appDir = "priv-app"
1914 }
Yo Chiange8128052020-07-23 20:09:18 +08001915 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001916 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1917 af.certificate = java.PresignedCertificate
1918 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001919 } else {
1920 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1921 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001922 case rroTag:
1923 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1924 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1925 } else {
1926 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1927 }
markchien2f59ec92020-09-02 16:23:38 +08001928 case bpfTag:
1929 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1930 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001931 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001932 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001933 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001934 }
1935 } else {
1936 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1937 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001938 case fsTag:
1939 if fs, ok := child.(filesystem.Filesystem); ok {
1940 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1941 } else {
1942 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1943 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001944 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001945 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001946 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001947 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001948 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001949 }
Paul Duffin0b817782021-03-17 15:02:19 +00001950 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001951 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1952 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1953 } else {
1954 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1955 }
Roland Levillain630846d2019-06-26 12:48:34 +01001956 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001957 if ccTest, ok := child.(*cc.Module); ok {
1958 if ccTest.IsTestPerSrcAllTestsVariation() {
1959 // Multiple-output test module (where `test_per_src: true`).
1960 //
1961 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1962 // We do not add this variation to `filesInfo`, as it has no output;
1963 // however, we do add the other variations of this module as indirect
1964 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001965 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001966 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001967 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001968 af.class = nativeTest
1969 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001970 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001971 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001972 } else {
1973 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1974 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001975 case keyTag:
1976 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001977 a.privateKeyFile = key.privateKeyFile
1978 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001979 } else {
1980 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001981 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001982 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001983 case certificateTag:
1984 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001985 a.containerCertificateFile = dep.Certificate.Pem
1986 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001987 } else {
1988 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1989 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001990 case android.PrebuiltDepTag:
1991 // If the prebuilt is force disabled, remember to delete the prebuilt file
1992 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001993 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001994 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1995 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001996 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001997 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001998 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001999 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002000 // We cannot use a switch statement on `depTag` here as the checked
2001 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002002 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002003 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09002004 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002005 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002006 return false
2007 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002008 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2009 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002010
2011 // Always track transitive dependencies for host.
2012 if a.Host() {
2013 filesInfo = append(filesInfo, af)
2014 return true
2015 }
2016
Colin Cross56a83212020-09-15 18:30:11 -07002017 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002018 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002019 // If the dependency is a stubs lib, don't include it in this APEX,
2020 // but make sure that the lib is installed on the device.
2021 // In case no APEX is having the lib, the lib is installed to the system
2022 // partition.
2023 //
2024 // Always include if we are a host-apex however since those won't have any
2025 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002026 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002027 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00002028 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002029 if !android.InList(name, a.requiredDeps) {
2030 a.requiredDeps = append(a.requiredDeps, name)
2031 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002032 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002033 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002034 // Don't track further
2035 return false
2036 }
Jiyong Parke3867542020-12-03 17:28:25 +09002037
2038 // If the dep is not considered to be in the same
2039 // apex, don't add it to filesInfo so that it is not
2040 // included in this APEX.
2041 // TODO(jiyong): move this to at the top of the
2042 // else-if clause for the indirect dependencies.
2043 // Currently, that's impossible because we would
2044 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002045 // DepIsInSameAPex is false. We also shouldn't do
2046 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002047 //
2048 // TODO(jiyong): explain why the same module is passed in twice.
2049 // Switching the first am to parent breaks lots of tests.
2050 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002051 return false
2052 }
2053
Jiyong Parkf653b052019-11-18 15:39:01 +09002054 filesInfo = append(filesInfo, af)
2055 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002056 } else if rm, ok := child.(*rust.Module); ok {
2057 af := apexFileForRustLibrary(ctx, rm)
2058 af.transitiveDep = true
2059 filesInfo = append(filesInfo, af)
2060 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002061 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002062 } else if cc.IsTestPerSrcDepTag(depTag) {
2063 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002064 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002065 // Handle modules created as `test_per_src` variations of a single test module:
2066 // use the name of the generated test binary (`fileToCopy`) instead of the name
2067 // of the original test module (`depName`, shared by all `test_per_src`
2068 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002069 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002070 // these are not considered transitive dep
2071 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002072 filesInfo = append(filesInfo, af)
2073 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002074 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002075 } else if cc.IsHeaderDepTag(depTag) {
2076 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002077 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002078 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2079 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002080 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002081 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002082 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2083 }
Jiyong Park99644e92020-11-17 22:21:02 +09002084 } else if rust.IsDylibDepTag(depTag) {
2085 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2086 af := apexFileForRustLibrary(ctx, rustm)
2087 af.transitiveDep = true
2088 filesInfo = append(filesInfo, af)
2089 return true // track transitive dependencies
2090 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002091 } else if rust.IsRlibDepTag(depTag) {
2092 // Rlib is statically linked, but it might have shared lib
2093 // dependencies. Track them.
2094 return true
Paul Duffin65898052021-04-20 22:47:03 +01002095 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002096 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002097 switch child.(type) {
2098 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002099 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002100 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002101 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002102 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002103 return false
2104 }
2105 filesInfo = append(filesInfo, af)
2106 return true // track transitive dependencies
2107 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002108 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 +00002109 }
satayev333a1732021-05-17 21:35:26 +01002110 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2111 // Add the contents of the systemserverclasspath fragment to the apex.
2112 switch child.(type) {
2113 case *java.Library, *java.SdkLibrary:
2114 af := apexFileForJavaModule(ctx, child.(javaModule))
2115 filesInfo = append(filesInfo, af)
2116 return true // track transitive dependencies
2117 default:
2118 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2119 }
Colin Cross56a83212020-09-15 18:30:11 -07002120 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2121 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002122 } else if depTag == android.DarwinUniversalVariantTag {
2123 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002124 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002125 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002126 }
2127 }
2128 }
2129 return false
2130 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002131 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002132 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002133 return
2134 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002135
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002136 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002137 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002138 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002139 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002140 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002141 if e, ok := encountered[dest]; !ok {
2142 encountered[dest] = f
2143 } else {
2144 // If a module is directly included and also transitively depended on
2145 // consider it as directly included.
2146 e.transitiveDep = e.transitiveDep && f.transitiveDep
2147 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002148 }
2149 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002150 var result []apexFile
2151 for _, v := range encountered {
2152 result = append(result, v)
2153 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002154 return result
2155 }
2156 filesInfo = removeDup(filesInfo)
2157
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002158 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002159 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002160 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2161 // changes.
2162 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002163 })
2164
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002165 ////////////////////////////////////////////////////////////////////////////////////////////
2166 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002167 a.installDir = android.PathForModuleInstall(ctx, "apex")
2168 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002170 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002171 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002172 switch a.properties.ApexType {
2173 case imageApex:
2174 if buildFlattenedAsDefault {
2175 a.suffix = imageApexSuffix
2176 } else {
2177 a.suffix = ""
2178 a.primaryApexType = true
2179
2180 if ctx.Config().InstallExtraFlattenedApexes() {
2181 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2182 }
2183 }
2184 case zipApex:
2185 if proptools.String(a.properties.Payload_type) == "zip" {
2186 a.suffix = ""
2187 a.primaryApexType = true
2188 } else {
2189 a.suffix = zipApexSuffix
2190 }
2191 case flattenedApex:
2192 if buildFlattenedAsDefault {
2193 a.suffix = ""
2194 a.primaryApexType = true
2195 } else {
2196 a.suffix = flattenedSuffix
2197 }
2198 }
2199
Theotime Combes4ba38c12020-06-12 12:46:59 +00002200 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2201 case ext4FsType:
2202 a.payloadFsType = ext4
2203 case f2fsFsType:
2204 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002205 case erofsFsType:
2206 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002207 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002208 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 +00002209 }
2210
Jiyong Park7cd10e32020-01-14 09:22:18 +09002211 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2212 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2213 // the same library in the system partition, thus effectively sharing the same libraries
2214 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2215 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002216 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002217
Jooyung Han85d61762020-06-24 23:50:26 +09002218 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2219 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002220 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002221 a.linkToSystemLib = false
2222 }
2223
Jiyong Park4da07972021-01-05 21:01:11 +09002224 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002225 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002226
Jiyong Park9d677202020-02-19 16:29:35 +09002227 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002228 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002229 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002230 a.linkToSystemLib = false
2231 }
2232
Jiyong Park638d30e2020-02-26 18:27:19 +09002233 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2234 if ctx.Host() {
2235 a.linkToSystemLib = false
2236 }
2237
Colin Cross6340ea52021-11-04 12:01:18 -07002238 if a.properties.ApexType != zipApex {
2239 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2240 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002241
2242 ////////////////////////////////////////////////////////////////////////////////////////////
2243 // 4) generate the build rules to create the APEX. This is done in builder.go.
2244 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002245 if a.properties.ApexType == flattenedApex {
2246 a.buildFlattenedApex(ctx)
2247 } else {
2248 a.buildUnflattenedApex(ctx)
2249 }
Jiyong Park956305c2020-01-09 12:32:06 +09002250 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002251 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002252
2253 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2254 if a.installable() {
2255 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2256 // along with other ordinary files. (Note that this is done by apexer for
2257 // non-flattened APEXes)
2258 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2259
2260 // Place the public key as apex_pubkey. This is also done by apexer for
2261 // non-flattened APEXes case.
2262 // TODO(jiyong): Why do we need this CP rule?
2263 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2264 ctx.Build(pctx, android.BuildParams{
2265 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002266 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002267 Output: copiedPubkey,
2268 })
2269 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2270 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002271}
2272
Paul Duffincc33ec82021-04-25 23:14:55 +01002273// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2274// the bootclasspath_fragment contributes to the apex.
2275func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2276 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2277 var filesToAdd []apexFile
2278
2279 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002280 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2281 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2282 dirInApex := filepath.Join("javalib", arch.String())
2283 for _, f := range files {
2284 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2285 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2286 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2287 filesToAdd = append(filesToAdd, af)
2288 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002289 }
2290 }
2291
satayev3db35472021-05-06 23:59:58 +01002292 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002293 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2294 filesToAdd = append(filesToAdd, *af)
2295 }
satayev3db35472021-05-06 23:59:58 +01002296
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002297 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2298 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2299 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2300
2301 if pathOnHost != nil {
2302 // We need to copy the profile to a temporary path with the right filename because the apexer
2303 // will take the filename as is.
2304 ctx.Build(pctx, android.BuildParams{
2305 Rule: android.Cp,
2306 Input: pathOnHost,
2307 Output: tempPath,
2308 })
2309 } else {
2310 // At this point, the boot image profile cannot be generated. It is probably because the boot
2311 // image profile source file does not exist on the branch, or it is not available for the
2312 // current build target.
2313 // However, we cannot enforce the boot image profile to be generated because some build
2314 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2315 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2316 // only if the APEX is being built.
2317 ctx.Build(pctx, android.BuildParams{
2318 Rule: android.ErrorRule,
2319 Output: tempPath,
2320 Args: map[string]string{
2321 "error": "Boot image profile cannot be generated",
2322 },
2323 })
2324 }
2325
2326 androidMkModuleName := filepath.Base(pathInApex)
2327 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2328 filesToAdd = append(filesToAdd, af)
2329 }
2330
Paul Duffincc33ec82021-04-25 23:14:55 +01002331 return filesToAdd
2332}
2333
satayevb98371c2021-06-15 16:49:50 +01002334// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2335// the module contributes to the apex; or nil if the proto config was not generated.
2336func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2337 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2338 if !info.ClasspathFragmentProtoGenerated {
2339 return nil
2340 }
2341 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2342 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2343 return &af
satayev14e49132021-05-17 21:03:07 +01002344}
2345
Paul Duffincc33ec82021-04-25 23:14:55 +01002346// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2347// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002348func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2349 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2350
2351 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2352 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002353 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2354 if err != nil {
2355 ctx.ModuleErrorf("%s", err)
2356 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002357
2358 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2359 // bootclasspath_fragment.
2360 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2361 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002362}
2363
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002364///////////////////////////////////////////////////////////////////////////////////////////////////
2365// Factory functions
2366//
2367
2368func newApexBundle() *apexBundle {
2369 module := &apexBundle{}
2370
2371 module.AddProperties(&module.properties)
2372 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002373 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002374 module.AddProperties(&module.overridableProperties)
2375
2376 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2377 android.InitDefaultableModule(module)
2378 android.InitSdkAwareModule(module)
2379 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002380 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002381 return module
2382}
2383
Paul Duffineb8051d2021-10-18 17:49:39 +01002384func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002385 bundle := newApexBundle()
2386 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002387 return bundle
2388}
2389
2390// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2391// certain compatibility checks such as apex_available are not done for apex_test.
2392func testApexBundleFactory() android.Module {
2393 bundle := newApexBundle()
2394 bundle.testApex = true
2395 return bundle
2396}
2397
2398// apex packages other modules into an APEX file which is a packaging format for system-level
2399// components like binaries, shared libraries, etc.
2400func BundleFactory() android.Module {
2401 return newApexBundle()
2402}
2403
2404type Defaults struct {
2405 android.ModuleBase
2406 android.DefaultsModuleBase
2407}
2408
2409// apex_defaults provides defaultable properties to other apex modules.
2410func defaultsFactory() android.Module {
2411 return DefaultsFactory()
2412}
2413
2414func DefaultsFactory(props ...interface{}) android.Module {
2415 module := &Defaults{}
2416
2417 module.AddProperties(props...)
2418 module.AddProperties(
2419 &apexBundleProperties{},
2420 &apexTargetBundleProperties{},
2421 &overridableProperties{},
2422 )
2423
2424 android.InitDefaultsModule(module)
2425 return module
2426}
2427
2428type OverrideApex struct {
2429 android.ModuleBase
2430 android.OverrideModuleBase
2431}
2432
2433func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2434 // All the overrides happen in the base module.
2435}
2436
2437// override_apex is used to create an apex module based on another apex module by overriding some of
2438// its properties.
2439func overrideApexFactory() android.Module {
2440 m := &OverrideApex{}
2441
2442 m.AddProperties(&overridableProperties{})
2443
2444 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2445 android.InitOverrideModule(m)
2446 return m
2447}
2448
2449///////////////////////////////////////////////////////////////////////////////////////////////////
2450// Vality check routines
2451//
2452// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2453// certain conditions are not met.
2454//
2455// TODO(jiyong): move these checks to a separate go file.
2456
satayevad991492021-12-03 18:58:32 +00002457var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2458
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002459// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2460// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002461func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002462 if a.testApex || a.vndkApex {
2463 return
2464 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002465 // apexBundle::minSdkVersion reports its own errors.
2466 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002467 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002468}
2469
Albert Martineefabcf2022-03-21 20:11:16 +00002470// Returns apex's min_sdk_version string value, honoring overrides
2471func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
2472 // Only override the minSdkVersion value on Apexes which already specify
2473 // a min_sdk_version (it's optional for non-updatable apexes), and that its
2474 // min_sdk_version value is lower than the one to override with.
2475 overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride()
2476 overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue)
2477 originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
2478 isMinSdkSet := a.properties.Min_sdk_version != nil
2479 isOverrideValueHigher := overrideApiLevel.CompareTo(originalMinApiLevel) > 0
2480 if overrideMinSdkValue != "" && isMinSdkSet && isOverrideValueHigher {
2481 return overrideMinSdkValue
2482 }
2483
2484 return proptools.String(a.properties.Min_sdk_version)
2485}
2486
2487// Returns apex's min_sdk_version SdkSpec, honoring overrides
satayevad991492021-12-03 18:58:32 +00002488func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2489 return android.SdkSpec{
2490 Kind: android.SdkNone,
2491 ApiLevel: a.minSdkVersion(ctx),
Albert Martineefabcf2022-03-21 20:11:16 +00002492 Raw: a.minSdkVersionValue(ctx),
satayevad991492021-12-03 18:58:32 +00002493 }
2494}
2495
Albert Martineefabcf2022-03-21 20:11:16 +00002496// Returns apex's min_sdk_version ApiLevel, honoring overrides
satayevad991492021-12-03 18:58:32 +00002497func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Albert Martineefabcf2022-03-21 20:11:16 +00002498 return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx))
2499}
2500
2501// Construct ApiLevel object from min_sdk_version string value
2502func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel {
2503 if value == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002504 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002505 }
Albert Martineefabcf2022-03-21 20:11:16 +00002506 apiLevel, err := android.ApiLevelFromUser(ctx, value)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002507 if err != nil {
2508 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2509 return android.NoneApiLevel
2510 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002511 return apiLevel
2512}
2513
2514// Ensures that a lib providing stub isn't statically linked
2515func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2516 // Practically, we only care about regular APEXes on the device.
2517 if ctx.Host() || a.testApex || a.vndkApex {
2518 return
2519 }
2520
2521 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2522
2523 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2524 if ccm, ok := to.(*cc.Module); ok {
2525 apexName := ctx.ModuleName()
2526 fromName := ctx.OtherModuleName(from)
2527 toName := ctx.OtherModuleName(to)
2528
2529 // If `to` is not actually in the same APEX as `from` then it does not need
2530 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002531 //
2532 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002533 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2534 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2535 return false
2536 }
2537
2538 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2539 // exception to this rule. It can't make the static dependencies dynamic
2540 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002541 // Same rule should be applied to linkerconfig, because it should be executed
2542 // only with static linked libraries before linker is available with ld.config.txt
2543 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002544 return false
2545 }
2546
2547 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2548 if isStubLibraryFromOtherApex && !externalDep {
2549 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2550 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2551 }
2552
2553 }
2554 return true
2555 })
2556}
2557
satayevb98371c2021-06-15 16:49:50 +01002558// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002559func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2560 if a.Updatable() {
Albert Martineefabcf2022-03-21 20:11:16 +00002561 if a.minSdkVersionValue(ctx) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002562 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2563 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002564 if a.UsePlatformApis() {
2565 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2566 }
Daniel Norman69109112021-12-02 12:52:42 -08002567 if a.SocSpecific() || a.DeviceSpecific() {
2568 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2569 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002570 if a.FutureUpdatable() {
2571 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2572 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002573 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002574 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002575 }
2576}
2577
satayevb98371c2021-06-15 16:49:50 +01002578// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2579func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2580 ctx.VisitDirectDeps(func(module android.Module) {
2581 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2582 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2583 if !info.ClasspathFragmentProtoGenerated {
2584 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2585 }
2586 }
2587 })
2588}
2589
2590// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002591func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002592 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2593 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002594 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2595 tag := ctx.OtherModuleDependencyTag(module)
2596 switch tag {
2597 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002598 if m, ok := module.(interface {
2599 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2600 }); ok {
2601 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002602 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2603 }
2604 }
2605 }
2606 })
2607}
2608
satayevb98371c2021-06-15 16:49:50 +01002609// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002610func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2611 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2612 if ctx.Host() || a.testApex || a.vndkApex {
2613 return
2614 }
2615
2616 // Because APEXes targeting other than system/system_ext partitions can't set
2617 // apex_available, we skip checks for these APEXes
2618 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2619 return
2620 }
2621
2622 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2623 // Requiring them and their transitive depencies with apex_available is not right
2624 // because they just add noise.
2625 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2626 return
2627 }
2628
2629 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2630 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2631 if externalDep {
2632 return false
2633 }
2634
2635 apexName := ctx.ModuleName()
2636 fromName := ctx.OtherModuleName(from)
2637 toName := ctx.OtherModuleName(to)
2638
2639 // If `to` is not actually in the same APEX as `from` then it does not need
2640 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002641 //
2642 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002643 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2644 // As soon as the dependency graph crosses the APEX boundary, don't go
2645 // further.
2646 return false
2647 }
2648
2649 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2650 return true
2651 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002652 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2653 "\n\nDependency path:%s\n\n"+
2654 "Consider adding %q to 'apex_available' property of %q",
2655 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002656 // Visit this module's dependencies to check and report any issues with their availability.
2657 return true
2658 })
2659}
2660
Jiyong Park192600a2021-08-03 07:52:17 +00002661// checkStaticExecutable ensures that executables in an APEX are not static.
2662func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002663 // No need to run this for host APEXes
2664 if ctx.Host() {
2665 return
2666 }
2667
Jiyong Park192600a2021-08-03 07:52:17 +00002668 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2669 if ctx.OtherModuleDependencyTag(module) != executableTag {
2670 return
2671 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002672
2673 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002674 apex := a.ApexVariationName()
2675 exec := ctx.OtherModuleName(module)
2676 if isStaticExecutableAllowed(apex, exec) {
2677 return
2678 }
2679 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2680 }
2681 })
2682}
2683
2684// A small list of exceptions where static executables are allowed in APEXes.
2685func isStaticExecutableAllowed(apex string, exec string) bool {
2686 m := map[string][]string{
2687 "com.android.runtime": []string{
2688 "linker",
2689 "linkerconfig",
2690 },
2691 }
2692 execNames, ok := m[apex]
2693 return ok && android.InList(exec, execNames)
2694}
2695
braleeb0c1f0c2021-06-07 22:49:13 +08002696// Collect information for opening IDE project files in java/jdeps.go.
2697func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Remi NGUYEN VANbe901722022-03-02 21:00:33 +09002698 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
2699 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
2700 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002701 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2702}
2703
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002704var (
2705 apexAvailBaseline = makeApexAvailableBaseline()
2706 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2707)
2708
Colin Cross440e0d02020-06-11 11:32:11 -07002709func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002710 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002711 moduleName = normalizeModuleName(moduleName)
2712
Colin Cross440e0d02020-06-11 11:32:11 -07002713 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002714 return true
2715 }
2716
2717 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002718 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002719 return true
2720 }
2721
2722 return false
2723}
2724
2725func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002726 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2727 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002728 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002729 if strings.HasPrefix(moduleName, "libclang_rt.") {
2730 // This module has many arch variants that depend on the product being built.
2731 // We don't want to list them all
2732 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002733 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002734 if strings.HasPrefix(moduleName, "androidx.") {
2735 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2736 moduleName = "androidx"
2737 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002738 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002739}
2740
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002741// Transform the map of apex -> modules to module -> apexes.
2742func invertApexBaseline(m map[string][]string) map[string][]string {
2743 r := make(map[string][]string)
2744 for apex, modules := range m {
2745 for _, module := range modules {
2746 r[module] = append(r[module], apex)
2747 }
2748 }
2749 return r
2750}
2751
2752// Retrieve the baseline of apexes to which the supplied module belongs.
2753func BaselineApexAvailable(moduleName string) []string {
2754 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2755}
2756
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002757// This is a map from apex to modules, which overrides the apex_available setting for that
2758// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002759// TODO(b/147364041): remove this
2760func makeApexAvailableBaseline() map[string][]string {
2761 // The "Module separator"s below are employed to minimize merge conflicts.
2762 m := make(map[string][]string)
2763 //
2764 // Module separator
2765 //
2766 m["com.android.appsearch"] = []string{
2767 "icing-java-proto-lite",
2768 "libprotobuf-java-lite",
2769 }
2770 //
2771 // Module separator
2772 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002773 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002774 "android.hardware.audio.common@5.0",
2775 "android.hardware.bluetooth.a2dp@1.0",
2776 "android.hardware.bluetooth.audio@2.0",
2777 "android.hardware.bluetooth@1.0",
2778 "android.hardware.bluetooth@1.1",
2779 "android.hardware.graphics.bufferqueue@1.0",
2780 "android.hardware.graphics.bufferqueue@2.0",
2781 "android.hardware.graphics.common@1.0",
2782 "android.hardware.graphics.common@1.1",
2783 "android.hardware.graphics.common@1.2",
2784 "android.hardware.media@1.0",
2785 "android.hidl.safe_union@1.0",
2786 "android.hidl.token@1.0",
2787 "android.hidl.token@1.0-utils",
2788 "avrcp-target-service",
2789 "avrcp_headers",
2790 "bluetooth-protos-lite",
2791 "bluetooth.mapsapi",
2792 "com.android.vcard",
2793 "dnsresolver_aidl_interface-V2-java",
2794 "ipmemorystore-aidl-interfaces-V5-java",
2795 "ipmemorystore-aidl-interfaces-java",
2796 "internal_include_headers",
2797 "lib-bt-packets",
2798 "lib-bt-packets-avrcp",
2799 "lib-bt-packets-base",
2800 "libFraunhoferAAC",
2801 "libaudio-a2dp-hw-utils",
2802 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002803 "libbluetooth",
2804 "libbluetooth-types",
2805 "libbluetooth-types-header",
2806 "libbluetooth_gd",
2807 "libbluetooth_headers",
2808 "libbluetooth_jni",
2809 "libbt-audio-hal-interface",
2810 "libbt-bta",
2811 "libbt-common",
2812 "libbt-hci",
2813 "libbt-platform-protos-lite",
2814 "libbt-protos-lite",
2815 "libbt-sbc-decoder",
2816 "libbt-sbc-encoder",
2817 "libbt-stack",
2818 "libbt-utils",
2819 "libbtcore",
2820 "libbtdevice",
2821 "libbte",
2822 "libbtif",
2823 "libchrome",
2824 "libevent",
2825 "libfmq",
2826 "libg722codec",
2827 "libgui_headers",
2828 "libmedia_headers",
2829 "libmodpb64",
2830 "libosi",
2831 "libstagefright_foundation_headers",
2832 "libstagefright_headers",
2833 "libstatslog",
2834 "libstatssocket",
2835 "libtinyxml2",
2836 "libudrv-uipc",
2837 "libz",
2838 "media_plugin_headers",
2839 "net-utils-services-common",
2840 "netd_aidl_interface-unstable-java",
2841 "netd_event_listener_interface-java",
2842 "netlink-client",
2843 "networkstack-client",
2844 "sap-api-java-static",
2845 "services.net",
2846 }
2847 //
2848 // Module separator
2849 //
2850 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2851 //
2852 // Module separator
2853 //
2854 m["com.android.extservices"] = []string{
2855 "error_prone_annotations",
2856 "ExtServices-core",
2857 "ExtServices",
2858 "libtextclassifier-java",
2859 "libz_current",
2860 "textclassifier-statsd",
2861 "TextClassifierNotificationLibNoManifest",
2862 "TextClassifierServiceLibNoManifest",
2863 }
2864 //
2865 // Module separator
2866 //
2867 m["com.android.neuralnetworks"] = []string{
2868 "android.hardware.neuralnetworks@1.0",
2869 "android.hardware.neuralnetworks@1.1",
2870 "android.hardware.neuralnetworks@1.2",
2871 "android.hardware.neuralnetworks@1.3",
2872 "android.hidl.allocator@1.0",
2873 "android.hidl.memory.token@1.0",
2874 "android.hidl.memory@1.0",
2875 "android.hidl.safe_union@1.0",
2876 "libarect",
2877 "libbuildversion",
2878 "libmath",
2879 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002880 }
2881 //
2882 // Module separator
2883 //
2884 m["com.android.media"] = []string{
2885 "android.frameworks.bufferhub@1.0",
2886 "android.hardware.cas.native@1.0",
2887 "android.hardware.cas@1.0",
2888 "android.hardware.configstore-utils",
2889 "android.hardware.configstore@1.0",
2890 "android.hardware.configstore@1.1",
2891 "android.hardware.graphics.allocator@2.0",
2892 "android.hardware.graphics.allocator@3.0",
2893 "android.hardware.graphics.bufferqueue@1.0",
2894 "android.hardware.graphics.bufferqueue@2.0",
2895 "android.hardware.graphics.common@1.0",
2896 "android.hardware.graphics.common@1.1",
2897 "android.hardware.graphics.common@1.2",
2898 "android.hardware.graphics.mapper@2.0",
2899 "android.hardware.graphics.mapper@2.1",
2900 "android.hardware.graphics.mapper@3.0",
2901 "android.hardware.media.omx@1.0",
2902 "android.hardware.media@1.0",
2903 "android.hidl.allocator@1.0",
2904 "android.hidl.memory.token@1.0",
2905 "android.hidl.memory@1.0",
2906 "android.hidl.token@1.0",
2907 "android.hidl.token@1.0-utils",
2908 "bionic_libc_platform_headers",
2909 "exoplayer2-extractor",
2910 "exoplayer2-extractor-annotation-stubs",
2911 "gl_headers",
2912 "jsr305",
2913 "libEGL",
2914 "libEGL_blobCache",
2915 "libEGL_getProcAddress",
2916 "libFLAC",
2917 "libFLAC-config",
2918 "libFLAC-headers",
2919 "libGLESv2",
2920 "libaacextractor",
2921 "libamrextractor",
2922 "libarect",
2923 "libaudio_system_headers",
2924 "libaudioclient",
2925 "libaudioclient_headers",
2926 "libaudiofoundation",
2927 "libaudiofoundation_headers",
2928 "libaudiomanager",
2929 "libaudiopolicy",
2930 "libaudioutils",
2931 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002932 "libbluetooth-types-header",
2933 "libbufferhub",
2934 "libbufferhub_headers",
2935 "libbufferhubqueue",
2936 "libc_malloc_debug_backtrace",
2937 "libcamera_client",
2938 "libcamera_metadata",
2939 "libdvr_headers",
2940 "libexpat",
2941 "libfifo",
2942 "libflacextractor",
2943 "libgrallocusage",
2944 "libgraphicsenv",
2945 "libgui",
2946 "libgui_headers",
2947 "libhardware_headers",
2948 "libinput",
2949 "liblzma",
2950 "libmath",
2951 "libmedia",
2952 "libmedia_codeclist",
2953 "libmedia_headers",
2954 "libmedia_helper",
2955 "libmedia_helper_headers",
2956 "libmedia_midiiowrapper",
2957 "libmedia_omx",
2958 "libmediautils",
2959 "libmidiextractor",
2960 "libmkvextractor",
2961 "libmp3extractor",
2962 "libmp4extractor",
2963 "libmpeg2extractor",
2964 "libnativebase_headers",
2965 "libnativewindow_headers",
2966 "libnblog",
2967 "liboggextractor",
2968 "libpackagelistparser",
2969 "libpdx",
2970 "libpdx_default_transport",
2971 "libpdx_headers",
2972 "libpdx_uds",
2973 "libprocinfo",
2974 "libspeexresampler",
2975 "libspeexresampler",
2976 "libstagefright_esds",
2977 "libstagefright_flacdec",
2978 "libstagefright_flacdec",
2979 "libstagefright_foundation",
2980 "libstagefright_foundation_headers",
2981 "libstagefright_foundation_without_imemory",
2982 "libstagefright_headers",
2983 "libstagefright_id3",
2984 "libstagefright_metadatautils",
2985 "libstagefright_mpeg2extractor",
2986 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002987 "libui",
2988 "libui_headers",
2989 "libunwindstack",
2990 "libvibrator",
2991 "libvorbisidec",
2992 "libwavextractor",
2993 "libwebm",
2994 "media_ndk_headers",
2995 "media_plugin_headers",
2996 "updatable-media",
2997 }
2998 //
2999 // Module separator
3000 //
3001 m["com.android.media.swcodec"] = []string{
3002 "android.frameworks.bufferhub@1.0",
3003 "android.hardware.common-ndk_platform",
3004 "android.hardware.configstore-utils",
3005 "android.hardware.configstore@1.0",
3006 "android.hardware.configstore@1.1",
3007 "android.hardware.graphics.allocator@2.0",
3008 "android.hardware.graphics.allocator@3.0",
3009 "android.hardware.graphics.allocator@4.0",
3010 "android.hardware.graphics.bufferqueue@1.0",
3011 "android.hardware.graphics.bufferqueue@2.0",
3012 "android.hardware.graphics.common-ndk_platform",
3013 "android.hardware.graphics.common@1.0",
3014 "android.hardware.graphics.common@1.1",
3015 "android.hardware.graphics.common@1.2",
3016 "android.hardware.graphics.mapper@2.0",
3017 "android.hardware.graphics.mapper@2.1",
3018 "android.hardware.graphics.mapper@3.0",
3019 "android.hardware.graphics.mapper@4.0",
3020 "android.hardware.media.bufferpool@2.0",
3021 "android.hardware.media.c2@1.0",
3022 "android.hardware.media.c2@1.1",
3023 "android.hardware.media.omx@1.0",
3024 "android.hardware.media@1.0",
3025 "android.hardware.media@1.0",
3026 "android.hidl.memory.token@1.0",
3027 "android.hidl.memory@1.0",
3028 "android.hidl.safe_union@1.0",
3029 "android.hidl.token@1.0",
3030 "android.hidl.token@1.0-utils",
3031 "libEGL",
3032 "libFLAC",
3033 "libFLAC-config",
3034 "libFLAC-headers",
3035 "libFraunhoferAAC",
3036 "libLibGuiProperties",
3037 "libarect",
3038 "libaudio_system_headers",
3039 "libaudioutils",
3040 "libaudioutils",
3041 "libaudioutils_fixedfft",
3042 "libavcdec",
3043 "libavcenc",
3044 "libavservices_minijail",
3045 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003046 "libbinderthreadstateutils",
3047 "libbluetooth-types-header",
3048 "libbufferhub_headers",
3049 "libcodec2",
3050 "libcodec2_headers",
3051 "libcodec2_hidl@1.0",
3052 "libcodec2_hidl@1.1",
3053 "libcodec2_internal",
3054 "libcodec2_soft_aacdec",
3055 "libcodec2_soft_aacenc",
3056 "libcodec2_soft_amrnbdec",
3057 "libcodec2_soft_amrnbenc",
3058 "libcodec2_soft_amrwbdec",
3059 "libcodec2_soft_amrwbenc",
3060 "libcodec2_soft_av1dec_gav1",
3061 "libcodec2_soft_avcdec",
3062 "libcodec2_soft_avcenc",
3063 "libcodec2_soft_common",
3064 "libcodec2_soft_flacdec",
3065 "libcodec2_soft_flacenc",
3066 "libcodec2_soft_g711alawdec",
3067 "libcodec2_soft_g711mlawdec",
3068 "libcodec2_soft_gsmdec",
3069 "libcodec2_soft_h263dec",
3070 "libcodec2_soft_h263enc",
3071 "libcodec2_soft_hevcdec",
3072 "libcodec2_soft_hevcenc",
3073 "libcodec2_soft_mp3dec",
3074 "libcodec2_soft_mpeg2dec",
3075 "libcodec2_soft_mpeg4dec",
3076 "libcodec2_soft_mpeg4enc",
3077 "libcodec2_soft_opusdec",
3078 "libcodec2_soft_opusenc",
3079 "libcodec2_soft_rawdec",
3080 "libcodec2_soft_vorbisdec",
3081 "libcodec2_soft_vp8dec",
3082 "libcodec2_soft_vp8enc",
3083 "libcodec2_soft_vp9dec",
3084 "libcodec2_soft_vp9enc",
3085 "libcodec2_vndk",
3086 "libdvr_headers",
3087 "libfmq",
3088 "libfmq",
3089 "libgav1",
3090 "libgralloctypes",
3091 "libgrallocusage",
3092 "libgraphicsenv",
3093 "libgsm",
3094 "libgui_bufferqueue_static",
3095 "libgui_headers",
3096 "libhardware",
3097 "libhardware_headers",
3098 "libhevcdec",
3099 "libhevcenc",
3100 "libion",
3101 "libjpeg",
3102 "liblzma",
3103 "libmath",
3104 "libmedia_codecserviceregistrant",
3105 "libmedia_headers",
3106 "libmpeg2dec",
3107 "libnativebase_headers",
3108 "libnativewindow_headers",
3109 "libpdx_headers",
3110 "libscudo_wrapper",
3111 "libsfplugin_ccodec_utils",
3112 "libspeexresampler",
3113 "libstagefright_amrnb_common",
3114 "libstagefright_amrnbdec",
3115 "libstagefright_amrnbenc",
3116 "libstagefright_amrwbdec",
3117 "libstagefright_amrwbenc",
3118 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003119 "libstagefright_enc_common",
3120 "libstagefright_flacdec",
3121 "libstagefright_foundation",
3122 "libstagefright_foundation_headers",
3123 "libstagefright_headers",
3124 "libstagefright_m4vh263dec",
3125 "libstagefright_m4vh263enc",
3126 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003127 "libui",
3128 "libui_headers",
3129 "libunwindstack",
3130 "libvorbisidec",
3131 "libvpx",
3132 "libyuv",
3133 "libyuv_static",
3134 "media_ndk_headers",
3135 "media_plugin_headers",
3136 "mediaswcodec",
3137 }
3138 //
3139 // Module separator
3140 //
3141 m["com.android.mediaprovider"] = []string{
3142 "MediaProvider",
3143 "MediaProviderGoogle",
3144 "fmtlib_ndk",
3145 "libbase_ndk",
3146 "libfuse",
3147 "libfuse_jni",
3148 }
3149 //
3150 // Module separator
3151 //
3152 m["com.android.permission"] = []string{
3153 "car-ui-lib",
3154 "iconloader",
3155 "kotlin-annotations",
3156 "kotlin-stdlib",
3157 "kotlin-stdlib-jdk7",
3158 "kotlin-stdlib-jdk8",
3159 "kotlinx-coroutines-android",
3160 "kotlinx-coroutines-android-nodeps",
3161 "kotlinx-coroutines-core",
3162 "kotlinx-coroutines-core-nodeps",
3163 "permissioncontroller-statsd",
3164 "GooglePermissionController",
3165 "PermissionController",
3166 "SettingsLibActionBarShadow",
3167 "SettingsLibAppPreference",
3168 "SettingsLibBarChartPreference",
3169 "SettingsLibLayoutPreference",
3170 "SettingsLibProgressBar",
3171 "SettingsLibSearchWidget",
3172 "SettingsLibSettingsTheme",
3173 "SettingsLibRestrictedLockUtils",
3174 "SettingsLibHelpUtils",
3175 }
3176 //
3177 // Module separator
3178 //
3179 m["com.android.runtime"] = []string{
3180 "bionic_libc_platform_headers",
3181 "libarm-optimized-routines-math",
3182 "libc_aeabi",
3183 "libc_bionic",
3184 "libc_bionic_ndk",
3185 "libc_bootstrap",
3186 "libc_common",
3187 "libc_common_shared",
3188 "libc_common_static",
3189 "libc_dns",
3190 "libc_dynamic_dispatch",
3191 "libc_fortify",
3192 "libc_freebsd",
3193 "libc_freebsd_large_stack",
3194 "libc_gdtoa",
3195 "libc_init_dynamic",
3196 "libc_init_static",
3197 "libc_jemalloc_wrapper",
3198 "libc_netbsd",
3199 "libc_nomalloc",
3200 "libc_nopthread",
3201 "libc_openbsd",
3202 "libc_openbsd_large_stack",
3203 "libc_openbsd_ndk",
3204 "libc_pthread",
3205 "libc_static_dispatch",
3206 "libc_syscalls",
3207 "libc_tzcode",
3208 "libc_unwind_static",
3209 "libdebuggerd",
3210 "libdebuggerd_common_headers",
3211 "libdebuggerd_handler_core",
3212 "libdebuggerd_handler_fallback",
3213 "libdl_static",
3214 "libjemalloc5",
3215 "liblinker_main",
3216 "liblinker_malloc",
3217 "liblz4",
3218 "liblzma",
3219 "libprocinfo",
3220 "libpropertyinfoparser",
3221 "libscudo",
3222 "libstdc++",
3223 "libsystemproperties",
3224 "libtombstoned_client_static",
3225 "libunwindstack",
3226 "libz",
3227 "libziparchive",
3228 }
3229 //
3230 // Module separator
3231 //
3232 m["com.android.tethering"] = []string{
3233 "android.hardware.tetheroffload.config-V1.0-java",
3234 "android.hardware.tetheroffload.control-V1.0-java",
3235 "android.hidl.base-V1.0-java",
3236 "libcgrouprc",
3237 "libcgrouprc_format",
3238 "libtetherutilsjni",
3239 "libvndksupport",
3240 "net-utils-framework-common",
3241 "netd_aidl_interface-V3-java",
3242 "netlink-client",
3243 "networkstack-aidl-interfaces-java",
3244 "tethering-aidl-interfaces-java",
3245 "TetheringApiCurrentLib",
3246 }
3247 //
3248 // Module separator
3249 //
3250 m["com.android.wifi"] = []string{
3251 "PlatformProperties",
3252 "android.hardware.wifi-V1.0-java",
3253 "android.hardware.wifi-V1.0-java-constants",
3254 "android.hardware.wifi-V1.1-java",
3255 "android.hardware.wifi-V1.2-java",
3256 "android.hardware.wifi-V1.3-java",
3257 "android.hardware.wifi-V1.4-java",
3258 "android.hardware.wifi.hostapd-V1.0-java",
3259 "android.hardware.wifi.hostapd-V1.1-java",
3260 "android.hardware.wifi.hostapd-V1.2-java",
3261 "android.hardware.wifi.supplicant-V1.0-java",
3262 "android.hardware.wifi.supplicant-V1.1-java",
3263 "android.hardware.wifi.supplicant-V1.2-java",
3264 "android.hardware.wifi.supplicant-V1.3-java",
3265 "android.hidl.base-V1.0-java",
3266 "android.hidl.manager-V1.0-java",
3267 "android.hidl.manager-V1.1-java",
3268 "android.hidl.manager-V1.2-java",
3269 "bouncycastle-unbundled",
3270 "dnsresolver_aidl_interface-V2-java",
3271 "error_prone_annotations",
3272 "framework-wifi-pre-jarjar",
3273 "framework-wifi-util-lib",
3274 "ipmemorystore-aidl-interfaces-V3-java",
3275 "ipmemorystore-aidl-interfaces-java",
3276 "ksoap2",
3277 "libnanohttpd",
3278 "libwifi-jni",
3279 "net-utils-services-common",
3280 "netd_aidl_interface-V2-java",
3281 "netd_aidl_interface-unstable-java",
3282 "netd_event_listener_interface-java",
3283 "netlink-client",
3284 "networkstack-client",
3285 "services.net",
3286 "wifi-lite-protos",
3287 "wifi-nano-protos",
3288 "wifi-service-pre-jarjar",
3289 "wifi-service-resources",
3290 }
3291 //
3292 // Module separator
3293 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003294 m["com.android.os.statsd"] = []string{
3295 "libstatssocket",
3296 }
3297 //
3298 // Module separator
3299 //
3300 m[android.AvailableToAnyApex] = []string{
3301 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3302 "androidx",
3303 "androidx-constraintlayout_constraintlayout",
3304 "androidx-constraintlayout_constraintlayout-nodeps",
3305 "androidx-constraintlayout_constraintlayout-solver",
3306 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3307 "com.google.android.material_material",
3308 "com.google.android.material_material-nodeps",
3309
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003310 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003311 "libprofile-clang-extras",
3312 "libprofile-clang-extras_ndk",
3313 "libprofile-extras",
3314 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003315 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003316 }
3317 return m
3318}
3319
3320func init() {
Spandan Dasf14e2542021-11-12 00:01:37 +00003321 android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...)
3322 android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003323}
3324
Spandan Dasf14e2542021-11-12 00:01:37 +00003325func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule {
3326 rules := make([]android.Rule, 0, len(bcpPermittedPackages))
3327 for jar, permittedPackages := range bcpPermittedPackages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003328 permittedPackagesRule := android.NeverAllow().
Spandan Dasf14e2542021-11-12 00:01:37 +00003329 With("name", jar).
3330 WithMatcher("permitted_packages", android.NotInList(permittedPackages)).
3331 Because(jar +
3332 " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") +
Anton Hanssone1b18362021-12-23 15:05:38 +00003333 ". Please consider the following alternatives:\n" +
Andrei Onead967aee2022-01-19 15:36:40 +00003334 " 1. If the offending code is from a statically linked library, consider " +
3335 "removing that dependency and using an alternative already in the " +
3336 "bootclasspath, or perhaps a shared library." +
3337 " 2. Move the offending code into an allowed package.\n" +
3338 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3339 "health implications of bundling that code, particularly if the offending jar " +
3340 "is part of the bootclasspath.")
Spandan Dasf14e2542021-11-12 00:01:37 +00003341
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003342 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003343 }
3344 return rules
3345}
3346
Anton Hanssone1b18362021-12-23 15:05:38 +00003347// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003348// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003349func qBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003350 return map[string][]string{
Spandan Dasf14e2542021-11-12 00:01:37 +00003351 "conscrypt": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003352 "android.net.ssl",
3353 "com.android.org.conscrypt",
3354 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003355 "updatable-media": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003356 "android.media",
3357 },
3358 }
3359}
3360
Anton Hanssone1b18362021-12-23 15:05:38 +00003361// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003362// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003363func rBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003364 return map[string][]string{
Spandan Dasf14e2542021-11-12 00:01:37 +00003365 "framework-mediaprovider": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003366 "android.provider",
3367 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003368 "framework-permission": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003369 "android.permission",
3370 "android.app.role",
3371 "com.android.permission",
3372 "com.android.role",
3373 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003374 "framework-sdkextensions": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003375 "android.os.ext",
3376 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003377 "framework-statsd": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003378 "android.app",
3379 "android.os",
3380 "android.util",
3381 "com.android.internal.statsd",
3382 "com.android.server.stats",
3383 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003384 "framework-wifi": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003385 "com.android.server.wifi",
3386 "com.android.wifi.x",
3387 "android.hardware.wifi",
3388 "android.net.wifi",
3389 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003390 "framework-tethering": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003391 "android.net",
3392 },
3393 }
3394}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003395
3396// For Bazel / bp2build
3397
3398type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003399 Manifest bazel.LabelAttribute
3400 Android_manifest bazel.LabelAttribute
3401 File_contexts bazel.LabelAttribute
3402 Key bazel.LabelAttribute
3403 Certificate bazel.LabelAttribute
3404 Min_sdk_version *string
3405 Updatable bazel.BoolAttribute
3406 Installable bazel.BoolAttribute
3407 Binaries bazel.LabelListAttribute
3408 Prebuilts bazel.LabelListAttribute
3409 Native_shared_libs_32 bazel.LabelListAttribute
3410 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003411 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003412}
3413
3414type convertedNativeSharedLibs struct {
3415 Native_shared_libs_32 bazel.LabelListAttribute
3416 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003417}
3418
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003419// ConvertWithBp2build performs bp2build conversion of an apex
3420func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3421 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003422 if ctx.ModuleType() != "apex" {
3423 return
3424 }
3425
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003426 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003427 if a.properties.Manifest != nil {
3428 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003429 }
3430
3431 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003432 if a.properties.AndroidManifest != nil {
3433 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003434 }
3435
3436 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003437 if a.properties.File_contexts != nil {
3438 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003439 }
3440
Albert Martineefabcf2022-03-21 20:11:16 +00003441 // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
3442 // given it's coming via config, we probably don't want to put it in here.
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003443 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003444 if a.properties.Min_sdk_version != nil {
3445 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003446 }
3447
3448 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003449 if a.overridableProperties.Key != nil {
3450 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003451 }
3452
3453 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003454 if a.overridableProperties.Certificate != nil {
3455 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003456 }
3457
Yu Liu4ae55d12022-01-05 17:17:23 -08003458 nativeSharedLibs := &convertedNativeSharedLibs{
3459 Native_shared_libs_32: bazel.LabelListAttribute{},
3460 Native_shared_libs_64: bazel.LabelListAttribute{},
3461 }
3462 compileMultilib := "both"
3463 if a.CompileMultilib() != nil {
3464 compileMultilib = *a.CompileMultilib()
3465 }
3466
3467 // properties.Native_shared_libs is treated as "both"
3468 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3469 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3470 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3471 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3472 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003473
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003474 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003475 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3476 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3477
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003478 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003479 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003480
3481 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003482 if a.properties.Updatable != nil {
3483 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003484 }
3485
3486 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003487 if a.properties.Installable != nil {
3488 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003489 }
3490
Wei Lif034cb42022-01-19 15:54:31 -08003491 var compressibleAttribute bazel.BoolAttribute
3492 if a.overridableProperties.Compressible != nil {
3493 compressibleAttribute.Value = a.overridableProperties.Compressible
3494 }
3495
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003496 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003497 Manifest: manifestLabelAttribute,
3498 Android_manifest: androidManifestLabelAttribute,
3499 File_contexts: fileContextsLabelAttribute,
3500 Min_sdk_version: minSdkVersion,
3501 Key: keyLabelAttribute,
3502 Certificate: certificateLabelAttribute,
3503 Updatable: updatableAttribute,
3504 Installable: installableAttribute,
3505 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3506 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3507 Binaries: binariesLabelListAttribute,
3508 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003509 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003510 }
3511
3512 props := bazel.BazelTargetModuleProperties{
3513 Rule_class: "apex",
3514 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3515 }
3516
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003517 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003518}
Yu Liu4ae55d12022-01-05 17:17:23 -08003519
3520// The following conversions are based on this table where the rows are the compile_multilib
3521// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3522// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3523// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3524// should not be compiled.
3525// multib/compile_multilib, 32, 64, both, first
3526// 32, 32/32, none/none, 32/32, none/32
3527// 64, none/none, 64/none, 64/none, 64/none
3528// both, 32/32, 64/none, 32&64/32, 64/32
3529// first, 32/32, 64/none, 64/32, 64/32
3530
3531func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3532 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3533 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3534 switch compileMultilb {
3535 case "both", "32":
3536 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3537 case "first":
3538 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3539 case "64":
3540 // Incompatible, ignore
3541 default:
3542 invalidCompileMultilib(ctx, compileMultilb)
3543 }
3544}
3545
3546func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3547 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3548 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3549 switch compileMultilb {
3550 case "both", "64", "first":
3551 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3552 case "32":
3553 // Incompatible, ignore
3554 default:
3555 invalidCompileMultilib(ctx, compileMultilb)
3556 }
3557}
3558
3559func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3560 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3561 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3562 switch compileMultilb {
3563 case "both":
3564 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3565 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3566 case "first":
3567 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3568 case "32":
3569 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3570 case "64":
3571 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3572 default:
3573 invalidCompileMultilib(ctx, compileMultilb)
3574 }
3575}
3576
3577func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3578 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3579 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3580 switch compileMultilb {
3581 case "both", "first":
3582 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3583 case "32":
3584 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3585 case "64":
3586 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3587 default:
3588 invalidCompileMultilib(ctx, compileMultilb)
3589 }
3590}
3591
3592func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3593 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3594 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3595}
3596
3597func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3598 list := bazel.LabelListAttribute{}
3599 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3600 nativeSharedLibs.Native_shared_libs_32.Append(list)
3601}
3602
3603func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3604 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3605 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3606}
3607
3608func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3609 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3610 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3611}
3612
3613func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3614 labelListAttr *bazel.LabelListAttribute) {
3615 list := bazel.LabelListAttribute{}
3616 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3617 labelListAttr.Append(list)
3618}
3619
3620func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3621 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3622}