blob: eac7cf2b6de3416dc737590d9d31d5cc230ce82a [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"
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +000022 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090023 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024 "strings"
25
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080027 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090028 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070029
30 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040031 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080032 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070033 "android/soong/cc"
34 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090035 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070036 "android/soong/java"
Inseob Kim5eb7ee92022-04-27 10:30:34 +090037 "android/soong/multitree"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090039 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070040 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090041)
42
Jiyong Park8e6d52f2020-11-19 14:37:47 +090043func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000044 registerApexBuildComponents(android.InitRegistrationContext)
45}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090046
Paul Duffin667893c2021-03-09 22:34:13 +000047func registerApexBuildComponents(ctx android.RegistrationContext) {
48 ctx.RegisterModuleType("apex", BundleFactory)
49 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
50 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
51 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
52 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070053 ctx.RegisterModuleType("override_apex", OverrideApexFactory)
Paul Duffin667893c2021-03-09 22:34:13 +000054 ctx.RegisterModuleType("apex_set", apexSetFactory)
55
Paul Duffin5dda3e32021-05-05 14:13:27 +010056 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000057 ctx.PreDepsMutators(RegisterPreDepsMutators)
58 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090059}
60
Paul Duffin5dda3e32021-05-05 14:13:27 +010061func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
62 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
63}
64
Jiyong Park8e6d52f2020-11-19 14:37:47 +090065func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
66 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
67 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
68}
69
70func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000071 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090072 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
73 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
74 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010075 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
76 // it should create a platform variant.
77 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090078 ctx.BottomUp("apex", apexMutator).Parallel()
79 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
80 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Spandan Das66773252022-01-15 00:23:18 +000081 // Register after apex_info mutator so that it can use ApexVariationName
82 ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090083}
84
85type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090086 // Json manifest file describing meta info of this APEX bundle. Refer to
87 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090088 Manifest *string `android:"path"`
89
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090090 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
91 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090092 AndroidManifest *string `android:"path"`
93
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090094 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
95 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090096 Apex_name *string
97
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090098 // Determines the file contexts file for setting the security contexts to files in this APEX
99 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
100 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900101 File_contexts *string `android:"path"`
102
Jiyong Park038e8522021-12-13 23:56:35 +0900103 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
104 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
105 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
106 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
107 // capability. If this property is not set, or a file is missing in the file, default config
108 // is used.
109 Canned_fs_config *string `android:"path"`
110
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900111 ApexNativeDependencies
112
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900113 Multilib apexMultilibProperties
114
Sundong Ahn80c04892021-11-23 00:57:19 +0000115 // List of sh binaries that are embedded inside this APEX bundle.
116 Sh_binaries []string
117
Paul Duffin3abc1742021-03-15 19:32:23 +0000118 // List of platform_compat_config files that are embedded inside this APEX bundle.
119 Compat_configs []string
120
Jiyong Park12a719c2021-01-07 15:31:24 +0900121 // List of filesystem images that are embedded inside this APEX bundle.
122 Filesystems []string
123
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900124 // The minimum SDK version that this APEX must support at minimum. This is usually set to
125 // the SDK version that the APEX was first introduced.
126 Min_sdk_version *string
127
128 // Whether this APEX is considered updatable or not. When set to true, this will enforce
129 // additional rules for making sure that the APEX is truly updatable. To be updatable,
130 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000131 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900132 Updatable *bool
133
Jiyong Parkf4020582021-11-29 12:37:10 +0900134 // Marks that this APEX is designed to be updatable in the future, although it's not
135 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
136 // updatable APEXes. Currently, this disables the size optimization, so that the size of
137 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
138 // false.
139 Future_updatable *bool
140
Jiyong Park1bc84122021-06-22 20:23:05 +0900141 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
142 // false`. Default is false.
143 Platform_apis *bool
144
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900145 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
146 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900147 Installable *bool
148
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900149 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
150 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
151 Use_vndk_as_stable *bool
152
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000153 // Whether this is multi-installed APEX should skip installing symbol files.
154 // Multi-installed APEXes share the same apex_name and are installed at the same time.
155 // Default is false.
156 //
157 // Should be set to true for all multi-installed APEXes except the singular
158 // default version within the multi-installed group.
159 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
160 // or else conflicting build rules may be created.
161 Multi_install_skip_symbol_files *bool
162
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900163 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
164 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
165 // container. When set to zip, contents are stored in a zip container directly. This type is
166 // mostly for host-side debugging. When set to both, the two types are both built. Default
167 // is 'image'.
168 Payload_type *string
169
Huang Jianan13cac632021-08-02 15:02:17 +0800170 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
171 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900172 Payload_fs_type *string
173
174 // For telling the APEX to ignore special handling for system libraries such as bionic.
175 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900176 Ignore_system_library_special_case *bool
177
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100178 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100179 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100180 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900181
182 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
183 // used in tests.
184 Test_only_unsigned_payload *bool
185
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000186 // Whenever apex should be compressed, regardless of product flag used. Should be only
187 // used in tests.
188 Test_only_force_compression *bool
189
Jooyung Han09c11ad2021-10-27 03:45:31 +0900190 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
191 // with the tool to sign payload contents.
192 Custom_sign_tool *string
193
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100194 // Canonical name of this APEX bundle. Used to determine the path to the
195 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
196 // apex mutator variations. For override_apex modules, this is the name of the
197 // overridden base module.
198 ApexVariationName string `blueprint:"mutated"`
199
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900200 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900201
202 // List of sanitizer names that this APEX is enabled for
203 SanitizerNames []string `blueprint:"mutated"`
204
205 PreventInstall bool `blueprint:"mutated"`
206
207 HideFromMake bool `blueprint:"mutated"`
208
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900209 // Internal package method for this APEX. When payload_type is image, this can be either
210 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
211 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900212 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900213}
214
215type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900216 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900217 Native_shared_libs []string
218
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900219 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900220 Jni_libs []string
221
Jiyong Park99644e92020-11-17 22:21:02 +0900222 // List of rust dyn libraries
223 Rust_dyn_libs []string
224
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900225 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900226 Binaries []string
227
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900228 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900229 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900230
231 // List of filesystem images that are embedded inside this APEX bundle.
232 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900233}
234
235type apexMultilibProperties struct {
236 // Native dependencies whose compile_multilib is "first"
237 First ApexNativeDependencies
238
239 // Native dependencies whose compile_multilib is "both"
240 Both ApexNativeDependencies
241
242 // Native dependencies whose compile_multilib is "prefer32"
243 Prefer32 ApexNativeDependencies
244
245 // Native dependencies whose compile_multilib is "32"
246 Lib32 ApexNativeDependencies
247
248 // Native dependencies whose compile_multilib is "64"
249 Lib64 ApexNativeDependencies
250}
251
252type apexTargetBundleProperties struct {
253 Target struct {
254 // Multilib properties only for android.
255 Android struct {
256 Multilib apexMultilibProperties
257 }
258
259 // Multilib properties only for host.
260 Host struct {
261 Multilib apexMultilibProperties
262 }
263
264 // Multilib properties only for host linux_bionic.
265 Linux_bionic struct {
266 Multilib apexMultilibProperties
267 }
268
269 // Multilib properties only for host linux_glibc.
270 Linux_glibc struct {
271 Multilib apexMultilibProperties
272 }
273 }
274}
275
Jiyong Park59140302020-12-14 18:44:04 +0900276type apexArchBundleProperties struct {
277 Arch struct {
278 Arm struct {
279 ApexNativeDependencies
280 }
281 Arm64 struct {
282 ApexNativeDependencies
283 }
284 X86 struct {
285 ApexNativeDependencies
286 }
287 X86_64 struct {
288 ApexNativeDependencies
289 }
290 }
291}
292
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900293// These properties can be used in override_apex to override the corresponding properties in the
294// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900295type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900296 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900297 Apps []string
298
Daniel Norman5a3ce132021-08-26 15:44:43 -0700299 // List of prebuilt files that are embedded inside this APEX bundle.
300 Prebuilts []string
301
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900302 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900303 Rros []string
304
markchien7c803b82021-08-26 22:10:06 +0800305 // List of BPF programs inside this APEX bundle.
306 Bpfs []string
307
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900308 // List of bootclasspath fragments that are embedded inside this APEX bundle.
309 Bootclasspath_fragments []string
310
311 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
312 Systemserverclasspath_fragments []string
313
314 // List of java libraries that are embedded inside this APEX bundle.
315 Java_libs []string
316
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900317 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
318 // Soong). This does not completely prevent installation of the overridden binaries, but if
319 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
320 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900321 Overrides []string
322
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900323 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900324 Logging_parent string
325
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900326 // Apex Container package name. Override value for attribute package:name in
327 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900328 Package_name string
329
330 // A txt file containing list of files that are allowed to be included in this APEX.
331 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700332
333 // Name of the apex_key module that provides the private key to sign this APEX bundle.
334 Key *string
335
336 // Specifies the certificate and the private key to sign the zip container of this APEX. If
337 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
338 // as the certificate and the private key, respectively. If this is ":module", then the
339 // certificate and the private key are provided from the android_app_certificate module
340 // named "module".
341 Certificate *string
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -0400342
343 // Whether this APEX can be compressed or not. Setting this property to false means this
344 // APEX will never be compressed. When set to true, APEX will be compressed if other
345 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
346 // Default: false.
347 Compressible *bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900348}
349
350type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900351 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352 android.ModuleBase
353 android.DefaultableModuleBase
354 android.OverridableModuleBase
355 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400356 android.BazelModuleBase
Inseob Kim5eb7ee92022-04-27 10:30:34 +0900357 multitree.ExportableModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900358
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900359 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900360 properties apexBundleProperties
361 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900362 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900364 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900365
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900366 ///////////////////////////////////////////////////////////////////////////////////////////
367 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900368
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800370 publicKeyFile android.Path
371 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900372
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900373 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800374 containerCertificateFile android.Path
375 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900376
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900377 // Flags for special variants of APEX
378 testApex bool
379 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900380
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900381 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
382 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383 primaryApexType bool
384
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900385 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900386 suffix string
387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900388 // File system type of apex_payload.img
389 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900390
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900391 // Whether to create symlink to the system file instead of having a file inside the apex or
392 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900393 linkToSystemLib bool
394
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900395 // List of files to be included in this APEX. This is filled in the first part of
396 // GenerateAndroidBuildActions.
397 filesInfo []apexFile
398
399 // List of other module names that should be installed when this APEX gets installed.
400 requiredDeps []string
401
402 ///////////////////////////////////////////////////////////////////////////////////////////
403 // Outputs (final and intermediates)
404
405 // Processed apex manifest in JSONson format (for Q)
406 manifestJsonOut android.WritablePath
407
408 // Processed apex manifest in PB format (for R+)
409 manifestPbOut android.WritablePath
410
411 // Processed file_contexts files
412 fileContexts android.WritablePath
413
Bob Badourde6a0872022-04-01 18:00:00 +0000414 // Path to notice file in html.gz format.
415 htmlGzNotice android.WritablePath
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900416
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900417 // The built APEX file. This is the main product.
Jooyung Hana6d36672022-02-24 13:58:07 +0900418 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900419 outputFile android.WritablePath
420
Jooyung Hana6d36672022-02-24 13:58:07 +0900421 // The built uncompressed .apex file.
422 outputApexFile android.WritablePath
423
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900424 // The built APEX file in app bundle format. This file is not directly installed to the
425 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
426 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
427 // system) to be merged into a single app bundle file that Play accepts. See
428 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
429 bundleModuleFile android.WritablePath
430
Colin Cross6340ea52021-11-04 12:01:18 -0700431 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900432 installDir android.InstallPath
433
Colin Cross6340ea52021-11-04 12:01:18 -0700434 // Path where this APEX was installed.
435 installedFile android.InstallPath
436
437 // Installed locations of symlinks for backward compatibility.
438 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900439
440 // Text file having the list of individual files that are included in this APEX. Used for
441 // debugging purpose.
442 installedFilesFile android.WritablePath
443
444 // List of module names that this APEX is including (to be shown via *-deps-info target).
445 // Used for debugging purpose.
446 android.ApexBundleDepsInfo
447
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900448 // Optional list of lint report zip files for apexes that contain java or app modules
449 lintReports android.Paths
450
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900451 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000452
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000453 isCompressed bool
454
sophiezc80a2b32020-11-12 16:39:19 +0000455 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700456 nativeApisUsedByModuleFile android.ModuleOutPath
457 nativeApisBackedByModuleFile android.ModuleOutPath
458 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800459
460 // Collect the module directory for IDE info in java/jdeps.go.
461 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900462}
463
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900464// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900465type apexFileClass int
466
Jooyung Han72bd2f82019-10-23 16:46:38 +0900467const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900468 app apexFileClass = iota
469 appSet
470 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900471 goBinary
472 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900473 nativeExecutable
474 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900475 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900476 pyBinary
477 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900478)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900479
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900480// apexFile represents a file in an APEX bundle. This is created during the first half of
481// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
482// of the function, this is used to create commands that copies the files into a staging directory,
483// where they are packaged into the APEX file. This struct is also used for creating Make modules
484// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900485type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900486 // buildFile is put in the installDir inside the APEX.
Bob Badourde6a0872022-04-01 18:00:00 +0000487 builtFile android.Path
488 installDir string
489 customStem string
490 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900491
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900492 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
493 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
494 // suffix>]
495 androidMkModuleName string // becomes LOCAL_MODULE
496 class apexFileClass // becomes LOCAL_MODULE_CLASS
497 moduleDir string // becomes LOCAL_PATH
498 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
499 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
500 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
501 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900502
503 jacocoReportClassesFile android.Path // only for javalibs and apps
504 lintDepSets java.LintDepSets // only for javalibs and apps
505 certificate java.Certificate // only for apps
506 overriddenPackageName string // only for apps
507
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900508 transitiveDep bool
509 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900510
Jiyong Park57621b22021-01-20 20:33:11 +0900511 multilib string
512
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900513 // TODO(jiyong): remove this
514 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900515}
516
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900517// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900518func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
519 ret := apexFile{
520 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900522 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523 class: class,
524 module: module,
525 }
526 if module != nil {
527 ret.moduleDir = ctx.OtherModuleDir(module)
528 ret.requiredModuleNames = module.RequiredModuleNames()
529 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
530 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900531 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900532 }
533 return ret
534}
535
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900536func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900537 return af.builtFile != nil && af.builtFile.String() != ""
538}
539
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900540// apexRelativePath returns the relative path of the given path from the install directory of this
541// apexFile.
542// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900543func (af *apexFile) apexRelativePath(path string) string {
544 return filepath.Join(af.installDir, path)
545}
546
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900547// path returns path of this apex file relative to the APEX root
548func (af *apexFile) path() string {
549 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900550}
551
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900552// stem returns the base filename of this apex file
553func (af *apexFile) stem() string {
554 if af.customStem != "" {
555 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900556 }
557 return af.builtFile.Base()
558}
559
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900560// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
561func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900562 var ret []string
563 for _, symlink := range af.symlinks {
564 ret = append(ret, af.apexRelativePath(symlink))
565 }
566 return ret
567}
568
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900569// availableToPlatform tests whether this apexFile is from a module that can be installed to the
570// platform.
571func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900572 if af.module == nil {
573 return false
574 }
575 if am, ok := af.module.(android.ApexModule); ok {
576 return am.AvailableFor(android.AvailableToPlatform)
577 }
578 return false
579}
580
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900581////////////////////////////////////////////////////////////////////////////////////////////////////
582// Mutators
583//
584// Brief description about mutators for APEX. The following three mutators are the most important
585// ones.
586//
587// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
588// to the (direct) dependencies of this APEX bundle.
589//
Paul Duffin949abc02020-12-08 10:34:30 +0000590// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900591// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
592// modules are marked as being included in the APEX via BuildForApex().
593//
Paul Duffin949abc02020-12-08 10:34:30 +0000594// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
595// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900596
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900597type dependencyTag struct {
598 blueprint.BaseDependencyTag
599 name string
600
601 // Determines if the dependent will be part of the APEX payload. Can be false for the
602 // dependencies to the signing key module, etc.
603 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000604
605 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
606 // replacement. This is needed because some prebuilt modules do not provide all the information
607 // needed by the apex.
608 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900609}
610
Paul Duffin8c535da2021-03-17 14:51:03 +0000611func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
612 return !d.sourceOnly
613}
614
615var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
616
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900617var (
Paul Duffin0b817782021-03-17 15:02:19 +0000618 androidAppTag = dependencyTag{name: "androidApp", payload: true}
619 bpfTag = dependencyTag{name: "bpf", payload: true}
620 certificateTag = dependencyTag{name: "certificate"}
621 executableTag = dependencyTag{name: "executable", payload: true}
622 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100623 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100624 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000625 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000626 javaLibTag = dependencyTag{name: "javaLib", payload: true}
627 jniLibTag = dependencyTag{name: "jniLib", payload: true}
628 keyTag = dependencyTag{name: "key"}
629 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
630 rroTag = dependencyTag{name: "rro", payload: true}
631 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
632 testForTag = dependencyTag{name: "test for"}
633 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000634 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900635)
636
637// TODO(jiyong): shorten this function signature
638func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900639 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900641 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900642
643 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900644 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900645 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
646 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647 }
648
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900649 // Use *FarVariation* to be able to depend on modules having conflicting variations with
650 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
651 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900653 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900654 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
655 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900656 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900657 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900658}
659
660func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900661 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900662 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
663 } else {
664 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
665 if ctx.Os().Bionic() {
666 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
667 } else {
668 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
669 }
670 }
671}
672
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900673// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
674// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
675func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
676 deviceConfig := ctx.DeviceConfig()
677 if a.vndkApex {
678 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900679 }
680
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900681 var prefix string
682 var vndkVersion string
683 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000684 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900685 prefix = cc.VendorVariationPrefix
686 vndkVersion = deviceConfig.VndkVersion()
687 } else if a.ProductSpecific() {
688 prefix = cc.ProductVariationPrefix
689 vndkVersion = deviceConfig.ProductVndkVersion()
690 }
691 }
692 if vndkVersion == "current" {
693 vndkVersion = deviceConfig.PlatformVndkVersion()
694 }
695 if vndkVersion != "" {
696 return prefix + vndkVersion
697 }
698
699 return android.CoreVariation // The usual case
700}
701
702func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900703 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
704 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
705 // each target os/architectures, appropriate dependencies are selected by their
706 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900707 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900708 imageVariation := a.getImageVariation(ctx)
709
710 a.combineProperties(ctx)
711
712 has32BitTarget := false
713 for _, target := range targets {
714 if target.Arch.ArchType.Multilib == "lib32" {
715 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000716 }
717 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900718 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900719 // Don't include artifacts for the host cross targets because there is no way for us
720 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900721 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900722 continue
723 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000724
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900725 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000726
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900727 // Add native modules targeting both ABIs. When multilib.* is omitted for
728 // native_shared_libs/jni_libs/tests, it implies multilib.both
729 depsList = append(depsList, a.properties.Multilib.Both)
730 depsList = append(depsList, ApexNativeDependencies{
731 Native_shared_libs: a.properties.Native_shared_libs,
732 Tests: a.properties.Tests,
733 Jni_libs: a.properties.Jni_libs,
734 Binaries: nil,
735 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900736
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900737 // Add native modules targeting the first ABI When multilib.* is omitted for
738 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900739 isPrimaryAbi := i == 0
740 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900741 depsList = append(depsList, a.properties.Multilib.First)
742 depsList = append(depsList, ApexNativeDependencies{
743 Native_shared_libs: nil,
744 Tests: nil,
745 Jni_libs: nil,
746 Binaries: a.properties.Binaries,
747 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900748 }
749
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900750 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900751 switch target.Arch.ArchType.Multilib {
752 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900753 depsList = append(depsList, a.properties.Multilib.Lib32)
754 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900755 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900756 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900757 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900758 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900759 }
760 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761
Jiyong Park59140302020-12-14 18:44:04 +0900762 // Add native modules targeting a specific arch variant
763 switch target.Arch.ArchType {
764 case android.Arm:
765 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
766 case android.Arm64:
767 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
768 case android.X86:
769 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
770 case android.X86_64:
771 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
772 default:
773 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
774 }
775
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900776 for _, d := range depsList {
777 addDependenciesForNativeModules(ctx, d, target, imageVariation)
778 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000779 ctx.AddFarVariationDependencies([]blueprint.Variation{
780 {Mutator: "os", Variation: target.OsVariation()},
781 {Mutator: "arch", Variation: target.ArchVariation()},
782 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900783 }
784
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900785 // Common-arch dependencies come next
786 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Jiyong Park12a719c2021-01-07 15:31:24 +0900787 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000788 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100789}
790
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900791// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900792func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
793 if a.overridableProperties.Allowed_files != nil {
794 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100795 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900796
797 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
798 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800799 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900800 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900801 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.overridableProperties.Bootclasspath_fragments...)
802 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.overridableProperties.Systemserverclasspath_fragments...)
803 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.overridableProperties.Java_libs...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700804 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
805 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
806 // regardless of the TARGET_PREFER_* setting. See b/144532908
807 arches := ctx.DeviceConfig().Arches()
808 if len(arches) != 0 {
809 archForPrebuiltEtc := arches[0]
810 for _, arch := range arches {
811 // Prefer 64-bit arch if there is any
812 if arch.ArchType.Multilib == "lib64" {
813 archForPrebuiltEtc = arch
814 break
815 }
816 }
817 ctx.AddFarVariationDependencies([]blueprint.Variation{
818 {Mutator: "os", Variation: ctx.Os().String()},
819 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
820 }, prebuiltTag, prebuilts...)
821 }
822 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700823
824 // Dependencies for signing
825 if String(a.overridableProperties.Key) == "" {
826 ctx.PropertyErrorf("key", "missing")
827 return
828 }
829 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
830
831 cert := android.SrcIsModule(a.getCertString(ctx))
832 if cert != "" {
833 ctx.AddDependency(ctx.Module(), certificateTag, cert)
834 // empty cert is not an error. Cert and private keys will be directly found under
835 // PRODUCT_DEFAULT_DEV_CERTIFICATE
836 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100837}
838
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900839type ApexBundleInfo struct {
840 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100841}
842
Paul Duffin949abc02020-12-08 10:34:30 +0000843var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900844
Paul Duffina7d6a892020-12-07 17:39:59 +0000845var _ ApexInfoMutator = (*apexBundle)(nil)
846
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100847func (a *apexBundle) ApexVariationName() string {
848 return a.properties.ApexVariationName
849}
850
Paul Duffina7d6a892020-12-07 17:39:59 +0000851// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900852// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
853// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
854// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
855// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000856//
857// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
858// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
859// The apexMutator uses that list to create module variants for the apexes to which it belongs.
860// The relationship between module variants and apexes is not one-to-one as variants will be
861// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000862func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900863
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900864 // The VNDK APEX is special. For the APEX, the membership is described in a very different
865 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
866 // libraries are self-identified by their vndk.enabled properties. There is no need to run
867 // this mutator for the APEX as nothing will be collected. So, let's return fast.
868 if a.vndkApex {
869 return
870 }
871
872 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
873 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
874 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
875 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
876 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900877 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
878 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900879 if proptools.Bool(a.properties.Use_vndk_as_stable) {
880 if !useVndk {
881 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
882 }
883 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
884 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
885 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
886 }
887 })
888 if mctx.Failed() {
889 return
890 }
Jooyung Handf78e212020-07-22 15:54:47 +0900891 }
892
Colin Cross56a83212020-09-15 18:30:11 -0700893 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900894 am, ok := child.(android.ApexModule)
895 if !ok || !am.CanHaveApexVariants() {
896 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900897 }
Paul Duffin573989d2021-03-17 13:25:29 +0000898 depTag := mctx.OtherModuleDependencyTag(child)
899
900 // Check to see if the tag always requires that the child module has an apex variant for every
901 // apex variant of the parent module. If it does not then it is still possible for something
902 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
903 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
904 return true
905 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000906 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900907 return false
908 }
Jooyung Handf78e212020-07-22 15:54:47 +0900909 if excludeVndkLibs {
910 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
911 return false
912 }
913 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900914 // By default, all the transitive dependencies are collected, unless filtered out
915 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700916 return true
917 }
918
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900919 // Records whether a certain module is included in this apexBundle via direct dependency or
920 // inndirect dependency.
921 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700922 mctx.WalkDeps(func(child, parent android.Module) bool {
923 if !continueApexDepsWalk(child, parent) {
924 return false
925 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900926 // If the parent is apexBundle, this child is directly depended.
927 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900928 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700929 contents[depName] = contents[depName].Add(directDep)
930 return true
931 })
932
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900933 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900934 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700935 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
936 Contents: apexContents,
937 })
938
Jooyung Haned124c32021-01-26 11:43:46 +0900939 minSdkVersion := a.minSdkVersion(mctx)
940 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
941 if minSdkVersion.IsNone() {
942 minSdkVersion = android.FutureApiLevel
943 }
944
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900945 // This is the main part of this mutator. Mark the collected dependencies that they need to
946 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900947
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100948 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
949 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700950 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100951 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900952 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700953 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900954 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100955 InApexVariants: []string{apexVariationName},
956 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700957 ApexContents: []*android.ApexContents{apexContents},
958 }
Colin Cross56a83212020-09-15 18:30:11 -0700959 mctx.WalkDeps(func(child, parent android.Module) bool {
960 if !continueApexDepsWalk(child, parent) {
961 return false
962 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900963 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900964 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900965 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900966}
967
Paul Duffina7d6a892020-12-07 17:39:59 +0000968type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100969 // ApexVariationName returns the name of the APEX variation to use in the apex
970 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
971 ApexVariationName() string
972
Paul Duffina7d6a892020-12-07 17:39:59 +0000973 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
974 // depended upon by an apex and which require an apex specific variant.
975 ApexInfoMutator(android.TopDownMutatorContext)
976}
977
978// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
979// specific variant to modules that support the ApexInfoMutator.
Spandan Das42e89502022-05-06 22:12:55 +0000980// It also propagates updatable=true to apps of updatable apexes
Paul Duffina7d6a892020-12-07 17:39:59 +0000981func apexInfoMutator(mctx android.TopDownMutatorContext) {
982 if !mctx.Module().Enabled() {
983 return
984 }
985
986 if a, ok := mctx.Module().(ApexInfoMutator); ok {
987 a.ApexInfoMutator(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +0000988 }
Spandan Das42e89502022-05-06 22:12:55 +0000989 enforceAppUpdatability(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +0000990}
991
Spandan Das66773252022-01-15 00:23:18 +0000992// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
993// This check is enforced for updatable modules
994func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
995 if !mctx.Module().Enabled() {
996 return
997 }
Spandan Das08c911f2022-01-21 22:07:26 +0000998 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +0000999 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001000 // b/208656169 Do not propagate strict updatability linting to libcore/
1001 // These libs are available on the classpath during compilation
1002 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1003 // Only skip libraries defined in libcore root, not subdirectories
1004 if mctx.OtherModuleDir(child) == "libcore" {
1005 // Do not traverse transitive deps of libcore/ libs
1006 return false
1007 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001008 if android.InList(child.Name(), skipLintJavalibAllowlist) {
1009 return false
1010 }
Spandan Das66773252022-01-15 00:23:18 +00001011 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1012 lintable.SetStrictUpdatabilityLinting(true)
1013 }
1014 // visit transitive deps
1015 return true
1016 })
1017 }
1018}
1019
Spandan Das42e89502022-05-06 22:12:55 +00001020// enforceAppUpdatability propagates updatable=true to apps of updatable apexes
1021func enforceAppUpdatability(mctx android.TopDownMutatorContext) {
1022 if !mctx.Module().Enabled() {
1023 return
1024 }
1025 if apex, ok := mctx.Module().(*apexBundle); ok && apex.Updatable() {
1026 // checking direct deps is sufficient since apex->apk is a direct edge, even when inherited via apex_defaults
1027 mctx.VisitDirectDeps(func(module android.Module) {
1028 // ignore android_test_app
1029 if app, ok := module.(*java.AndroidApp); ok {
1030 app.SetUpdatable(true)
1031 }
1032 })
1033 }
1034}
1035
Spandan Das08c911f2022-01-21 22:07:26 +00001036// TODO: b/215736885 Whittle the denylist
1037// Transitive deps of certain mainline modules baseline NewApi errors
1038// Skip these mainline modules for now
1039var (
1040 skipStrictUpdatabilityLintAllowlist = []string{
1041 "com.android.art",
1042 "com.android.art.debug",
1043 "com.android.conscrypt",
1044 "com.android.media",
1045 // test apexes
1046 "test_com.android.art",
1047 "test_com.android.conscrypt",
1048 "test_com.android.media",
1049 "test_jitzygote_com.android.art",
1050 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001051
1052 // TODO: b/215736885 Remove this list
1053 skipLintJavalibAllowlist = []string{
1054 "conscrypt.module.platform.api.stubs",
1055 "conscrypt.module.public.api.stubs",
1056 "conscrypt.module.public.api.stubs.system",
1057 "conscrypt.module.public.api.stubs.module_lib",
1058 "framework-media.stubs",
1059 "framework-media.stubs.system",
1060 "framework-media.stubs.module_lib",
1061 }
Spandan Das08c911f2022-01-21 22:07:26 +00001062)
1063
1064func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1065 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1066}
1067
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001068// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1069// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1070// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001071func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1072 if !mctx.Module().Enabled() {
1073 return
1074 }
1075 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001076 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1077 }
1078}
1079
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001080// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1081// the apex in order to retrieve its contents later.
1082// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001083func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1084 if !mctx.Module().Enabled() {
1085 return
1086 }
Colin Cross56a83212020-09-15 18:30:11 -07001087 if am, ok := mctx.Module().(android.ApexModule); ok {
1088 if testFor := am.TestFor(); len(testFor) > 0 {
1089 mctx.AddFarVariationDependencies([]blueprint.Variation{
1090 {Mutator: "os", Variation: am.Target().OsVariation()},
1091 {"arch", "common"},
1092 }, testForTag, testFor...)
1093 }
1094 }
1095}
1096
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001097// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001098func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1099 if !mctx.Module().Enabled() {
1100 return
1101 }
Colin Cross56a83212020-09-15 18:30:11 -07001102 if _, ok := mctx.Module().(android.ApexModule); ok {
1103 var contents []*android.ApexContents
1104 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1105 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1106 contents = append(contents, abInfo.Contents)
1107 }
1108 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1109 ApexContents: contents,
1110 })
Colin Crossaede88c2020-08-11 12:17:01 -07001111 }
1112}
1113
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001114// markPlatformAvailability marks whether or not a module can be available to platform. A module
1115// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1116// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1117// be) available to platform
1118// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001119func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1120 // Host and recovery are not considered as platform
1121 if mctx.Host() || mctx.Module().InstallInRecovery() {
1122 return
1123 }
1124
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001125 am, ok := mctx.Module().(android.ApexModule)
1126 if !ok {
1127 return
1128 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001129
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001130 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001131
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001132 // If any of the dep is not available to platform, this module is also considered as being
1133 // not available to platform even if it has "//apex_available:platform"
1134 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001135 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001136 // if the dependency crosses apex boundary, don't consider it
1137 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001138 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001139 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1140 availableToPlatform = false
1141 // TODO(b/154889534) trigger an error when 'am' has
1142 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001143 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001144 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001145
Paul Duffinb5769c12021-05-12 16:16:51 +01001146 // Exception 1: check to see if the module always requires it.
1147 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001148 availableToPlatform = true
1149 }
1150
1151 // Exception 2: bootstrap bionic libraries are also always available to platform
1152 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1153 availableToPlatform = true
1154 }
1155
1156 if !availableToPlatform {
1157 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001158 }
1159}
1160
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001161// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001162// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001163func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001164 if !mctx.Module().Enabled() {
1165 return
1166 }
Colin Cross56a83212020-09-15 18:30:11 -07001167
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001168 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001169 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001170 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001171 return
1172 }
1173
1174 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001175 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1176 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001177 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001178 if strings.HasPrefix(apexBundleName, "com.android.art") {
1179 // Create an alias from the platform variant. This is done to make
1180 // test_for dependencies work for modules that are split by the APEX
1181 // mutator, since test_for dependencies always go to the platform variant.
1182 // This doesn't happen for normal APEXes that are disjunct, so only do
1183 // this for the overlapping ART APEXes.
1184 // TODO(b/183882457): Remove this if the test_for functionality is
1185 // refactored to depend on the proper APEX variants instead of platform.
1186 mctx.CreateAliasVariation("", apexBundleName)
1187 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001188 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1189 apexBundleName := o.GetOverriddenModuleName()
1190 if apexBundleName == "" {
1191 mctx.ModuleErrorf("base property is not set")
1192 return
1193 }
1194 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001195 if strings.HasPrefix(apexBundleName, "com.android.art") {
1196 // TODO(b/183882457): See note for CreateAliasVariation above.
1197 mctx.CreateAliasVariation("", apexBundleName)
1198 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001199 }
1200}
Sundong Ahne9b55722019-09-06 17:37:42 +09001201
Paul Duffin6717d882021-06-15 19:09:41 +01001202// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1203// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001204func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001205 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001206 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001207 return !a.vndkApex
1208 }
1209
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001210 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001211}
1212
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001213// See android.UpdateDirectlyInAnyApex
1214// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001215func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1216 if !mctx.Module().Enabled() {
1217 return
1218 }
1219 if am, ok := mctx.Module().(android.ApexModule); ok {
1220 android.UpdateDirectlyInAnyApex(mctx, am)
1221 }
1222}
1223
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001224// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001225type apexPackaging int
1226
1227const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001228 // imageApex is a packaging method where contents are included in a filesystem image which
1229 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001230 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001231
1232 // zipApex is a packaging method where contents are directly included in the zip container.
1233 // This is used for host-side testing - because the contents are easily accessible by
1234 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001235 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001236
1237 // flattendApex is a packaging method where contents are not included in the APEX file, but
1238 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1239 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001240 flattenedApex
1241)
1242
1243const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001244 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001245 imageApexSuffix = ".apex"
1246 imageCapexSuffix = ".capex"
1247 zipApexSuffix = ".zipapex"
1248 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001249
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001250 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001251 imageApexType = "image"
1252 zipApexType = "zip"
1253 flattenedApexType = "flattened"
1254
Dan Willemsen47e1a752021-10-16 18:36:13 -07001255 ext4FsType = "ext4"
1256 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001257 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001258)
1259
1260// The suffix for the output "file", not the module
1261func (a apexPackaging) suffix() string {
1262 switch a {
1263 case imageApex:
1264 return imageApexSuffix
1265 case zipApex:
1266 return zipApexSuffix
1267 default:
1268 panic(fmt.Errorf("unknown APEX type %d", a))
1269 }
1270}
1271
1272func (a apexPackaging) name() string {
1273 switch a {
1274 case imageApex:
1275 return imageApexType
1276 case zipApex:
1277 return zipApexType
1278 default:
1279 panic(fmt.Errorf("unknown APEX type %d", a))
1280 }
1281}
1282
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001283// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1284// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001285func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001286 if !mctx.Module().Enabled() {
1287 return
1288 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001289 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001290 var variants []string
1291 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1292 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001293 // This is the normal case. Note that both image and flattend APEXes are
1294 // created. The image type is installed to the system partition, while the
1295 // flattened APEX is (optionally) installed to the system_ext partition.
1296 // This is mostly for GSI which has to support wide range of devices. If GSI
1297 // is installed on a newer (APEX-capable) device, the image APEX in the
1298 // system will be used. However, if the same GSI is installed on an old
1299 // device which can't support image APEX, the flattened APEX in the
1300 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001301 variants = append(variants, imageApexType, flattenedApexType)
1302 case "zip":
1303 variants = append(variants, zipApexType)
1304 case "both":
1305 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1306 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001307 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001308 return
1309 }
1310
1311 modules := mctx.CreateLocalVariations(variants...)
1312
1313 for i, v := range variants {
1314 switch v {
1315 case imageApexType:
1316 modules[i].(*apexBundle).properties.ApexType = imageApex
1317 case zipApexType:
1318 modules[i].(*apexBundle).properties.ApexType = zipApex
1319 case flattenedApexType:
1320 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001321 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001322 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001323 modules[i].(*apexBundle).MakeAsSystemExt()
1324 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001325 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001326 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001327 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001328 // payload_type is forcibly overridden to "image"
1329 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001330 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001331 }
1332}
1333
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001334var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001335
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001336// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001337func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1338 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001339 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001340 return true
1341}
1342
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001343var _ android.OutputFileProducer = (*apexBundle)(nil)
1344
1345// Implements android.OutputFileProducer
1346func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1347 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001348 case "", android.DefaultDistTag:
1349 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001350 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001351 case imageApexSuffix:
1352 // uncompressed one
1353 if a.outputApexFile != nil {
1354 return android.Paths{a.outputApexFile}, nil
1355 }
1356 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001357 default:
1358 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1359 }
1360}
1361
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001362var _ multitree.Exportable = (*apexBundle)(nil)
1363
1364func (a *apexBundle) Exportable() bool {
1365 if a.properties.ApexType == flattenedApex {
1366 return false
1367 }
1368 return true
1369}
1370
1371func (a *apexBundle) TaggedOutputs() map[string]android.Paths {
1372 ret := make(map[string]android.Paths)
1373 ret["apex"] = android.Paths{a.outputFile}
1374 return ret
1375}
1376
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001377var _ cc.Coverage = (*apexBundle)(nil)
1378
1379// Implements cc.Coverage
1380func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1381 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1382}
1383
1384// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001385func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001386 a.properties.PreventInstall = true
1387}
1388
1389// Implements cc.Coverage
1390func (a *apexBundle) HideFromMake() {
1391 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001392 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1393 // TODO(ccross): untangle these
1394 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001395}
1396
1397// Implements cc.Coverage
1398func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1399 a.properties.IsCoverageVariant = coverage
1400}
1401
1402// Implements cc.Coverage
1403func (a *apexBundle) EnableCoverageIfNeeded() {}
1404
1405var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1406
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001407// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001408func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001409 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001410}
1411
Jiyong Parkf4020582021-11-29 12:37:10 +09001412func (a *apexBundle) FutureUpdatable() bool {
1413 return proptools.BoolDefault(a.properties.Future_updatable, false)
1414}
1415
Jiyong Park1bc84122021-06-22 20:23:05 +09001416func (a *apexBundle) UsePlatformApis() bool {
1417 return proptools.BoolDefault(a.properties.Platform_apis, false)
1418}
1419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001420// getCertString returns the name of the cert that should be used to sign this APEX. This is
1421// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001422func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001423 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001424 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1425 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1426 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001427 if a.vndkApex {
1428 moduleName = vndkApexName
1429 }
1430 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001431 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001432 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001433 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001434 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001435}
1436
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001437// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001438func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001439 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001440}
1441
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001442// See the generate_hashtree property
1443func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001444 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001445}
1446
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001447// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001448func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1449 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1450}
1451
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001452// See the test_only_force_compression property
1453func (a *apexBundle) testOnlyShouldForceCompression() bool {
1454 return proptools.Bool(a.properties.Test_only_force_compression)
1455}
1456
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001457// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1458// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1459// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001460
Jiyong Parkf97782b2019-02-13 20:28:58 +09001461func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1462 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1463 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1464 }
1465}
1466
Jiyong Park388ef3f2019-01-28 19:47:32 +09001467func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001468 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1469 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001470 }
1471
1472 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001473 globalSanitizerNames := []string{}
1474 if a.Host() {
1475 globalSanitizerNames = ctx.Config().SanitizeHost()
1476 } else {
1477 arches := ctx.Config().SanitizeDeviceArch()
1478 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1479 globalSanitizerNames = ctx.Config().SanitizeDevice()
1480 }
1481 }
1482 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001483}
1484
Jooyung Han8ce8db92020-05-15 19:05:05 +09001485func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001486 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1487 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001488 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001489 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001490 for _, target := range ctx.MultiTargets() {
1491 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001492 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Cross4c4c1be2022-02-10 11:41:18 -08001493 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001494 Tests: nil,
1495 Jni_libs: nil,
1496 Binaries: nil,
1497 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001498 break
1499 }
1500 }
1501 }
1502}
1503
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001504// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1505// returned apexFile saves information about the Soong module that will be used for creating the
1506// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001507func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001508 // Decide the APEX-local directory by the multilib of the library In the future, we may
1509 // query this to the module.
1510 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001511 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001512 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001513 case "lib32":
1514 dirInApex = "lib"
1515 case "lib64":
1516 dirInApex = "lib64"
1517 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001518 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001519 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001520 }
Jooyung Han35155c42020-02-06 17:33:20 +09001521 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001522 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001523 // Special case for Bionic libs and other libs installed with them. This is to
1524 // prevent those libs from being included in the search path
1525 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1526 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1527 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1528 // will be loaded into the default linker namespace (aka "platform" namespace). If
1529 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1530 // be loaded again into the runtime linker namespace, which will result in double
1531 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001532 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001533 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001534
Jiyong Parkf653b052019-11-18 15:39:01 +09001535 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001536 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1537 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001538}
1539
Jiyong Park1833cef2019-12-13 13:28:36 +09001540func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001541 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001542 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001543 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001544 }
Jooyung Han35155c42020-02-06 17:33:20 +09001545 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001546 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001547 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1548 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001549 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001550 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001551 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001552}
1553
Jiyong Park99644e92020-11-17 22:21:02 +09001554func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1555 dirInApex := "bin"
1556 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1557 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1558 }
1559 fileToCopy := rustm.OutputFile().Path()
1560 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1561 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1562 return af
1563}
1564
1565func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1566 // Decide the APEX-local directory by the multilib of the library
1567 // In the future, we may query this to the module.
1568 var dirInApex string
1569 switch rustm.Arch().ArchType.Multilib {
1570 case "lib32":
1571 dirInApex = "lib"
1572 case "lib64":
1573 dirInApex = "lib64"
1574 }
1575 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1576 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1577 }
1578 fileToCopy := rustm.OutputFile().Path()
1579 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1580 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1581}
1582
Jiyong Park1833cef2019-12-13 13:28:36 +09001583func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001584 dirInApex := "bin"
1585 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001586 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001587}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001588
Jiyong Park1833cef2019-12-13 13:28:36 +09001589func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001590 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001591 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001592 // NB: Since go binaries are static we don't need the module for anything here, which is
1593 // good since the go tool is a blueprint.Module not an android.Module like we would
1594 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001595 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001596}
1597
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001598func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001599 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001600 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1601 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1602 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001603 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001604 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001605 af.symlinks = sh.Symlinks()
1606 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001607}
1608
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001609func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001610 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001611 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001612 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001613}
1614
atrost6e126252020-01-27 17:01:16 +00001615func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1616 dirInApex := filepath.Join("etc", config.SubDir())
1617 fileToCopy := config.CompatConfig()
1618 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1619}
1620
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001621// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1622// way.
1623type javaModule interface {
1624 android.Module
1625 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001626 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001627 JacocoReportClassesFile() android.Path
1628 LintDepSets() java.LintDepSets
1629 Stem() string
1630}
1631
1632var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001633var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001634var _ javaModule = (*java.SdkLibrary)(nil)
1635var _ javaModule = (*java.DexImport)(nil)
1636var _ javaModule = (*java.SdkLibraryImport)(nil)
1637
Paul Duffin190fdef2021-04-26 10:33:59 +01001638// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001639func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001640 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001641}
1642
1643// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1644func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001645 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001646 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001647 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1648 af.lintDepSets = module.LintDepSets()
1649 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001650 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1651 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1652 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1653 }
1654 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001655 return af
1656}
1657
1658// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1659// the same way.
1660type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 android.Module
1662 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001663 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001664 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001665 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001666 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001667 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001668 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001669}
1670
1671var _ androidApp = (*java.AndroidApp)(nil)
1672var _ androidApp = (*java.AndroidAppImport)(nil)
1673
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +00001674func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string {
1675 buildId := ctx.Config().BuildId()
1676
1677 // The build ID is used as a suffix for a filename, so ensure that
1678 // the set of characters being used are sanitized.
1679 // - any word character: [a-zA-Z0-9_]
1680 // - dots: .
1681 // - dashes: -
1682 validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`)
1683 if !validRegex.MatchString(buildId) {
1684 ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId)
1685 }
1686 return buildId
1687}
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001688
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001689func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001690 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001692 appDir = "priv-app"
1693 }
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001694
1695 // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed
1696 // so that PackageManager correctly invalidates the existing installed apk
1697 // in favour of the new APK-in-APEX. See bugs for more information.
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +00001698 dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx))
Jiyong Parkf653b052019-11-18 15:39:01 +09001699 fileToCopy := aapp.OutputFile()
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001700
Yo Chiange8128052020-07-23 20:09:18 +08001701 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001702 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001703 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001704 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001705
1706 if app, ok := aapp.(interface {
1707 OverriddenManifestPackageName() string
1708 }); ok {
1709 af.overriddenPackageName = app.OverriddenManifestPackageName()
1710 }
Jiyong Park618922e2020-01-08 13:35:43 +09001711 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001712}
1713
Jiyong Park69aeba92020-04-24 21:16:36 +09001714func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1715 rroDir := "overlay"
1716 dirInApex := filepath.Join(rroDir, rro.Theme())
1717 fileToCopy := rro.OutputFile()
1718 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1719 af.certificate = rro.Certificate()
1720
1721 if a, ok := rro.(interface {
1722 OverriddenManifestPackageName() string
1723 }); ok {
1724 af.overriddenPackageName = a.OverriddenManifestPackageName()
1725 }
1726 return af
1727}
1728
Ken Chenfad7f9d2021-11-10 22:02:57 +08001729func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1730 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001731 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1732}
1733
Jiyong Park12a719c2021-01-07 15:31:24 +09001734func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1735 dirInApex := filepath.Join("etc", "fs")
1736 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1737}
1738
Paul Duffin064b70c2020-11-02 17:32:38 +00001739// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001740// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1741// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1742// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001743func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001744 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001745 am, ok := child.(android.ApexModule)
1746 if !ok || !am.CanHaveApexVariants() {
1747 return false
1748 }
1749
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001750 // Filter-out unwanted depedendencies
1751 depTag := ctx.OtherModuleDependencyTag(child)
1752 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1753 return false
1754 }
1755 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001756 return false
1757 }
1758
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001759 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001760 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001761
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001762 // Visit actually
1763 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001764 })
1765}
1766
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001767// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1768type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001769
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001770const (
1771 ext4 fsType = iota
1772 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001773 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001774)
Artur Satayev849f8442020-04-28 14:57:42 +01001775
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001776func (f fsType) string() string {
1777 switch f {
1778 case ext4:
1779 return ext4FsType
1780 case f2fs:
1781 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001782 case erofs:
1783 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001784 default:
1785 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001786 }
1787}
1788
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001789// Creates build rules for an APEX. It consists of the following major steps:
1790//
1791// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1792// 2) traverse the dependency tree to collect apexFile structs from them.
1793// 3) some fields in apexBundle struct are configured
1794// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001795func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001796 ////////////////////////////////////////////////////////////////////////////////////////////
1797 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001798 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001799 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001800 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001801 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001802 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001803 if len(a.properties.Tests) > 0 && !a.testApex {
1804 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1805 return
1806 }
Jiyong Park678c8812020-02-07 17:25:49 +09001807
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001808 ////////////////////////////////////////////////////////////////////////////////////////////
1809 // 2) traverse the dependency tree to collect apexFile structs from them.
1810
1811 // all the files that will be included in this APEX
1812 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001813
Jooyung Hane1633032019-08-01 17:41:43 +09001814 // native lib dependencies
1815 var provideNativeLibs []string
1816 var requireNativeLibs []string
1817
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001818 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1819
braleeb0c1f0c2021-06-07 22:49:13 +08001820 // Collect the module directory for IDE info in java/jdeps.go.
1821 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1822
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001823 // TODO(jiyong): do this using WalkPayloadDeps
1824 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001825 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001826 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001827 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1828 return false
1829 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001830 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1831 return false
1832 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001833 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001834 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001835 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001836 case sharedLibTag, jniLibTag:
1837 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001838 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001839 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1840 fi.isJniLib = isJniLib
1841 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001842 // Collect the list of stub-providing libs except:
1843 // - VNDK libs are only for vendors
1844 // - bootstrap bionic libs are treated as provided by system
1845 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001846 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001847 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001848 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001849 } else if r, ok := child.(*rust.Module); ok {
1850 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001851 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001852 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001853 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001854 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001855 propertyName := "native_shared_libs"
1856 if isJniLib {
1857 propertyName = "jni_libs"
1858 }
1859 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001860 }
1861 case executableTag:
1862 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001863 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001864 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001865 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001866 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001867 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001868 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001869 } else if rust, ok := child.(*rust.Module); ok {
1870 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1871 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001872 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001873 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1874 }
1875 case shBinaryTag:
1876 if sh, ok := child.(*sh.ShBinary); ok {
1877 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1878 } else {
1879 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001880 }
Paul Duffin94f19632021-04-20 12:40:07 +01001881 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001882 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001883 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1884 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001885 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001886 return false
1887 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001888
Paul Duffincc33ec82021-04-25 23:14:55 +01001889 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1890 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001891 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1892 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1893 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001894 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001895 }
satayev333a1732021-05-17 21:35:26 +01001896 case sscpfTag:
1897 {
1898 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1899 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1900 return false
1901 }
satayevb98371c2021-06-15 16:49:50 +01001902 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1903 filesInfo = append(filesInfo, *af)
1904 }
satayev333a1732021-05-17 21:35:26 +01001905 return true
1906 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001907 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001908 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001909 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001910 af := apexFileForJavaModule(ctx, child.(javaModule))
1911 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001912 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1913 return false
1914 }
1915 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001916 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001917 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001918 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001919 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001920 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001921 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001922 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001923 return true // track transitive dependencies
1924 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001925 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001926 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001927 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001928 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1929 appDir := "app"
1930 if ap.Privileged() {
1931 appDir = "priv-app"
1932 }
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001933 // TODO(b/224589412, b/226559955): Ensure that the dirname is
1934 // suffixed so that PackageManager correctly invalidates the
1935 // existing installed apk in favour of the new APK-in-APEX.
1936 // See bugs for more information.
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +00001937 appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx))
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001938 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap)
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001939 af.certificate = java.PresignedCertificate
1940 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001941 } else {
1942 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1943 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001944 case rroTag:
1945 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1946 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1947 } else {
1948 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1949 }
markchien2f59ec92020-09-02 16:23:38 +08001950 case bpfTag:
1951 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1952 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001953 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001954 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001955 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001956 }
1957 } else {
1958 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1959 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001960 case fsTag:
1961 if fs, ok := child.(filesystem.Filesystem); ok {
1962 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1963 } else {
1964 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1965 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001966 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001967 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001968 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001969 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001970 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001971 }
Paul Duffin0b817782021-03-17 15:02:19 +00001972 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001973 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1974 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1975 } else {
1976 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1977 }
Roland Levillain630846d2019-06-26 12:48:34 +01001978 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001979 if ccTest, ok := child.(*cc.Module); ok {
1980 if ccTest.IsTestPerSrcAllTestsVariation() {
1981 // Multiple-output test module (where `test_per_src: true`).
1982 //
1983 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1984 // We do not add this variation to `filesInfo`, as it has no output;
1985 // however, we do add the other variations of this module as indirect
1986 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001987 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001988 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001989 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001990 af.class = nativeTest
1991 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001992 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001993 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001994 } else {
1995 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1996 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001997 case keyTag:
1998 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001999 a.privateKeyFile = key.privateKeyFile
2000 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09002001 } else {
2002 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002003 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002004 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002005 case certificateTag:
2006 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002007 a.containerCertificateFile = dep.Certificate.Pem
2008 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002009 } else {
2010 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2011 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002012 case android.PrebuiltDepTag:
2013 // If the prebuilt is force disabled, remember to delete the prebuilt file
2014 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002015 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002016 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2017 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002018 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002019 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002020 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002021 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002022 // We cannot use a switch statement on `depTag` here as the checked
2023 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002024 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002025 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09002026 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002027 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002028 return false
2029 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002030 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2031 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002032
2033 // Always track transitive dependencies for host.
2034 if a.Host() {
2035 filesInfo = append(filesInfo, af)
2036 return true
2037 }
2038
Colin Cross56a83212020-09-15 18:30:11 -07002039 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002040 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002041 // If the dependency is a stubs lib, don't include it in this APEX,
2042 // but make sure that the lib is installed on the device.
2043 // In case no APEX is having the lib, the lib is installed to the system
2044 // partition.
2045 //
2046 // Always include if we are a host-apex however since those won't have any
2047 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002048 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002049 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00002050 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002051 if !android.InList(name, a.requiredDeps) {
2052 a.requiredDeps = append(a.requiredDeps, name)
2053 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002054 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002055 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002056 // Don't track further
2057 return false
2058 }
Jiyong Parke3867542020-12-03 17:28:25 +09002059
2060 // If the dep is not considered to be in the same
2061 // apex, don't add it to filesInfo so that it is not
2062 // included in this APEX.
2063 // TODO(jiyong): move this to at the top of the
2064 // else-if clause for the indirect dependencies.
2065 // Currently, that's impossible because we would
2066 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002067 // DepIsInSameAPex is false. We also shouldn't do
2068 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002069 //
2070 // TODO(jiyong): explain why the same module is passed in twice.
2071 // Switching the first am to parent breaks lots of tests.
2072 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002073 return false
2074 }
2075
Jiyong Parkf653b052019-11-18 15:39:01 +09002076 filesInfo = append(filesInfo, af)
2077 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002078 } else if rm, ok := child.(*rust.Module); ok {
2079 af := apexFileForRustLibrary(ctx, rm)
2080 af.transitiveDep = true
2081 filesInfo = append(filesInfo, af)
2082 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002083 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002084 } else if cc.IsTestPerSrcDepTag(depTag) {
2085 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002086 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002087 // Handle modules created as `test_per_src` variations of a single test module:
2088 // use the name of the generated test binary (`fileToCopy`) instead of the name
2089 // of the original test module (`depName`, shared by all `test_per_src`
2090 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002091 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002092 // these are not considered transitive dep
2093 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002094 filesInfo = append(filesInfo, af)
2095 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002096 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002097 } else if cc.IsHeaderDepTag(depTag) {
2098 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002099 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002100 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2101 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002102 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002103 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002104 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2105 }
Jiyong Park99644e92020-11-17 22:21:02 +09002106 } else if rust.IsDylibDepTag(depTag) {
2107 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2108 af := apexFileForRustLibrary(ctx, rustm)
2109 af.transitiveDep = true
2110 filesInfo = append(filesInfo, af)
2111 return true // track transitive dependencies
2112 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002113 } else if rust.IsRlibDepTag(depTag) {
2114 // Rlib is statically linked, but it might have shared lib
2115 // dependencies. Track them.
2116 return true
Paul Duffin65898052021-04-20 22:47:03 +01002117 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002118 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002119 switch child.(type) {
2120 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002121 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002122 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002123 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002124 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002125 return false
2126 }
2127 filesInfo = append(filesInfo, af)
2128 return true // track transitive dependencies
2129 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002130 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 +00002131 }
satayev333a1732021-05-17 21:35:26 +01002132 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2133 // Add the contents of the systemserverclasspath fragment to the apex.
2134 switch child.(type) {
2135 case *java.Library, *java.SdkLibrary:
2136 af := apexFileForJavaModule(ctx, child.(javaModule))
2137 filesInfo = append(filesInfo, af)
2138 return true // track transitive dependencies
2139 default:
2140 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2141 }
Colin Cross56a83212020-09-15 18:30:11 -07002142 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2143 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002144 } else if depTag == android.DarwinUniversalVariantTag {
2145 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002146 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002147 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002148 }
2149 }
2150 }
2151 return false
2152 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002153 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002154 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002155 return
2156 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002157
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002158 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002159 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002160 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002161 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002162 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002163 if e, ok := encountered[dest]; !ok {
2164 encountered[dest] = f
2165 } else {
2166 // If a module is directly included and also transitively depended on
2167 // consider it as directly included.
2168 e.transitiveDep = e.transitiveDep && f.transitiveDep
2169 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002170 }
2171 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002172 var result []apexFile
2173 for _, v := range encountered {
2174 result = append(result, v)
2175 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002176 return result
2177 }
2178 filesInfo = removeDup(filesInfo)
2179
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002180 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002181 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002182 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2183 // changes.
2184 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002185 })
2186
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002187 ////////////////////////////////////////////////////////////////////////////////////////////
2188 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002189 a.installDir = android.PathForModuleInstall(ctx, "apex")
2190 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002191
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002192 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002193 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002194 switch a.properties.ApexType {
2195 case imageApex:
2196 if buildFlattenedAsDefault {
2197 a.suffix = imageApexSuffix
2198 } else {
2199 a.suffix = ""
2200 a.primaryApexType = true
2201
2202 if ctx.Config().InstallExtraFlattenedApexes() {
2203 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2204 }
2205 }
2206 case zipApex:
2207 if proptools.String(a.properties.Payload_type) == "zip" {
2208 a.suffix = ""
2209 a.primaryApexType = true
2210 } else {
2211 a.suffix = zipApexSuffix
2212 }
2213 case flattenedApex:
2214 if buildFlattenedAsDefault {
2215 a.suffix = ""
2216 a.primaryApexType = true
2217 } else {
2218 a.suffix = flattenedSuffix
2219 }
2220 }
2221
Theotime Combes4ba38c12020-06-12 12:46:59 +00002222 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2223 case ext4FsType:
2224 a.payloadFsType = ext4
2225 case f2fsFsType:
2226 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002227 case erofsFsType:
2228 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002229 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002230 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 +00002231 }
2232
Jiyong Park7cd10e32020-01-14 09:22:18 +09002233 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2234 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2235 // the same library in the system partition, thus effectively sharing the same libraries
2236 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2237 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002238 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002239
Jooyung Han85d61762020-06-24 23:50:26 +09002240 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2241 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002242 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002243 a.linkToSystemLib = false
2244 }
2245
Jiyong Park4da07972021-01-05 21:01:11 +09002246 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002247 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002248
Jiyong Park9d677202020-02-19 16:29:35 +09002249 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002250 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002251 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002252 a.linkToSystemLib = false
2253 }
2254
Jiyong Park638d30e2020-02-26 18:27:19 +09002255 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2256 if ctx.Host() {
2257 a.linkToSystemLib = false
2258 }
2259
Colin Cross6340ea52021-11-04 12:01:18 -07002260 if a.properties.ApexType != zipApex {
2261 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2262 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002263
2264 ////////////////////////////////////////////////////////////////////////////////////////////
2265 // 4) generate the build rules to create the APEX. This is done in builder.go.
2266 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002267 if a.properties.ApexType == flattenedApex {
2268 a.buildFlattenedApex(ctx)
2269 } else {
2270 a.buildUnflattenedApex(ctx)
2271 }
Jiyong Park956305c2020-01-09 12:32:06 +09002272 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002273 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002274
2275 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2276 if a.installable() {
2277 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2278 // along with other ordinary files. (Note that this is done by apexer for
2279 // non-flattened APEXes)
2280 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2281
2282 // Place the public key as apex_pubkey. This is also done by apexer for
2283 // non-flattened APEXes case.
2284 // TODO(jiyong): Why do we need this CP rule?
2285 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2286 ctx.Build(pctx, android.BuildParams{
2287 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002288 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002289 Output: copiedPubkey,
2290 })
2291 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2292 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002293}
2294
Paul Duffincc33ec82021-04-25 23:14:55 +01002295// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2296// the bootclasspath_fragment contributes to the apex.
2297func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2298 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2299 var filesToAdd []apexFile
2300
2301 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002302 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2303 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2304 dirInApex := filepath.Join("javalib", arch.String())
2305 for _, f := range files {
2306 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2307 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2308 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2309 filesToAdd = append(filesToAdd, af)
2310 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002311 }
2312 }
2313
satayev3db35472021-05-06 23:59:58 +01002314 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002315 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2316 filesToAdd = append(filesToAdd, *af)
2317 }
satayev3db35472021-05-06 23:59:58 +01002318
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002319 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2320 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2321 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2322
2323 if pathOnHost != nil {
2324 // We need to copy the profile to a temporary path with the right filename because the apexer
2325 // will take the filename as is.
2326 ctx.Build(pctx, android.BuildParams{
2327 Rule: android.Cp,
2328 Input: pathOnHost,
2329 Output: tempPath,
2330 })
2331 } else {
2332 // At this point, the boot image profile cannot be generated. It is probably because the boot
2333 // image profile source file does not exist on the branch, or it is not available for the
2334 // current build target.
2335 // However, we cannot enforce the boot image profile to be generated because some build
2336 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2337 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2338 // only if the APEX is being built.
2339 ctx.Build(pctx, android.BuildParams{
2340 Rule: android.ErrorRule,
2341 Output: tempPath,
2342 Args: map[string]string{
2343 "error": "Boot image profile cannot be generated",
2344 },
2345 })
2346 }
2347
2348 androidMkModuleName := filepath.Base(pathInApex)
2349 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2350 filesToAdd = append(filesToAdd, af)
2351 }
2352
Paul Duffincc33ec82021-04-25 23:14:55 +01002353 return filesToAdd
2354}
2355
satayevb98371c2021-06-15 16:49:50 +01002356// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2357// the module contributes to the apex; or nil if the proto config was not generated.
2358func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2359 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2360 if !info.ClasspathFragmentProtoGenerated {
2361 return nil
2362 }
2363 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2364 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2365 return &af
satayev14e49132021-05-17 21:03:07 +01002366}
2367
Paul Duffincc33ec82021-04-25 23:14:55 +01002368// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2369// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002370func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2371 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2372
2373 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2374 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002375 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2376 if err != nil {
2377 ctx.ModuleErrorf("%s", err)
2378 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002379
2380 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2381 // bootclasspath_fragment.
2382 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2383 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002384}
2385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002386///////////////////////////////////////////////////////////////////////////////////////////////////
2387// Factory functions
2388//
2389
2390func newApexBundle() *apexBundle {
2391 module := &apexBundle{}
2392
2393 module.AddProperties(&module.properties)
2394 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002395 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002396 module.AddProperties(&module.overridableProperties)
2397
2398 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2399 android.InitDefaultableModule(module)
2400 android.InitSdkAwareModule(module)
2401 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002402 android.InitBazelModule(module)
Inseob Kim5eb7ee92022-04-27 10:30:34 +09002403 multitree.InitExportableModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002404 return module
2405}
2406
Paul Duffineb8051d2021-10-18 17:49:39 +01002407func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002408 bundle := newApexBundle()
2409 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002410 return bundle
2411}
2412
2413// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2414// certain compatibility checks such as apex_available are not done for apex_test.
2415func testApexBundleFactory() android.Module {
2416 bundle := newApexBundle()
2417 bundle.testApex = true
2418 return bundle
2419}
2420
2421// apex packages other modules into an APEX file which is a packaging format for system-level
2422// components like binaries, shared libraries, etc.
2423func BundleFactory() android.Module {
2424 return newApexBundle()
2425}
2426
2427type Defaults struct {
2428 android.ModuleBase
2429 android.DefaultsModuleBase
2430}
2431
2432// apex_defaults provides defaultable properties to other apex modules.
2433func defaultsFactory() android.Module {
2434 return DefaultsFactory()
2435}
2436
2437func DefaultsFactory(props ...interface{}) android.Module {
2438 module := &Defaults{}
2439
2440 module.AddProperties(props...)
2441 module.AddProperties(
2442 &apexBundleProperties{},
2443 &apexTargetBundleProperties{},
2444 &overridableProperties{},
2445 )
2446
2447 android.InitDefaultsModule(module)
2448 return module
2449}
2450
2451type OverrideApex struct {
2452 android.ModuleBase
2453 android.OverrideModuleBase
Wei Li1c66fc72022-05-09 23:59:14 -07002454 android.BazelModuleBase
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002455}
2456
2457func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2458 // All the overrides happen in the base module.
2459}
2460
2461// override_apex is used to create an apex module based on another apex module by overriding some of
2462// its properties.
Wei Li1c66fc72022-05-09 23:59:14 -07002463func OverrideApexFactory() android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002464 m := &OverrideApex{}
2465
2466 m.AddProperties(&overridableProperties{})
2467
2468 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2469 android.InitOverrideModule(m)
Wei Li1c66fc72022-05-09 23:59:14 -07002470 android.InitBazelModule(m)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002471 return m
2472}
2473
Wei Li1c66fc72022-05-09 23:59:14 -07002474func (o *OverrideApex) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
2475 if ctx.ModuleType() != "override_apex" {
2476 return
2477 }
2478
2479 baseApexModuleName := o.OverrideModuleBase.GetOverriddenModuleName()
2480 baseModule, baseApexExists := ctx.ModuleFromName(baseApexModuleName)
2481 if !baseApexExists {
2482 panic(fmt.Errorf("Base apex module doesn't exist: %s", baseApexModuleName))
2483 }
2484
2485 a, baseModuleIsApex := baseModule.(*apexBundle)
2486 if !baseModuleIsApex {
2487 panic(fmt.Errorf("Base module is not apex module: %s", baseApexModuleName))
2488 }
2489 attrs, props := convertWithBp2build(a, ctx)
2490
2491 for _, p := range o.GetProperties() {
2492 overridableProperties, ok := p.(*overridableProperties)
2493 if !ok {
2494 continue
2495 }
2496 // Key
2497 if overridableProperties.Key != nil {
2498 attrs.Key = bazel.LabelAttribute{}
2499 attrs.Key.SetValue(android.BazelLabelForModuleDepSingle(ctx, *overridableProperties.Key))
2500 }
2501
2502 // Certificate
2503 if overridableProperties.Certificate != nil {
2504 attrs.Certificate = bazel.LabelAttribute{}
2505 attrs.Certificate.SetValue(android.BazelLabelForModuleDepSingle(ctx, *overridableProperties.Certificate))
2506 }
2507
2508 // Prebuilts
2509 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, overridableProperties.Prebuilts)
2510 attrs.Prebuilts = bazel.MakeLabelListAttribute(prebuiltsLabelList)
2511
2512 // Compressible
2513 if overridableProperties.Compressible != nil {
2514 attrs.Compressible = bazel.BoolAttribute{Value: overridableProperties.Compressible}
2515 }
2516 }
2517
2518 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: o.Name()}, &attrs)
2519}
2520
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002521///////////////////////////////////////////////////////////////////////////////////////////////////
2522// Vality check routines
2523//
2524// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2525// certain conditions are not met.
2526//
2527// TODO(jiyong): move these checks to a separate go file.
2528
satayevad991492021-12-03 18:58:32 +00002529var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2530
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002531// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2532// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002533func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002534 if a.testApex || a.vndkApex {
2535 return
2536 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002537 // apexBundle::minSdkVersion reports its own errors.
2538 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002539 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002540}
2541
Albert Martineefabcf2022-03-21 20:11:16 +00002542// Returns apex's min_sdk_version string value, honoring overrides
2543func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
2544 // Only override the minSdkVersion value on Apexes which already specify
2545 // a min_sdk_version (it's optional for non-updatable apexes), and that its
2546 // min_sdk_version value is lower than the one to override with.
2547 overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride()
2548 overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue)
2549 originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
2550 isMinSdkSet := a.properties.Min_sdk_version != nil
2551 isOverrideValueHigher := overrideApiLevel.CompareTo(originalMinApiLevel) > 0
2552 if overrideMinSdkValue != "" && isMinSdkSet && isOverrideValueHigher {
2553 return overrideMinSdkValue
2554 }
2555
2556 return proptools.String(a.properties.Min_sdk_version)
2557}
2558
2559// Returns apex's min_sdk_version SdkSpec, honoring overrides
satayevad991492021-12-03 18:58:32 +00002560func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2561 return android.SdkSpec{
2562 Kind: android.SdkNone,
2563 ApiLevel: a.minSdkVersion(ctx),
Albert Martineefabcf2022-03-21 20:11:16 +00002564 Raw: a.minSdkVersionValue(ctx),
satayevad991492021-12-03 18:58:32 +00002565 }
2566}
2567
Albert Martineefabcf2022-03-21 20:11:16 +00002568// Returns apex's min_sdk_version ApiLevel, honoring overrides
satayevad991492021-12-03 18:58:32 +00002569func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Albert Martineefabcf2022-03-21 20:11:16 +00002570 return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx))
2571}
2572
2573// Construct ApiLevel object from min_sdk_version string value
2574func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel {
2575 if value == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002576 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002577 }
Albert Martineefabcf2022-03-21 20:11:16 +00002578 apiLevel, err := android.ApiLevelFromUser(ctx, value)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002579 if err != nil {
2580 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2581 return android.NoneApiLevel
2582 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002583 return apiLevel
2584}
2585
2586// Ensures that a lib providing stub isn't statically linked
2587func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2588 // Practically, we only care about regular APEXes on the device.
2589 if ctx.Host() || a.testApex || a.vndkApex {
2590 return
2591 }
2592
2593 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2594
2595 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2596 if ccm, ok := to.(*cc.Module); ok {
2597 apexName := ctx.ModuleName()
2598 fromName := ctx.OtherModuleName(from)
2599 toName := ctx.OtherModuleName(to)
2600
2601 // If `to` is not actually in the same APEX as `from` then it does not need
2602 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002603 //
2604 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002605 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2606 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2607 return false
2608 }
2609
2610 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2611 // exception to this rule. It can't make the static dependencies dynamic
2612 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002613 // Same rule should be applied to linkerconfig, because it should be executed
2614 // only with static linked libraries before linker is available with ld.config.txt
2615 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002616 return false
2617 }
2618
2619 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2620 if isStubLibraryFromOtherApex && !externalDep {
2621 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2622 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2623 }
2624
2625 }
2626 return true
2627 })
2628}
2629
satayevb98371c2021-06-15 16:49:50 +01002630// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002631func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2632 if a.Updatable() {
Albert Martineefabcf2022-03-21 20:11:16 +00002633 if a.minSdkVersionValue(ctx) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002634 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2635 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002636 if a.UsePlatformApis() {
2637 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2638 }
Daniel Norman69109112021-12-02 12:52:42 -08002639 if a.SocSpecific() || a.DeviceSpecific() {
2640 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2641 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002642 if a.FutureUpdatable() {
2643 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2644 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002645 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002646 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002647 }
2648}
2649
satayevb98371c2021-06-15 16:49:50 +01002650// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2651func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2652 ctx.VisitDirectDeps(func(module android.Module) {
2653 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2654 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2655 if !info.ClasspathFragmentProtoGenerated {
2656 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2657 }
2658 }
2659 })
2660}
2661
2662// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002663func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002664 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2665 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002666 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2667 tag := ctx.OtherModuleDependencyTag(module)
2668 switch tag {
2669 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002670 if m, ok := module.(interface {
2671 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2672 }); ok {
2673 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002674 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2675 }
2676 }
2677 }
2678 })
2679}
2680
satayevb98371c2021-06-15 16:49:50 +01002681// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002682func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2683 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2684 if ctx.Host() || a.testApex || a.vndkApex {
2685 return
2686 }
2687
2688 // Because APEXes targeting other than system/system_ext partitions can't set
2689 // apex_available, we skip checks for these APEXes
2690 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2691 return
2692 }
2693
2694 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2695 // Requiring them and their transitive depencies with apex_available is not right
2696 // because they just add noise.
2697 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2698 return
2699 }
2700
2701 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2702 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2703 if externalDep {
2704 return false
2705 }
2706
2707 apexName := ctx.ModuleName()
2708 fromName := ctx.OtherModuleName(from)
2709 toName := ctx.OtherModuleName(to)
2710
2711 // If `to` is not actually in the same APEX as `from` then it does not need
2712 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002713 //
2714 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002715 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2716 // As soon as the dependency graph crosses the APEX boundary, don't go
2717 // further.
2718 return false
2719 }
2720
2721 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2722 return true
2723 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002724 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2725 "\n\nDependency path:%s\n\n"+
2726 "Consider adding %q to 'apex_available' property of %q",
2727 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002728 // Visit this module's dependencies to check and report any issues with their availability.
2729 return true
2730 })
2731}
2732
Jiyong Park192600a2021-08-03 07:52:17 +00002733// checkStaticExecutable ensures that executables in an APEX are not static.
2734func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002735 // No need to run this for host APEXes
2736 if ctx.Host() {
2737 return
2738 }
2739
Jiyong Park192600a2021-08-03 07:52:17 +00002740 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2741 if ctx.OtherModuleDependencyTag(module) != executableTag {
2742 return
2743 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002744
2745 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002746 apex := a.ApexVariationName()
2747 exec := ctx.OtherModuleName(module)
2748 if isStaticExecutableAllowed(apex, exec) {
2749 return
2750 }
2751 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2752 }
2753 })
2754}
2755
2756// A small list of exceptions where static executables are allowed in APEXes.
2757func isStaticExecutableAllowed(apex string, exec string) bool {
2758 m := map[string][]string{
2759 "com.android.runtime": []string{
2760 "linker",
2761 "linkerconfig",
2762 },
2763 }
2764 execNames, ok := m[apex]
2765 return ok && android.InList(exec, execNames)
2766}
2767
braleeb0c1f0c2021-06-07 22:49:13 +08002768// Collect information for opening IDE project files in java/jdeps.go.
2769func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Remi NGUYEN VANbe901722022-03-02 21:00:33 +09002770 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
2771 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
2772 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002773 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2774}
2775
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002776var (
2777 apexAvailBaseline = makeApexAvailableBaseline()
2778 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2779)
2780
Colin Cross440e0d02020-06-11 11:32:11 -07002781func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002782 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002783 moduleName = normalizeModuleName(moduleName)
2784
Colin Cross440e0d02020-06-11 11:32:11 -07002785 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002786 return true
2787 }
2788
2789 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002790 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002791 return true
2792 }
2793
2794 return false
2795}
2796
2797func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002798 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2799 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002800 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002801 if strings.HasPrefix(moduleName, "libclang_rt.") {
2802 // This module has many arch variants that depend on the product being built.
2803 // We don't want to list them all
2804 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002805 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002806 if strings.HasPrefix(moduleName, "androidx.") {
2807 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2808 moduleName = "androidx"
2809 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002810 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002811}
2812
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002813// Transform the map of apex -> modules to module -> apexes.
2814func invertApexBaseline(m map[string][]string) map[string][]string {
2815 r := make(map[string][]string)
2816 for apex, modules := range m {
2817 for _, module := range modules {
2818 r[module] = append(r[module], apex)
2819 }
2820 }
2821 return r
2822}
2823
2824// Retrieve the baseline of apexes to which the supplied module belongs.
2825func BaselineApexAvailable(moduleName string) []string {
2826 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2827}
2828
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002829// This is a map from apex to modules, which overrides the apex_available setting for that
2830// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002831// TODO(b/147364041): remove this
2832func makeApexAvailableBaseline() map[string][]string {
2833 // The "Module separator"s below are employed to minimize merge conflicts.
2834 m := make(map[string][]string)
2835 //
2836 // Module separator
2837 //
2838 m["com.android.appsearch"] = []string{
2839 "icing-java-proto-lite",
2840 "libprotobuf-java-lite",
2841 }
2842 //
2843 // Module separator
2844 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002845 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002846 "android.hardware.audio.common@5.0",
2847 "android.hardware.bluetooth.a2dp@1.0",
2848 "android.hardware.bluetooth.audio@2.0",
2849 "android.hardware.bluetooth@1.0",
2850 "android.hardware.bluetooth@1.1",
2851 "android.hardware.graphics.bufferqueue@1.0",
2852 "android.hardware.graphics.bufferqueue@2.0",
2853 "android.hardware.graphics.common@1.0",
2854 "android.hardware.graphics.common@1.1",
2855 "android.hardware.graphics.common@1.2",
2856 "android.hardware.media@1.0",
2857 "android.hidl.safe_union@1.0",
2858 "android.hidl.token@1.0",
2859 "android.hidl.token@1.0-utils",
2860 "avrcp-target-service",
2861 "avrcp_headers",
2862 "bluetooth-protos-lite",
2863 "bluetooth.mapsapi",
2864 "com.android.vcard",
2865 "dnsresolver_aidl_interface-V2-java",
2866 "ipmemorystore-aidl-interfaces-V5-java",
2867 "ipmemorystore-aidl-interfaces-java",
2868 "internal_include_headers",
2869 "lib-bt-packets",
2870 "lib-bt-packets-avrcp",
2871 "lib-bt-packets-base",
2872 "libFraunhoferAAC",
2873 "libaudio-a2dp-hw-utils",
2874 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002875 "libbluetooth",
2876 "libbluetooth-types",
2877 "libbluetooth-types-header",
2878 "libbluetooth_gd",
2879 "libbluetooth_headers",
2880 "libbluetooth_jni",
2881 "libbt-audio-hal-interface",
2882 "libbt-bta",
2883 "libbt-common",
2884 "libbt-hci",
2885 "libbt-platform-protos-lite",
2886 "libbt-protos-lite",
2887 "libbt-sbc-decoder",
2888 "libbt-sbc-encoder",
2889 "libbt-stack",
2890 "libbt-utils",
2891 "libbtcore",
2892 "libbtdevice",
2893 "libbte",
2894 "libbtif",
2895 "libchrome",
2896 "libevent",
2897 "libfmq",
2898 "libg722codec",
2899 "libgui_headers",
2900 "libmedia_headers",
2901 "libmodpb64",
2902 "libosi",
2903 "libstagefright_foundation_headers",
2904 "libstagefright_headers",
2905 "libstatslog",
2906 "libstatssocket",
2907 "libtinyxml2",
2908 "libudrv-uipc",
2909 "libz",
2910 "media_plugin_headers",
2911 "net-utils-services-common",
2912 "netd_aidl_interface-unstable-java",
2913 "netd_event_listener_interface-java",
2914 "netlink-client",
2915 "networkstack-client",
2916 "sap-api-java-static",
2917 "services.net",
2918 }
2919 //
2920 // Module separator
2921 //
2922 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2923 //
2924 // Module separator
2925 //
2926 m["com.android.extservices"] = []string{
2927 "error_prone_annotations",
2928 "ExtServices-core",
2929 "ExtServices",
2930 "libtextclassifier-java",
2931 "libz_current",
2932 "textclassifier-statsd",
2933 "TextClassifierNotificationLibNoManifest",
2934 "TextClassifierServiceLibNoManifest",
2935 }
2936 //
2937 // Module separator
2938 //
2939 m["com.android.neuralnetworks"] = []string{
2940 "android.hardware.neuralnetworks@1.0",
2941 "android.hardware.neuralnetworks@1.1",
2942 "android.hardware.neuralnetworks@1.2",
2943 "android.hardware.neuralnetworks@1.3",
2944 "android.hidl.allocator@1.0",
2945 "android.hidl.memory.token@1.0",
2946 "android.hidl.memory@1.0",
2947 "android.hidl.safe_union@1.0",
2948 "libarect",
2949 "libbuildversion",
2950 "libmath",
2951 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002952 }
2953 //
2954 // Module separator
2955 //
2956 m["com.android.media"] = []string{
2957 "android.frameworks.bufferhub@1.0",
2958 "android.hardware.cas.native@1.0",
2959 "android.hardware.cas@1.0",
2960 "android.hardware.configstore-utils",
2961 "android.hardware.configstore@1.0",
2962 "android.hardware.configstore@1.1",
2963 "android.hardware.graphics.allocator@2.0",
2964 "android.hardware.graphics.allocator@3.0",
2965 "android.hardware.graphics.bufferqueue@1.0",
2966 "android.hardware.graphics.bufferqueue@2.0",
2967 "android.hardware.graphics.common@1.0",
2968 "android.hardware.graphics.common@1.1",
2969 "android.hardware.graphics.common@1.2",
2970 "android.hardware.graphics.mapper@2.0",
2971 "android.hardware.graphics.mapper@2.1",
2972 "android.hardware.graphics.mapper@3.0",
2973 "android.hardware.media.omx@1.0",
2974 "android.hardware.media@1.0",
2975 "android.hidl.allocator@1.0",
2976 "android.hidl.memory.token@1.0",
2977 "android.hidl.memory@1.0",
2978 "android.hidl.token@1.0",
2979 "android.hidl.token@1.0-utils",
2980 "bionic_libc_platform_headers",
2981 "exoplayer2-extractor",
2982 "exoplayer2-extractor-annotation-stubs",
2983 "gl_headers",
2984 "jsr305",
2985 "libEGL",
2986 "libEGL_blobCache",
2987 "libEGL_getProcAddress",
2988 "libFLAC",
2989 "libFLAC-config",
2990 "libFLAC-headers",
2991 "libGLESv2",
2992 "libaacextractor",
2993 "libamrextractor",
2994 "libarect",
2995 "libaudio_system_headers",
2996 "libaudioclient",
2997 "libaudioclient_headers",
2998 "libaudiofoundation",
2999 "libaudiofoundation_headers",
3000 "libaudiomanager",
3001 "libaudiopolicy",
3002 "libaudioutils",
3003 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003004 "libbluetooth-types-header",
3005 "libbufferhub",
3006 "libbufferhub_headers",
3007 "libbufferhubqueue",
3008 "libc_malloc_debug_backtrace",
3009 "libcamera_client",
3010 "libcamera_metadata",
3011 "libdvr_headers",
3012 "libexpat",
3013 "libfifo",
3014 "libflacextractor",
3015 "libgrallocusage",
3016 "libgraphicsenv",
3017 "libgui",
3018 "libgui_headers",
3019 "libhardware_headers",
3020 "libinput",
3021 "liblzma",
3022 "libmath",
3023 "libmedia",
3024 "libmedia_codeclist",
3025 "libmedia_headers",
3026 "libmedia_helper",
3027 "libmedia_helper_headers",
3028 "libmedia_midiiowrapper",
3029 "libmedia_omx",
3030 "libmediautils",
3031 "libmidiextractor",
3032 "libmkvextractor",
3033 "libmp3extractor",
3034 "libmp4extractor",
3035 "libmpeg2extractor",
3036 "libnativebase_headers",
3037 "libnativewindow_headers",
3038 "libnblog",
3039 "liboggextractor",
3040 "libpackagelistparser",
3041 "libpdx",
3042 "libpdx_default_transport",
3043 "libpdx_headers",
3044 "libpdx_uds",
3045 "libprocinfo",
3046 "libspeexresampler",
3047 "libspeexresampler",
3048 "libstagefright_esds",
3049 "libstagefright_flacdec",
3050 "libstagefright_flacdec",
3051 "libstagefright_foundation",
3052 "libstagefright_foundation_headers",
3053 "libstagefright_foundation_without_imemory",
3054 "libstagefright_headers",
3055 "libstagefright_id3",
3056 "libstagefright_metadatautils",
3057 "libstagefright_mpeg2extractor",
3058 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003059 "libui",
3060 "libui_headers",
3061 "libunwindstack",
3062 "libvibrator",
3063 "libvorbisidec",
3064 "libwavextractor",
3065 "libwebm",
3066 "media_ndk_headers",
3067 "media_plugin_headers",
3068 "updatable-media",
3069 }
3070 //
3071 // Module separator
3072 //
3073 m["com.android.media.swcodec"] = []string{
3074 "android.frameworks.bufferhub@1.0",
3075 "android.hardware.common-ndk_platform",
3076 "android.hardware.configstore-utils",
3077 "android.hardware.configstore@1.0",
3078 "android.hardware.configstore@1.1",
3079 "android.hardware.graphics.allocator@2.0",
3080 "android.hardware.graphics.allocator@3.0",
3081 "android.hardware.graphics.allocator@4.0",
3082 "android.hardware.graphics.bufferqueue@1.0",
3083 "android.hardware.graphics.bufferqueue@2.0",
3084 "android.hardware.graphics.common-ndk_platform",
3085 "android.hardware.graphics.common@1.0",
3086 "android.hardware.graphics.common@1.1",
3087 "android.hardware.graphics.common@1.2",
3088 "android.hardware.graphics.mapper@2.0",
3089 "android.hardware.graphics.mapper@2.1",
3090 "android.hardware.graphics.mapper@3.0",
3091 "android.hardware.graphics.mapper@4.0",
3092 "android.hardware.media.bufferpool@2.0",
3093 "android.hardware.media.c2@1.0",
3094 "android.hardware.media.c2@1.1",
3095 "android.hardware.media.omx@1.0",
3096 "android.hardware.media@1.0",
3097 "android.hardware.media@1.0",
3098 "android.hidl.memory.token@1.0",
3099 "android.hidl.memory@1.0",
3100 "android.hidl.safe_union@1.0",
3101 "android.hidl.token@1.0",
3102 "android.hidl.token@1.0-utils",
3103 "libEGL",
3104 "libFLAC",
3105 "libFLAC-config",
3106 "libFLAC-headers",
3107 "libFraunhoferAAC",
3108 "libLibGuiProperties",
3109 "libarect",
3110 "libaudio_system_headers",
3111 "libaudioutils",
3112 "libaudioutils",
3113 "libaudioutils_fixedfft",
3114 "libavcdec",
3115 "libavcenc",
3116 "libavservices_minijail",
3117 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003118 "libbinderthreadstateutils",
3119 "libbluetooth-types-header",
3120 "libbufferhub_headers",
3121 "libcodec2",
3122 "libcodec2_headers",
3123 "libcodec2_hidl@1.0",
3124 "libcodec2_hidl@1.1",
3125 "libcodec2_internal",
3126 "libcodec2_soft_aacdec",
3127 "libcodec2_soft_aacenc",
3128 "libcodec2_soft_amrnbdec",
3129 "libcodec2_soft_amrnbenc",
3130 "libcodec2_soft_amrwbdec",
3131 "libcodec2_soft_amrwbenc",
3132 "libcodec2_soft_av1dec_gav1",
3133 "libcodec2_soft_avcdec",
3134 "libcodec2_soft_avcenc",
3135 "libcodec2_soft_common",
3136 "libcodec2_soft_flacdec",
3137 "libcodec2_soft_flacenc",
3138 "libcodec2_soft_g711alawdec",
3139 "libcodec2_soft_g711mlawdec",
3140 "libcodec2_soft_gsmdec",
3141 "libcodec2_soft_h263dec",
3142 "libcodec2_soft_h263enc",
3143 "libcodec2_soft_hevcdec",
3144 "libcodec2_soft_hevcenc",
3145 "libcodec2_soft_mp3dec",
3146 "libcodec2_soft_mpeg2dec",
3147 "libcodec2_soft_mpeg4dec",
3148 "libcodec2_soft_mpeg4enc",
3149 "libcodec2_soft_opusdec",
3150 "libcodec2_soft_opusenc",
3151 "libcodec2_soft_rawdec",
3152 "libcodec2_soft_vorbisdec",
3153 "libcodec2_soft_vp8dec",
3154 "libcodec2_soft_vp8enc",
3155 "libcodec2_soft_vp9dec",
3156 "libcodec2_soft_vp9enc",
3157 "libcodec2_vndk",
3158 "libdvr_headers",
3159 "libfmq",
3160 "libfmq",
3161 "libgav1",
3162 "libgralloctypes",
3163 "libgrallocusage",
3164 "libgraphicsenv",
3165 "libgsm",
3166 "libgui_bufferqueue_static",
3167 "libgui_headers",
3168 "libhardware",
3169 "libhardware_headers",
3170 "libhevcdec",
3171 "libhevcenc",
3172 "libion",
3173 "libjpeg",
3174 "liblzma",
3175 "libmath",
3176 "libmedia_codecserviceregistrant",
3177 "libmedia_headers",
3178 "libmpeg2dec",
3179 "libnativebase_headers",
3180 "libnativewindow_headers",
3181 "libpdx_headers",
3182 "libscudo_wrapper",
3183 "libsfplugin_ccodec_utils",
3184 "libspeexresampler",
3185 "libstagefright_amrnb_common",
3186 "libstagefright_amrnbdec",
3187 "libstagefright_amrnbenc",
3188 "libstagefright_amrwbdec",
3189 "libstagefright_amrwbenc",
3190 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003191 "libstagefright_enc_common",
3192 "libstagefright_flacdec",
3193 "libstagefright_foundation",
3194 "libstagefright_foundation_headers",
3195 "libstagefright_headers",
3196 "libstagefright_m4vh263dec",
3197 "libstagefright_m4vh263enc",
3198 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003199 "libui",
3200 "libui_headers",
3201 "libunwindstack",
3202 "libvorbisidec",
3203 "libvpx",
3204 "libyuv",
3205 "libyuv_static",
3206 "media_ndk_headers",
3207 "media_plugin_headers",
3208 "mediaswcodec",
3209 }
3210 //
3211 // Module separator
3212 //
3213 m["com.android.mediaprovider"] = []string{
3214 "MediaProvider",
3215 "MediaProviderGoogle",
3216 "fmtlib_ndk",
3217 "libbase_ndk",
3218 "libfuse",
3219 "libfuse_jni",
3220 }
3221 //
3222 // Module separator
3223 //
3224 m["com.android.permission"] = []string{
3225 "car-ui-lib",
3226 "iconloader",
3227 "kotlin-annotations",
3228 "kotlin-stdlib",
3229 "kotlin-stdlib-jdk7",
3230 "kotlin-stdlib-jdk8",
3231 "kotlinx-coroutines-android",
3232 "kotlinx-coroutines-android-nodeps",
3233 "kotlinx-coroutines-core",
3234 "kotlinx-coroutines-core-nodeps",
3235 "permissioncontroller-statsd",
3236 "GooglePermissionController",
3237 "PermissionController",
3238 "SettingsLibActionBarShadow",
3239 "SettingsLibAppPreference",
3240 "SettingsLibBarChartPreference",
3241 "SettingsLibLayoutPreference",
3242 "SettingsLibProgressBar",
3243 "SettingsLibSearchWidget",
3244 "SettingsLibSettingsTheme",
3245 "SettingsLibRestrictedLockUtils",
3246 "SettingsLibHelpUtils",
3247 }
3248 //
3249 // Module separator
3250 //
3251 m["com.android.runtime"] = []string{
3252 "bionic_libc_platform_headers",
3253 "libarm-optimized-routines-math",
3254 "libc_aeabi",
3255 "libc_bionic",
3256 "libc_bionic_ndk",
3257 "libc_bootstrap",
3258 "libc_common",
3259 "libc_common_shared",
3260 "libc_common_static",
3261 "libc_dns",
3262 "libc_dynamic_dispatch",
3263 "libc_fortify",
3264 "libc_freebsd",
3265 "libc_freebsd_large_stack",
3266 "libc_gdtoa",
3267 "libc_init_dynamic",
3268 "libc_init_static",
3269 "libc_jemalloc_wrapper",
3270 "libc_netbsd",
3271 "libc_nomalloc",
3272 "libc_nopthread",
3273 "libc_openbsd",
3274 "libc_openbsd_large_stack",
3275 "libc_openbsd_ndk",
3276 "libc_pthread",
3277 "libc_static_dispatch",
3278 "libc_syscalls",
3279 "libc_tzcode",
3280 "libc_unwind_static",
3281 "libdebuggerd",
3282 "libdebuggerd_common_headers",
3283 "libdebuggerd_handler_core",
3284 "libdebuggerd_handler_fallback",
3285 "libdl_static",
3286 "libjemalloc5",
3287 "liblinker_main",
3288 "liblinker_malloc",
3289 "liblz4",
3290 "liblzma",
3291 "libprocinfo",
3292 "libpropertyinfoparser",
3293 "libscudo",
3294 "libstdc++",
3295 "libsystemproperties",
3296 "libtombstoned_client_static",
3297 "libunwindstack",
3298 "libz",
3299 "libziparchive",
3300 }
3301 //
3302 // Module separator
3303 //
3304 m["com.android.tethering"] = []string{
3305 "android.hardware.tetheroffload.config-V1.0-java",
3306 "android.hardware.tetheroffload.control-V1.0-java",
3307 "android.hidl.base-V1.0-java",
3308 "libcgrouprc",
3309 "libcgrouprc_format",
3310 "libtetherutilsjni",
3311 "libvndksupport",
3312 "net-utils-framework-common",
3313 "netd_aidl_interface-V3-java",
3314 "netlink-client",
3315 "networkstack-aidl-interfaces-java",
3316 "tethering-aidl-interfaces-java",
3317 "TetheringApiCurrentLib",
3318 }
3319 //
3320 // Module separator
3321 //
3322 m["com.android.wifi"] = []string{
3323 "PlatformProperties",
3324 "android.hardware.wifi-V1.0-java",
3325 "android.hardware.wifi-V1.0-java-constants",
3326 "android.hardware.wifi-V1.1-java",
3327 "android.hardware.wifi-V1.2-java",
3328 "android.hardware.wifi-V1.3-java",
3329 "android.hardware.wifi-V1.4-java",
3330 "android.hardware.wifi.hostapd-V1.0-java",
3331 "android.hardware.wifi.hostapd-V1.1-java",
3332 "android.hardware.wifi.hostapd-V1.2-java",
3333 "android.hardware.wifi.supplicant-V1.0-java",
3334 "android.hardware.wifi.supplicant-V1.1-java",
3335 "android.hardware.wifi.supplicant-V1.2-java",
3336 "android.hardware.wifi.supplicant-V1.3-java",
3337 "android.hidl.base-V1.0-java",
3338 "android.hidl.manager-V1.0-java",
3339 "android.hidl.manager-V1.1-java",
3340 "android.hidl.manager-V1.2-java",
3341 "bouncycastle-unbundled",
3342 "dnsresolver_aidl_interface-V2-java",
3343 "error_prone_annotations",
3344 "framework-wifi-pre-jarjar",
3345 "framework-wifi-util-lib",
3346 "ipmemorystore-aidl-interfaces-V3-java",
3347 "ipmemorystore-aidl-interfaces-java",
3348 "ksoap2",
3349 "libnanohttpd",
3350 "libwifi-jni",
3351 "net-utils-services-common",
3352 "netd_aidl_interface-V2-java",
3353 "netd_aidl_interface-unstable-java",
3354 "netd_event_listener_interface-java",
3355 "netlink-client",
3356 "networkstack-client",
3357 "services.net",
3358 "wifi-lite-protos",
3359 "wifi-nano-protos",
3360 "wifi-service-pre-jarjar",
3361 "wifi-service-resources",
3362 }
3363 //
3364 // Module separator
3365 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003366 m["com.android.os.statsd"] = []string{
3367 "libstatssocket",
3368 }
3369 //
3370 // Module separator
3371 //
3372 m[android.AvailableToAnyApex] = []string{
3373 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3374 "androidx",
3375 "androidx-constraintlayout_constraintlayout",
3376 "androidx-constraintlayout_constraintlayout-nodeps",
3377 "androidx-constraintlayout_constraintlayout-solver",
3378 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3379 "com.google.android.material_material",
3380 "com.google.android.material_material-nodeps",
3381
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003382 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003383 "libprofile-clang-extras",
3384 "libprofile-clang-extras_ndk",
3385 "libprofile-extras",
3386 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003387 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003388 }
3389 return m
3390}
3391
3392func init() {
Spandan Dasf14e2542021-11-12 00:01:37 +00003393 android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...)
3394 android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003395}
3396
Spandan Dasf14e2542021-11-12 00:01:37 +00003397func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule {
3398 rules := make([]android.Rule, 0, len(bcpPermittedPackages))
3399 for jar, permittedPackages := range bcpPermittedPackages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003400 permittedPackagesRule := android.NeverAllow().
Spandan Dasf14e2542021-11-12 00:01:37 +00003401 With("name", jar).
3402 WithMatcher("permitted_packages", android.NotInList(permittedPackages)).
3403 Because(jar +
3404 " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") +
Anton Hanssone1b18362021-12-23 15:05:38 +00003405 ". Please consider the following alternatives:\n" +
Andrei Onead967aee2022-01-19 15:36:40 +00003406 " 1. If the offending code is from a statically linked library, consider " +
3407 "removing that dependency and using an alternative already in the " +
3408 "bootclasspath, or perhaps a shared library." +
3409 " 2. Move the offending code into an allowed package.\n" +
3410 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3411 "health implications of bundling that code, particularly if the offending jar " +
3412 "is part of the bootclasspath.")
Spandan Dasf14e2542021-11-12 00:01:37 +00003413
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003414 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003415 }
3416 return rules
3417}
3418
Anton Hanssone1b18362021-12-23 15:05:38 +00003419// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003420// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003421func qBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003422 return map[string][]string{
Spandan Dasf14e2542021-11-12 00:01:37 +00003423 "conscrypt": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003424 "android.net.ssl",
3425 "com.android.org.conscrypt",
3426 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003427 "updatable-media": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003428 "android.media",
3429 },
3430 }
3431}
3432
Anton Hanssone1b18362021-12-23 15:05:38 +00003433// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003434// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003435func rBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003436 return map[string][]string{
Spandan Dasf14e2542021-11-12 00:01:37 +00003437 "framework-mediaprovider": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003438 "android.provider",
3439 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003440 "framework-permission": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003441 "android.permission",
3442 "android.app.role",
3443 "com.android.permission",
3444 "com.android.role",
3445 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003446 "framework-sdkextensions": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003447 "android.os.ext",
3448 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003449 "framework-statsd": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003450 "android.app",
3451 "android.os",
3452 "android.util",
3453 "com.android.internal.statsd",
3454 "com.android.server.stats",
3455 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003456 "framework-wifi": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003457 "com.android.server.wifi",
3458 "com.android.wifi.x",
3459 "android.hardware.wifi",
3460 "android.net.wifi",
3461 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003462 "framework-tethering": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003463 "android.net",
3464 },
3465 }
3466}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003467
3468// For Bazel / bp2build
3469
3470type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003471 Manifest bazel.LabelAttribute
3472 Android_manifest bazel.LabelAttribute
3473 File_contexts bazel.LabelAttribute
3474 Key bazel.LabelAttribute
3475 Certificate bazel.LabelAttribute
3476 Min_sdk_version *string
3477 Updatable bazel.BoolAttribute
3478 Installable bazel.BoolAttribute
3479 Binaries bazel.LabelListAttribute
3480 Prebuilts bazel.LabelListAttribute
3481 Native_shared_libs_32 bazel.LabelListAttribute
3482 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003483 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003484}
3485
3486type convertedNativeSharedLibs struct {
3487 Native_shared_libs_32 bazel.LabelListAttribute
3488 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003489}
3490
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003491// ConvertWithBp2build performs bp2build conversion of an apex
3492func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3493 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003494 if ctx.ModuleType() != "apex" {
3495 return
3496 }
3497
Wei Li1c66fc72022-05-09 23:59:14 -07003498 attrs, props := convertWithBp2build(a, ctx)
3499 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, &attrs)
3500}
3501
3502func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (bazelApexBundleAttributes, bazel.BazelTargetModuleProperties) {
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003503 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003504 if a.properties.Manifest != nil {
3505 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003506 }
3507
3508 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003509 if a.properties.AndroidManifest != nil {
3510 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003511 }
3512
3513 var fileContextsLabelAttribute bazel.LabelAttribute
Wei Li1c66fc72022-05-09 23:59:14 -07003514 if a.properties.File_contexts == nil {
3515 // See buildFileContexts(), if file_contexts is not specified the default one is used, which is //system/sepolicy/apex:<module name>-file_contexts
3516 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, a.Name()+"-file_contexts"))
3517 } else if strings.HasPrefix(*a.properties.File_contexts, ":") {
3518 // File_contexts is a module
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003519 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Wei Li1c66fc72022-05-09 23:59:14 -07003520 } else {
3521 // File_contexts is a file
3522 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003523 }
3524
Albert Martineefabcf2022-03-21 20:11:16 +00003525 // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
3526 // given it's coming via config, we probably don't want to put it in here.
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003527 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003528 if a.properties.Min_sdk_version != nil {
3529 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003530 }
3531
3532 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003533 if a.overridableProperties.Key != nil {
3534 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003535 }
3536
3537 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003538 if a.overridableProperties.Certificate != nil {
3539 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003540 }
3541
Yu Liu4ae55d12022-01-05 17:17:23 -08003542 nativeSharedLibs := &convertedNativeSharedLibs{
3543 Native_shared_libs_32: bazel.LabelListAttribute{},
3544 Native_shared_libs_64: bazel.LabelListAttribute{},
3545 }
3546 compileMultilib := "both"
3547 if a.CompileMultilib() != nil {
3548 compileMultilib = *a.CompileMultilib()
3549 }
3550
3551 // properties.Native_shared_libs is treated as "both"
3552 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3553 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3554 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3555 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3556 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003557
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003558 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003559 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3560 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3561
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003562 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003563 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003564
3565 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003566 if a.properties.Updatable != nil {
3567 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003568 }
3569
3570 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003571 if a.properties.Installable != nil {
3572 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003573 }
3574
Wei Lif034cb42022-01-19 15:54:31 -08003575 var compressibleAttribute bazel.BoolAttribute
3576 if a.overridableProperties.Compressible != nil {
3577 compressibleAttribute.Value = a.overridableProperties.Compressible
3578 }
3579
Wei Li1c66fc72022-05-09 23:59:14 -07003580 attrs := bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003581 Manifest: manifestLabelAttribute,
3582 Android_manifest: androidManifestLabelAttribute,
3583 File_contexts: fileContextsLabelAttribute,
3584 Min_sdk_version: minSdkVersion,
3585 Key: keyLabelAttribute,
3586 Certificate: certificateLabelAttribute,
3587 Updatable: updatableAttribute,
3588 Installable: installableAttribute,
3589 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3590 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3591 Binaries: binariesLabelListAttribute,
3592 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003593 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003594 }
3595
3596 props := bazel.BazelTargetModuleProperties{
3597 Rule_class: "apex",
Cole Faust5f90da32022-04-29 13:37:43 -07003598 Bzl_load_location: "//build/bazel/rules/apex:apex.bzl",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003599 }
3600
Wei Li1c66fc72022-05-09 23:59:14 -07003601 return attrs, props
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003602}
Yu Liu4ae55d12022-01-05 17:17:23 -08003603
3604// The following conversions are based on this table where the rows are the compile_multilib
3605// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3606// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3607// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3608// should not be compiled.
3609// multib/compile_multilib, 32, 64, both, first
3610// 32, 32/32, none/none, 32/32, none/32
3611// 64, none/none, 64/none, 64/none, 64/none
3612// both, 32/32, 64/none, 32&64/32, 64/32
3613// first, 32/32, 64/none, 64/32, 64/32
3614
3615func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3616 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3617 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3618 switch compileMultilb {
3619 case "both", "32":
3620 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3621 case "first":
3622 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3623 case "64":
3624 // Incompatible, ignore
3625 default:
3626 invalidCompileMultilib(ctx, compileMultilb)
3627 }
3628}
3629
3630func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3631 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3632 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3633 switch compileMultilb {
3634 case "both", "64", "first":
3635 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3636 case "32":
3637 // Incompatible, ignore
3638 default:
3639 invalidCompileMultilib(ctx, compileMultilb)
3640 }
3641}
3642
3643func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3644 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3645 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3646 switch compileMultilb {
3647 case "both":
3648 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3649 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3650 case "first":
3651 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3652 case "32":
3653 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3654 case "64":
3655 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3656 default:
3657 invalidCompileMultilib(ctx, compileMultilb)
3658 }
3659}
3660
3661func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3662 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3663 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3664 switch compileMultilb {
3665 case "both", "first":
3666 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3667 case "32":
3668 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3669 case "64":
3670 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3671 default:
3672 invalidCompileMultilib(ctx, compileMultilb)
3673 }
3674}
3675
3676func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3677 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3678 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3679}
3680
3681func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3682 list := bazel.LabelListAttribute{}
3683 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3684 nativeSharedLibs.Native_shared_libs_32.Append(list)
3685}
3686
3687func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3688 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3689 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3690}
3691
3692func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3693 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3694 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3695}
3696
3697func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3698 labelListAttr *bazel.LabelListAttribute) {
3699 list := bazel.LabelListAttribute{}
3700 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3701 labelListAttr.Append(list)
3702}
3703
3704func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3705 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3706}