blob: d613861fbc8fad17713313a8166f79bd26fb87c8 [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 Gascóa70425f2022-05-20 13:05:34 +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"
37 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090038 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070039 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090040)
41
Jiyong Park8e6d52f2020-11-19 14:37:47 +090042func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000043 registerApexBuildComponents(android.InitRegistrationContext)
44}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090045
Paul Duffin667893c2021-03-09 22:34:13 +000046func registerApexBuildComponents(ctx android.RegistrationContext) {
47 ctx.RegisterModuleType("apex", BundleFactory)
48 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
49 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
50 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
51 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
52 ctx.RegisterModuleType("override_apex", overrideApexFactory)
53 ctx.RegisterModuleType("apex_set", apexSetFactory)
54
Paul Duffin5dda3e32021-05-05 14:13:27 +010055 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000056 ctx.PreDepsMutators(RegisterPreDepsMutators)
57 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090058}
59
Paul Duffin5dda3e32021-05-05 14:13:27 +010060func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
61 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
62}
63
Jiyong Park8e6d52f2020-11-19 14:37:47 +090064func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
65 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
66 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
67}
68
69func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000070 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090071 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
72 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
73 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010074 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
75 // it should create a platform variant.
76 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090077 ctx.BottomUp("apex", apexMutator).Parallel()
78 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
79 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Spandan Das66773252022-01-15 00:23:18 +000080 // Register after apex_info mutator so that it can use ApexVariationName
81 ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090082}
83
84type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090085 // Json manifest file describing meta info of this APEX bundle. Refer to
86 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090087 Manifest *string `android:"path"`
88
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090089 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
90 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090091 AndroidManifest *string `android:"path"`
92
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090093 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
94 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090095 Apex_name *string
96
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090097 // Determines the file contexts file for setting the security contexts to files in this APEX
98 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
99 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900100 File_contexts *string `android:"path"`
101
Jiyong Park038e8522021-12-13 23:56:35 +0900102 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
103 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
104 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
105 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
106 // capability. If this property is not set, or a file is missing in the file, default config
107 // is used.
108 Canned_fs_config *string `android:"path"`
109
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900110 ApexNativeDependencies
111
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900112 Multilib apexMultilibProperties
113
Sundong Ahn80c04892021-11-23 00:57:19 +0000114 // List of sh binaries that are embedded inside this APEX bundle.
115 Sh_binaries []string
116
Paul Duffin3abc1742021-03-15 19:32:23 +0000117 // List of platform_compat_config files that are embedded inside this APEX bundle.
118 Compat_configs []string
119
Jiyong Park12a719c2021-01-07 15:31:24 +0900120 // List of filesystem images that are embedded inside this APEX bundle.
121 Filesystems []string
122
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900123 // The minimum SDK version that this APEX must support at minimum. This is usually set to
124 // the SDK version that the APEX was first introduced.
125 Min_sdk_version *string
126
127 // Whether this APEX is considered updatable or not. When set to true, this will enforce
128 // additional rules for making sure that the APEX is truly updatable. To be updatable,
129 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000130 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900131 Updatable *bool
132
Jiyong Parkf4020582021-11-29 12:37:10 +0900133 // Marks that this APEX is designed to be updatable in the future, although it's not
134 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
135 // updatable APEXes. Currently, this disables the size optimization, so that the size of
136 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
137 // false.
138 Future_updatable *bool
139
Jiyong Park1bc84122021-06-22 20:23:05 +0900140 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
141 // false`. Default is false.
142 Platform_apis *bool
143
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900144 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
145 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900146 Installable *bool
147
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900148 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
149 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
150 Use_vndk_as_stable *bool
151
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000152 // Whether this is multi-installed APEX should skip installing symbol files.
153 // Multi-installed APEXes share the same apex_name and are installed at the same time.
154 // Default is false.
155 //
156 // Should be set to true for all multi-installed APEXes except the singular
157 // default version within the multi-installed group.
158 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
159 // or else conflicting build rules may be created.
160 Multi_install_skip_symbol_files *bool
161
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900162 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
163 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
164 // container. When set to zip, contents are stored in a zip container directly. This type is
165 // mostly for host-side debugging. When set to both, the two types are both built. Default
166 // is 'image'.
167 Payload_type *string
168
Huang Jianan13cac632021-08-02 15:02:17 +0800169 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
170 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900171 Payload_fs_type *string
172
173 // For telling the APEX to ignore special handling for system libraries such as bionic.
174 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900175 Ignore_system_library_special_case *bool
176
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100177 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100178 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100179 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900180
181 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
182 // used in tests.
183 Test_only_unsigned_payload *bool
184
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000185 // Whenever apex should be compressed, regardless of product flag used. Should be only
186 // used in tests.
187 Test_only_force_compression *bool
188
Jooyung Han09c11ad2021-10-27 03:45:31 +0900189 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
190 // with the tool to sign payload contents.
191 Custom_sign_tool *string
192
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100193 // Canonical name of this APEX bundle. Used to determine the path to the
194 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
195 // apex mutator variations. For override_apex modules, this is the name of the
196 // overridden base module.
197 ApexVariationName string `blueprint:"mutated"`
198
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900199 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900200
201 // List of sanitizer names that this APEX is enabled for
202 SanitizerNames []string `blueprint:"mutated"`
203
204 PreventInstall bool `blueprint:"mutated"`
205
206 HideFromMake bool `blueprint:"mutated"`
207
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900208 // Internal package method for this APEX. When payload_type is image, this can be either
209 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
210 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900211 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900212}
213
214type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900215 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900216 Native_shared_libs []string
217
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900218 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900219 Jni_libs []string
220
Jiyong Park99644e92020-11-17 22:21:02 +0900221 // List of rust dyn libraries
222 Rust_dyn_libs []string
223
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900224 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900225 Binaries []string
226
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900227 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900228 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900229
230 // List of filesystem images that are embedded inside this APEX bundle.
231 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900232}
233
234type apexMultilibProperties struct {
235 // Native dependencies whose compile_multilib is "first"
236 First ApexNativeDependencies
237
238 // Native dependencies whose compile_multilib is "both"
239 Both ApexNativeDependencies
240
241 // Native dependencies whose compile_multilib is "prefer32"
242 Prefer32 ApexNativeDependencies
243
244 // Native dependencies whose compile_multilib is "32"
245 Lib32 ApexNativeDependencies
246
247 // Native dependencies whose compile_multilib is "64"
248 Lib64 ApexNativeDependencies
249}
250
251type apexTargetBundleProperties struct {
252 Target struct {
253 // Multilib properties only for android.
254 Android struct {
255 Multilib apexMultilibProperties
256 }
257
258 // Multilib properties only for host.
259 Host struct {
260 Multilib apexMultilibProperties
261 }
262
263 // Multilib properties only for host linux_bionic.
264 Linux_bionic struct {
265 Multilib apexMultilibProperties
266 }
267
268 // Multilib properties only for host linux_glibc.
269 Linux_glibc struct {
270 Multilib apexMultilibProperties
271 }
272 }
273}
274
Jiyong Park59140302020-12-14 18:44:04 +0900275type apexArchBundleProperties struct {
276 Arch struct {
277 Arm struct {
278 ApexNativeDependencies
279 }
280 Arm64 struct {
281 ApexNativeDependencies
282 }
283 X86 struct {
284 ApexNativeDependencies
285 }
286 X86_64 struct {
287 ApexNativeDependencies
288 }
289 }
290}
291
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900292// These properties can be used in override_apex to override the corresponding properties in the
293// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900294type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900295 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900296 Apps []string
297
Daniel Norman5a3ce132021-08-26 15:44:43 -0700298 // List of prebuilt files that are embedded inside this APEX bundle.
299 Prebuilts []string
300
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900301 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900302 Rros []string
303
markchien7c803b82021-08-26 22:10:06 +0800304 // List of BPF programs inside this APEX bundle.
305 Bpfs []string
306
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900307 // List of bootclasspath fragments that are embedded inside this APEX bundle.
308 Bootclasspath_fragments []string
309
310 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
311 Systemserverclasspath_fragments []string
312
313 // List of java libraries that are embedded inside this APEX bundle.
314 Java_libs []string
315
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900316 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
317 // Soong). This does not completely prevent installation of the overridden binaries, but if
318 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
319 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900320 Overrides []string
321
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900322 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900323 Logging_parent string
324
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900325 // Apex Container package name. Override value for attribute package:name in
326 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900327 Package_name string
328
329 // A txt file containing list of files that are allowed to be included in this APEX.
330 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700331
332 // Name of the apex_key module that provides the private key to sign this APEX bundle.
333 Key *string
334
335 // Specifies the certificate and the private key to sign the zip container of this APEX. If
336 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
337 // as the certificate and the private key, respectively. If this is ":module", then the
338 // certificate and the private key are provided from the android_app_certificate module
339 // named "module".
340 Certificate *string
Oriol Prieto Gasco2c4a9632021-10-14 15:33:41 -0400341
342 // Whether this APEX can be compressed or not. Setting this property to false means this
343 // APEX will never be compressed. When set to true, APEX will be compressed if other
344 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
345 // Default: false.
346 Compressible *bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900347}
348
349type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900350 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900351 android.ModuleBase
352 android.DefaultableModuleBase
353 android.OverridableModuleBase
354 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400355 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900357 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900358 properties apexBundleProperties
359 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900360 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900364 ///////////////////////////////////////////////////////////////////////////////////////////
365 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900366
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900367 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800368 publicKeyFile android.Path
369 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900370
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900371 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800372 containerCertificateFile android.Path
373 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900374
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900375 // Flags for special variants of APEX
376 testApex bool
377 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900378
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900379 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
380 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381 primaryApexType bool
382
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900383 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900384 suffix string
385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900386 // File system type of apex_payload.img
387 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900388
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900389 // Whether to create symlink to the system file instead of having a file inside the apex or
390 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900391 linkToSystemLib bool
392
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900393 // List of files to be included in this APEX. This is filled in the first part of
394 // GenerateAndroidBuildActions.
395 filesInfo []apexFile
396
397 // List of other module names that should be installed when this APEX gets installed.
398 requiredDeps []string
399
400 ///////////////////////////////////////////////////////////////////////////////////////////
401 // Outputs (final and intermediates)
402
403 // Processed apex manifest in JSONson format (for Q)
404 manifestJsonOut android.WritablePath
405
406 // Processed apex manifest in PB format (for R+)
407 manifestPbOut android.WritablePath
408
409 // Processed file_contexts files
410 fileContexts android.WritablePath
411
Bob Badourde6a0872022-04-01 18:00:00 +0000412 // Path to notice file in html.gz format.
413 htmlGzNotice android.WritablePath
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900414
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900415 // The built APEX file. This is the main product.
Jooyung Hana6d36672022-02-24 13:58:07 +0900416 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900417 outputFile android.WritablePath
418
Jooyung Hana6d36672022-02-24 13:58:07 +0900419 // The built uncompressed .apex file.
420 outputApexFile android.WritablePath
421
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900422 // The built APEX file in app bundle format. This file is not directly installed to the
423 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
424 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
425 // system) to be merged into a single app bundle file that Play accepts. See
426 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
427 bundleModuleFile android.WritablePath
428
Colin Cross6340ea52021-11-04 12:01:18 -0700429 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900430 installDir android.InstallPath
431
Colin Cross6340ea52021-11-04 12:01:18 -0700432 // Path where this APEX was installed.
433 installedFile android.InstallPath
434
435 // Installed locations of symlinks for backward compatibility.
436 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900437
438 // Text file having the list of individual files that are included in this APEX. Used for
439 // debugging purpose.
440 installedFilesFile android.WritablePath
441
442 // List of module names that this APEX is including (to be shown via *-deps-info target).
443 // Used for debugging purpose.
444 android.ApexBundleDepsInfo
445
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900446 // Optional list of lint report zip files for apexes that contain java or app modules
447 lintReports android.Paths
448
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900449 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000450
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000451 isCompressed bool
452
sophiezc80a2b32020-11-12 16:39:19 +0000453 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700454 nativeApisUsedByModuleFile android.ModuleOutPath
455 nativeApisBackedByModuleFile android.ModuleOutPath
456 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800457
458 // Collect the module directory for IDE info in java/jdeps.go.
459 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900460}
461
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900462// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900463type apexFileClass int
464
Jooyung Han72bd2f82019-10-23 16:46:38 +0900465const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900466 app apexFileClass = iota
467 appSet
468 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900469 goBinary
470 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900471 nativeExecutable
472 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900473 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900474 pyBinary
475 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900476)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900477
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900478// apexFile represents a file in an APEX bundle. This is created during the first half of
479// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
480// of the function, this is used to create commands that copies the files into a staging directory,
481// where they are packaged into the APEX file. This struct is also used for creating Make modules
482// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900483type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900484 // buildFile is put in the installDir inside the APEX.
Bob Badourde6a0872022-04-01 18:00:00 +0000485 builtFile android.Path
486 installDir string
487 customStem string
488 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900489
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900490 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
491 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
492 // suffix>]
493 androidMkModuleName string // becomes LOCAL_MODULE
494 class apexFileClass // becomes LOCAL_MODULE_CLASS
495 moduleDir string // becomes LOCAL_PATH
496 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
497 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
498 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
499 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900500
501 jacocoReportClassesFile android.Path // only for javalibs and apps
502 lintDepSets java.LintDepSets // only for javalibs and apps
503 certificate java.Certificate // only for apps
504 overriddenPackageName string // only for apps
505
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900506 transitiveDep bool
507 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900508
Jiyong Park57621b22021-01-20 20:33:11 +0900509 multilib string
510
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900511 // TODO(jiyong): remove this
512 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900513}
514
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900515// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900516func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
517 ret := apexFile{
518 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900519 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900520 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521 class: class,
522 module: module,
523 }
524 if module != nil {
525 ret.moduleDir = ctx.OtherModuleDir(module)
526 ret.requiredModuleNames = module.RequiredModuleNames()
527 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
528 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900529 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900530 }
531 return ret
532}
533
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900534func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900535 return af.builtFile != nil && af.builtFile.String() != ""
536}
537
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900538// apexRelativePath returns the relative path of the given path from the install directory of this
539// apexFile.
540// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900541func (af *apexFile) apexRelativePath(path string) string {
542 return filepath.Join(af.installDir, path)
543}
544
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900545// path returns path of this apex file relative to the APEX root
546func (af *apexFile) path() string {
547 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900548}
549
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900550// stem returns the base filename of this apex file
551func (af *apexFile) stem() string {
552 if af.customStem != "" {
553 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900554 }
555 return af.builtFile.Base()
556}
557
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900558// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
559func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900560 var ret []string
561 for _, symlink := range af.symlinks {
562 ret = append(ret, af.apexRelativePath(symlink))
563 }
564 return ret
565}
566
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900567// availableToPlatform tests whether this apexFile is from a module that can be installed to the
568// platform.
569func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900570 if af.module == nil {
571 return false
572 }
573 if am, ok := af.module.(android.ApexModule); ok {
574 return am.AvailableFor(android.AvailableToPlatform)
575 }
576 return false
577}
578
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900579////////////////////////////////////////////////////////////////////////////////////////////////////
580// Mutators
581//
582// Brief description about mutators for APEX. The following three mutators are the most important
583// ones.
584//
585// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
586// to the (direct) dependencies of this APEX bundle.
587//
Paul Duffin949abc02020-12-08 10:34:30 +0000588// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900589// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
590// modules are marked as being included in the APEX via BuildForApex().
591//
Paul Duffin949abc02020-12-08 10:34:30 +0000592// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
593// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900594
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900595type dependencyTag struct {
596 blueprint.BaseDependencyTag
597 name string
598
599 // Determines if the dependent will be part of the APEX payload. Can be false for the
600 // dependencies to the signing key module, etc.
601 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000602
603 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
604 // replacement. This is needed because some prebuilt modules do not provide all the information
605 // needed by the apex.
606 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900607}
608
Paul Duffine4713a82022-05-13 13:01:59 +0000609func (d *dependencyTag) String() string {
610 return fmt.Sprintf("apex.dependencyTag{%q}", d.name)
611}
612
613func (d *dependencyTag) ReplaceSourceWithPrebuilt() bool {
Paul Duffin8c535da2021-03-17 14:51:03 +0000614 return !d.sourceOnly
615}
616
617var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
618
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900619var (
Paul Duffine4713a82022-05-13 13:01:59 +0000620 androidAppTag = &dependencyTag{name: "androidApp", payload: true}
621 bpfTag = &dependencyTag{name: "bpf", payload: true}
622 certificateTag = &dependencyTag{name: "certificate"}
623 executableTag = &dependencyTag{name: "executable", payload: true}
624 fsTag = &dependencyTag{name: "filesystem", payload: true}
625 bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
626 sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
627 compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
628 javaLibTag = &dependencyTag{name: "javaLib", payload: true}
629 jniLibTag = &dependencyTag{name: "jniLib", payload: true}
630 keyTag = &dependencyTag{name: "key"}
631 prebuiltTag = &dependencyTag{name: "prebuilt", payload: true}
632 rroTag = &dependencyTag{name: "rro", payload: true}
633 sharedLibTag = &dependencyTag{name: "sharedLib", payload: true}
634 testForTag = &dependencyTag{name: "test for"}
635 testTag = &dependencyTag{name: "test", payload: true}
636 shBinaryTag = &dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900637)
638
639// TODO(jiyong): shorten this function signature
640func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900641 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900642 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900643 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900644
645 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900646 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900647 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
648 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900649 }
650
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900651 // Use *FarVariation* to be able to depend on modules having conflicting variations with
652 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
653 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900654 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900655 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900656 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
657 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900658 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900659 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900660}
661
662func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900663 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900664 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
665 } else {
666 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
667 if ctx.Os().Bionic() {
668 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
669 } else {
670 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
671 }
672 }
673}
674
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900675// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
676// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
677func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
678 deviceConfig := ctx.DeviceConfig()
679 if a.vndkApex {
680 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900681 }
682
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900683 var prefix string
684 var vndkVersion string
685 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000686 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900687 prefix = cc.VendorVariationPrefix
688 vndkVersion = deviceConfig.VndkVersion()
689 } else if a.ProductSpecific() {
690 prefix = cc.ProductVariationPrefix
691 vndkVersion = deviceConfig.ProductVndkVersion()
692 }
693 }
694 if vndkVersion == "current" {
695 vndkVersion = deviceConfig.PlatformVndkVersion()
696 }
697 if vndkVersion != "" {
698 return prefix + vndkVersion
699 }
700
701 return android.CoreVariation // The usual case
702}
703
704func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900705 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
706 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
707 // each target os/architectures, appropriate dependencies are selected by their
708 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900709 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900710 imageVariation := a.getImageVariation(ctx)
711
712 a.combineProperties(ctx)
713
714 has32BitTarget := false
715 for _, target := range targets {
716 if target.Arch.ArchType.Multilib == "lib32" {
717 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000718 }
719 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900720 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900721 // Don't include artifacts for the host cross targets because there is no way for us
722 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900723 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900724 continue
725 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000726
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900727 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000728
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900729 // Add native modules targeting both ABIs. When multilib.* is omitted for
730 // native_shared_libs/jni_libs/tests, it implies multilib.both
731 depsList = append(depsList, a.properties.Multilib.Both)
732 depsList = append(depsList, ApexNativeDependencies{
733 Native_shared_libs: a.properties.Native_shared_libs,
734 Tests: a.properties.Tests,
735 Jni_libs: a.properties.Jni_libs,
736 Binaries: nil,
737 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900738
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900739 // Add native modules targeting the first ABI When multilib.* is omitted for
740 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900741 isPrimaryAbi := i == 0
742 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900743 depsList = append(depsList, a.properties.Multilib.First)
744 depsList = append(depsList, ApexNativeDependencies{
745 Native_shared_libs: nil,
746 Tests: nil,
747 Jni_libs: nil,
748 Binaries: a.properties.Binaries,
749 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900750 }
751
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900752 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900753 switch target.Arch.ArchType.Multilib {
754 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900755 depsList = append(depsList, a.properties.Multilib.Lib32)
756 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900757 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900758 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900759 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900760 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900761 }
762 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900763
Jiyong Park59140302020-12-14 18:44:04 +0900764 // Add native modules targeting a specific arch variant
765 switch target.Arch.ArchType {
766 case android.Arm:
767 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
768 case android.Arm64:
769 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
770 case android.X86:
771 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
772 case android.X86_64:
773 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
774 default:
775 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
776 }
777
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900778 for _, d := range depsList {
779 addDependenciesForNativeModules(ctx, d, target, imageVariation)
780 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000781 ctx.AddFarVariationDependencies([]blueprint.Variation{
782 {Mutator: "os", Variation: target.OsVariation()},
783 {Mutator: "arch", Variation: target.ArchVariation()},
784 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900785 }
786
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900787 // Common-arch dependencies come next
788 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Jiyong Park12a719c2021-01-07 15:31:24 +0900789 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000790 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100791}
792
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900793// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900794func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
795 if a.overridableProperties.Allowed_files != nil {
796 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100797 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900798
799 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
800 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800801 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900802 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900803 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.overridableProperties.Bootclasspath_fragments...)
804 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.overridableProperties.Systemserverclasspath_fragments...)
805 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.overridableProperties.Java_libs...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700806 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
807 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
808 // regardless of the TARGET_PREFER_* setting. See b/144532908
809 arches := ctx.DeviceConfig().Arches()
810 if len(arches) != 0 {
811 archForPrebuiltEtc := arches[0]
812 for _, arch := range arches {
813 // Prefer 64-bit arch if there is any
814 if arch.ArchType.Multilib == "lib64" {
815 archForPrebuiltEtc = arch
816 break
817 }
818 }
819 ctx.AddFarVariationDependencies([]blueprint.Variation{
820 {Mutator: "os", Variation: ctx.Os().String()},
821 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
822 }, prebuiltTag, prebuilts...)
823 }
824 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700825
826 // Dependencies for signing
827 if String(a.overridableProperties.Key) == "" {
828 ctx.PropertyErrorf("key", "missing")
829 return
830 }
831 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
832
833 cert := android.SrcIsModule(a.getCertString(ctx))
834 if cert != "" {
835 ctx.AddDependency(ctx.Module(), certificateTag, cert)
836 // empty cert is not an error. Cert and private keys will be directly found under
837 // PRODUCT_DEFAULT_DEV_CERTIFICATE
838 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100839}
840
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900841type ApexBundleInfo struct {
842 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100843}
844
Paul Duffin949abc02020-12-08 10:34:30 +0000845var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900846
Paul Duffina7d6a892020-12-07 17:39:59 +0000847var _ ApexInfoMutator = (*apexBundle)(nil)
848
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100849func (a *apexBundle) ApexVariationName() string {
850 return a.properties.ApexVariationName
851}
852
Paul Duffina7d6a892020-12-07 17:39:59 +0000853// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900854// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
855// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
856// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
857// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000858//
859// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
860// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
861// The apexMutator uses that list to create module variants for the apexes to which it belongs.
862// The relationship between module variants and apexes is not one-to-one as variants will be
863// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000864func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900865
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900866 // The VNDK APEX is special. For the APEX, the membership is described in a very different
867 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
868 // libraries are self-identified by their vndk.enabled properties. There is no need to run
869 // this mutator for the APEX as nothing will be collected. So, let's return fast.
870 if a.vndkApex {
871 return
872 }
873
874 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
875 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
876 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
877 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
878 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900879 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
880 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900881 if proptools.Bool(a.properties.Use_vndk_as_stable) {
882 if !useVndk {
883 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
884 }
885 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
886 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
887 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
888 }
889 })
890 if mctx.Failed() {
891 return
892 }
Jooyung Handf78e212020-07-22 15:54:47 +0900893 }
894
Colin Cross56a83212020-09-15 18:30:11 -0700895 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900896 am, ok := child.(android.ApexModule)
897 if !ok || !am.CanHaveApexVariants() {
898 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900899 }
Paul Duffin573989d2021-03-17 13:25:29 +0000900 depTag := mctx.OtherModuleDependencyTag(child)
901
902 // Check to see if the tag always requires that the child module has an apex variant for every
903 // apex variant of the parent module. If it does not then it is still possible for something
904 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
905 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
906 return true
907 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000908 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900909 return false
910 }
Jooyung Handf78e212020-07-22 15:54:47 +0900911 if excludeVndkLibs {
912 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
913 return false
914 }
915 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900916 // By default, all the transitive dependencies are collected, unless filtered out
917 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700918 return true
919 }
920
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900921 // Records whether a certain module is included in this apexBundle via direct dependency or
922 // inndirect dependency.
923 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700924 mctx.WalkDeps(func(child, parent android.Module) bool {
925 if !continueApexDepsWalk(child, parent) {
926 return false
927 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900928 // If the parent is apexBundle, this child is directly depended.
929 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900930 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700931 contents[depName] = contents[depName].Add(directDep)
932 return true
933 })
934
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900935 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900936 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700937 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
938 Contents: apexContents,
939 })
940
Jooyung Haned124c32021-01-26 11:43:46 +0900941 minSdkVersion := a.minSdkVersion(mctx)
942 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
943 if minSdkVersion.IsNone() {
944 minSdkVersion = android.FutureApiLevel
945 }
946
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900947 // This is the main part of this mutator. Mark the collected dependencies that they need to
948 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900949
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100950 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
951 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700952 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100953 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900954 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700955 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900956 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100957 InApexVariants: []string{apexVariationName},
958 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700959 ApexContents: []*android.ApexContents{apexContents},
960 }
Colin Cross56a83212020-09-15 18:30:11 -0700961 mctx.WalkDeps(func(child, parent android.Module) bool {
962 if !continueApexDepsWalk(child, parent) {
963 return false
964 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900965 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900966 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900967 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900968}
969
Paul Duffina7d6a892020-12-07 17:39:59 +0000970type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100971 // ApexVariationName returns the name of the APEX variation to use in the apex
972 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
973 ApexVariationName() string
974
Paul Duffina7d6a892020-12-07 17:39:59 +0000975 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
976 // depended upon by an apex and which require an apex specific variant.
977 ApexInfoMutator(android.TopDownMutatorContext)
978}
979
980// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
981// specific variant to modules that support the ApexInfoMutator.
Spandan Das91250b12022-05-06 22:12:55 +0000982// It also propagates updatable=true to apps of updatable apexes
Paul Duffina7d6a892020-12-07 17:39:59 +0000983func apexInfoMutator(mctx android.TopDownMutatorContext) {
984 if !mctx.Module().Enabled() {
985 return
986 }
987
988 if a, ok := mctx.Module().(ApexInfoMutator); ok {
989 a.ApexInfoMutator(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +0000990 }
Spandan Das91250b12022-05-06 22:12:55 +0000991 enforceAppUpdatability(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +0000992}
993
Spandan Das66773252022-01-15 00:23:18 +0000994// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
995// This check is enforced for updatable modules
996func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
997 if !mctx.Module().Enabled() {
998 return
999 }
Spandan Das08c911f2022-01-21 22:07:26 +00001000 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +00001001 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001002 // b/208656169 Do not propagate strict updatability linting to libcore/
1003 // These libs are available on the classpath during compilation
1004 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1005 // Only skip libraries defined in libcore root, not subdirectories
1006 if mctx.OtherModuleDir(child) == "libcore" {
1007 // Do not traverse transitive deps of libcore/ libs
1008 return false
1009 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001010 if android.InList(child.Name(), skipLintJavalibAllowlist) {
1011 return false
1012 }
Spandan Das66773252022-01-15 00:23:18 +00001013 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1014 lintable.SetStrictUpdatabilityLinting(true)
1015 }
1016 // visit transitive deps
1017 return true
1018 })
1019 }
1020}
1021
Spandan Das91250b12022-05-06 22:12:55 +00001022// enforceAppUpdatability propagates updatable=true to apps of updatable apexes
1023func enforceAppUpdatability(mctx android.TopDownMutatorContext) {
1024 if !mctx.Module().Enabled() {
1025 return
1026 }
1027 if apex, ok := mctx.Module().(*apexBundle); ok && apex.Updatable() {
1028 // checking direct deps is sufficient since apex->apk is a direct edge, even when inherited via apex_defaults
1029 mctx.VisitDirectDeps(func(module android.Module) {
1030 // ignore android_test_app
1031 if app, ok := module.(*java.AndroidApp); ok {
1032 app.SetUpdatable(true)
1033 }
1034 })
1035 }
1036}
1037
Spandan Das08c911f2022-01-21 22:07:26 +00001038// TODO: b/215736885 Whittle the denylist
1039// Transitive deps of certain mainline modules baseline NewApi errors
1040// Skip these mainline modules for now
1041var (
1042 skipStrictUpdatabilityLintAllowlist = []string{
1043 "com.android.art",
1044 "com.android.art.debug",
1045 "com.android.conscrypt",
1046 "com.android.media",
1047 // test apexes
1048 "test_com.android.art",
1049 "test_com.android.conscrypt",
1050 "test_com.android.media",
1051 "test_jitzygote_com.android.art",
1052 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001053
1054 // TODO: b/215736885 Remove this list
1055 skipLintJavalibAllowlist = []string{
1056 "conscrypt.module.platform.api.stubs",
1057 "conscrypt.module.public.api.stubs",
1058 "conscrypt.module.public.api.stubs.system",
1059 "conscrypt.module.public.api.stubs.module_lib",
1060 "framework-media.stubs",
1061 "framework-media.stubs.system",
1062 "framework-media.stubs.module_lib",
1063 }
Spandan Das08c911f2022-01-21 22:07:26 +00001064)
1065
1066func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1067 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1068}
1069
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001070// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1071// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1072// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001073func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1074 if !mctx.Module().Enabled() {
1075 return
1076 }
1077 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001078 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1079 }
1080}
1081
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001082// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1083// the apex in order to retrieve its contents later.
1084// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001085func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1086 if !mctx.Module().Enabled() {
1087 return
1088 }
Colin Cross56a83212020-09-15 18:30:11 -07001089 if am, ok := mctx.Module().(android.ApexModule); ok {
1090 if testFor := am.TestFor(); len(testFor) > 0 {
1091 mctx.AddFarVariationDependencies([]blueprint.Variation{
1092 {Mutator: "os", Variation: am.Target().OsVariation()},
1093 {"arch", "common"},
1094 }, testForTag, testFor...)
1095 }
1096 }
1097}
1098
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001099// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001100func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1101 if !mctx.Module().Enabled() {
1102 return
1103 }
Colin Cross56a83212020-09-15 18:30:11 -07001104 if _, ok := mctx.Module().(android.ApexModule); ok {
1105 var contents []*android.ApexContents
1106 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1107 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1108 contents = append(contents, abInfo.Contents)
1109 }
1110 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1111 ApexContents: contents,
1112 })
Colin Crossaede88c2020-08-11 12:17:01 -07001113 }
1114}
1115
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001116// markPlatformAvailability marks whether or not a module can be available to platform. A module
1117// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1118// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1119// be) available to platform
1120// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001121func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1122 // Host and recovery are not considered as platform
1123 if mctx.Host() || mctx.Module().InstallInRecovery() {
1124 return
1125 }
1126
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001127 am, ok := mctx.Module().(android.ApexModule)
1128 if !ok {
1129 return
1130 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001131
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001132 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001133
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001134 // If any of the dep is not available to platform, this module is also considered as being
1135 // not available to platform even if it has "//apex_available:platform"
1136 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001137 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001138 // if the dependency crosses apex boundary, don't consider it
1139 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001140 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001141 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1142 availableToPlatform = false
1143 // TODO(b/154889534) trigger an error when 'am' has
1144 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001145 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001146 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001147
Paul Duffinb5769c12021-05-12 16:16:51 +01001148 // Exception 1: check to see if the module always requires it.
1149 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001150 availableToPlatform = true
1151 }
1152
1153 // Exception 2: bootstrap bionic libraries are also always available to platform
1154 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1155 availableToPlatform = true
1156 }
1157
1158 if !availableToPlatform {
1159 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001160 }
1161}
1162
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001163// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001164// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001165func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001166 if !mctx.Module().Enabled() {
1167 return
1168 }
Colin Cross56a83212020-09-15 18:30:11 -07001169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001170 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001171 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001172 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001173 return
1174 }
1175
1176 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001177 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1178 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001179 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001180 if strings.HasPrefix(apexBundleName, "com.android.art") {
1181 // Create an alias from the platform variant. This is done to make
1182 // test_for dependencies work for modules that are split by the APEX
1183 // mutator, since test_for dependencies always go to the platform variant.
1184 // This doesn't happen for normal APEXes that are disjunct, so only do
1185 // this for the overlapping ART APEXes.
1186 // TODO(b/183882457): Remove this if the test_for functionality is
1187 // refactored to depend on the proper APEX variants instead of platform.
1188 mctx.CreateAliasVariation("", apexBundleName)
1189 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001190 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1191 apexBundleName := o.GetOverriddenModuleName()
1192 if apexBundleName == "" {
1193 mctx.ModuleErrorf("base property is not set")
1194 return
1195 }
1196 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001197 if strings.HasPrefix(apexBundleName, "com.android.art") {
1198 // TODO(b/183882457): See note for CreateAliasVariation above.
1199 mctx.CreateAliasVariation("", apexBundleName)
1200 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001201 }
1202}
Sundong Ahne9b55722019-09-06 17:37:42 +09001203
Paul Duffin6717d882021-06-15 19:09:41 +01001204// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1205// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001206func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001207 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001208 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001209 return !a.vndkApex
1210 }
1211
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001212 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001213}
1214
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001215// See android.UpdateDirectlyInAnyApex
1216// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001217func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1218 if !mctx.Module().Enabled() {
1219 return
1220 }
1221 if am, ok := mctx.Module().(android.ApexModule); ok {
1222 android.UpdateDirectlyInAnyApex(mctx, am)
1223 }
1224}
1225
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001226// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001227type apexPackaging int
1228
1229const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001230 // imageApex is a packaging method where contents are included in a filesystem image which
1231 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001232 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001233
1234 // zipApex is a packaging method where contents are directly included in the zip container.
1235 // This is used for host-side testing - because the contents are easily accessible by
1236 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001237 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001238
1239 // flattendApex is a packaging method where contents are not included in the APEX file, but
1240 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1241 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001242 flattenedApex
1243)
1244
1245const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001247 imageApexSuffix = ".apex"
1248 imageCapexSuffix = ".capex"
1249 zipApexSuffix = ".zipapex"
1250 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001251
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001252 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001253 imageApexType = "image"
1254 zipApexType = "zip"
1255 flattenedApexType = "flattened"
1256
Dan Willemsen47e1a752021-10-16 18:36:13 -07001257 ext4FsType = "ext4"
1258 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001259 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001260)
1261
1262// The suffix for the output "file", not the module
1263func (a apexPackaging) suffix() string {
1264 switch a {
1265 case imageApex:
1266 return imageApexSuffix
1267 case zipApex:
1268 return zipApexSuffix
1269 default:
1270 panic(fmt.Errorf("unknown APEX type %d", a))
1271 }
1272}
1273
1274func (a apexPackaging) name() string {
1275 switch a {
1276 case imageApex:
1277 return imageApexType
1278 case zipApex:
1279 return zipApexType
1280 default:
1281 panic(fmt.Errorf("unknown APEX type %d", a))
1282 }
1283}
1284
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001285// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1286// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001287func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001288 if !mctx.Module().Enabled() {
1289 return
1290 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001291 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001292 var variants []string
1293 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1294 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001295 // This is the normal case. Note that both image and flattend APEXes are
1296 // created. The image type is installed to the system partition, while the
1297 // flattened APEX is (optionally) installed to the system_ext partition.
1298 // This is mostly for GSI which has to support wide range of devices. If GSI
1299 // is installed on a newer (APEX-capable) device, the image APEX in the
1300 // system will be used. However, if the same GSI is installed on an old
1301 // device which can't support image APEX, the flattened APEX in the
1302 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001303 variants = append(variants, imageApexType, flattenedApexType)
1304 case "zip":
1305 variants = append(variants, zipApexType)
1306 case "both":
1307 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1308 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001309 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001310 return
1311 }
1312
1313 modules := mctx.CreateLocalVariations(variants...)
1314
1315 for i, v := range variants {
1316 switch v {
1317 case imageApexType:
1318 modules[i].(*apexBundle).properties.ApexType = imageApex
1319 case zipApexType:
1320 modules[i].(*apexBundle).properties.ApexType = zipApex
1321 case flattenedApexType:
1322 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001323 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001324 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001325 modules[i].(*apexBundle).MakeAsSystemExt()
1326 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001327 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001328 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001329 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001330 // payload_type is forcibly overridden to "image"
1331 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001332 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001333 }
1334}
1335
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001336var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001337
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001338// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001339func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1340 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001341 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001342 return true
1343}
1344
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001345var _ android.OutputFileProducer = (*apexBundle)(nil)
1346
1347// Implements android.OutputFileProducer
1348func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1349 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001350 case "", android.DefaultDistTag:
1351 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001352 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001353 case imageApexSuffix:
1354 // uncompressed one
1355 if a.outputApexFile != nil {
1356 return android.Paths{a.outputApexFile}, nil
1357 }
1358 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001359 default:
1360 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1361 }
1362}
1363
1364var _ cc.Coverage = (*apexBundle)(nil)
1365
1366// Implements cc.Coverage
1367func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1368 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1369}
1370
1371// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001372func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001373 a.properties.PreventInstall = true
1374}
1375
1376// Implements cc.Coverage
1377func (a *apexBundle) HideFromMake() {
1378 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001379 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1380 // TODO(ccross): untangle these
1381 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001382}
1383
1384// Implements cc.Coverage
1385func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1386 a.properties.IsCoverageVariant = coverage
1387}
1388
1389// Implements cc.Coverage
1390func (a *apexBundle) EnableCoverageIfNeeded() {}
1391
1392var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1393
Oriol Prieto Gasco2c4a9632021-10-14 15:33:41 -04001394// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001395func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001396 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397}
1398
Jiyong Parkf4020582021-11-29 12:37:10 +09001399func (a *apexBundle) FutureUpdatable() bool {
1400 return proptools.BoolDefault(a.properties.Future_updatable, false)
1401}
1402
Jiyong Park1bc84122021-06-22 20:23:05 +09001403func (a *apexBundle) UsePlatformApis() bool {
1404 return proptools.BoolDefault(a.properties.Platform_apis, false)
1405}
1406
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001407// getCertString returns the name of the cert that should be used to sign this APEX. This is
1408// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001409func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001410 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001411 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1412 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1413 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001414 if a.vndkApex {
1415 moduleName = vndkApexName
1416 }
1417 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001418 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001419 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001420 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001421 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001422}
1423
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001424// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001425func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001426 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001427}
1428
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001429// See the generate_hashtree property
1430func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001431 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001432}
1433
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001434// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001435func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1436 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1437}
1438
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001439// See the test_only_force_compression property
1440func (a *apexBundle) testOnlyShouldForceCompression() bool {
1441 return proptools.Bool(a.properties.Test_only_force_compression)
1442}
1443
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001444// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1445// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1446// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001447
Jiyong Parkf97782b2019-02-13 20:28:58 +09001448func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1449 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1450 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1451 }
1452}
1453
Jiyong Park388ef3f2019-01-28 19:47:32 +09001454func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001455 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1456 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001457 }
1458
1459 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001460 globalSanitizerNames := []string{}
1461 if a.Host() {
1462 globalSanitizerNames = ctx.Config().SanitizeHost()
1463 } else {
1464 arches := ctx.Config().SanitizeDeviceArch()
1465 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1466 globalSanitizerNames = ctx.Config().SanitizeDevice()
1467 }
1468 }
1469 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001470}
1471
Jooyung Han8ce8db92020-05-15 19:05:05 +09001472func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001473 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1474 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001475 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001476 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001477 for _, target := range ctx.MultiTargets() {
1478 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001479 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Crossfc0df952022-02-10 11:41:18 -08001480 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001481 Tests: nil,
1482 Jni_libs: nil,
1483 Binaries: nil,
1484 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001485 break
1486 }
1487 }
1488 }
1489}
1490
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001491// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1492// returned apexFile saves information about the Soong module that will be used for creating the
1493// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001494func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001495 // Decide the APEX-local directory by the multilib of the library In the future, we may
1496 // query this to the module.
1497 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001498 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001499 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001500 case "lib32":
1501 dirInApex = "lib"
1502 case "lib64":
1503 dirInApex = "lib64"
1504 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001505 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001506 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001507 }
Jooyung Han35155c42020-02-06 17:33:20 +09001508 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001509 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001510 // Special case for Bionic libs and other libs installed with them. This is to
1511 // prevent those libs from being included in the search path
1512 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1513 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1514 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1515 // will be loaded into the default linker namespace (aka "platform" namespace). If
1516 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1517 // be loaded again into the runtime linker namespace, which will result in double
1518 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001519 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001520 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001521
Jiyong Parkf653b052019-11-18 15:39:01 +09001522 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001523 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1524 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001525}
1526
Jiyong Park1833cef2019-12-13 13:28:36 +09001527func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001528 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001529 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001530 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001531 }
Jooyung Han35155c42020-02-06 17:33:20 +09001532 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001533 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001534 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1535 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001536 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001537 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001538 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001539}
1540
Jiyong Park99644e92020-11-17 22:21:02 +09001541func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1542 dirInApex := "bin"
1543 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1544 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1545 }
1546 fileToCopy := rustm.OutputFile().Path()
1547 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1548 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1549 return af
1550}
1551
1552func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1553 // Decide the APEX-local directory by the multilib of the library
1554 // In the future, we may query this to the module.
1555 var dirInApex string
1556 switch rustm.Arch().ArchType.Multilib {
1557 case "lib32":
1558 dirInApex = "lib"
1559 case "lib64":
1560 dirInApex = "lib64"
1561 }
1562 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1563 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1564 }
1565 fileToCopy := rustm.OutputFile().Path()
1566 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1567 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1568}
1569
Jiyong Park1833cef2019-12-13 13:28:36 +09001570func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001571 dirInApex := "bin"
1572 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001573 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001574}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001575
Jiyong Park1833cef2019-12-13 13:28:36 +09001576func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001577 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001578 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001579 // NB: Since go binaries are static we don't need the module for anything here, which is
1580 // good since the go tool is a blueprint.Module not an android.Module like we would
1581 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001582 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001583}
1584
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001585func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001586 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001587 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1588 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1589 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001590 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001591 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001592 af.symlinks = sh.Symlinks()
1593 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001594}
1595
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001596func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001597 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001598 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001599 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001600}
1601
atrost6e126252020-01-27 17:01:16 +00001602func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1603 dirInApex := filepath.Join("etc", config.SubDir())
1604 fileToCopy := config.CompatConfig()
1605 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1606}
1607
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001608// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1609// way.
1610type javaModule interface {
1611 android.Module
1612 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001613 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001614 JacocoReportClassesFile() android.Path
1615 LintDepSets() java.LintDepSets
1616 Stem() string
1617}
1618
1619var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001620var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001621var _ javaModule = (*java.SdkLibrary)(nil)
1622var _ javaModule = (*java.DexImport)(nil)
1623var _ javaModule = (*java.SdkLibraryImport)(nil)
1624
Paul Duffin190fdef2021-04-26 10:33:59 +01001625// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001626func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001627 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001628}
1629
1630// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1631func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001633 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001634 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1635 af.lintDepSets = module.LintDepSets()
1636 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001637 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1638 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1639 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1640 }
1641 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001642 return af
1643}
1644
1645// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1646// the same way.
1647type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001648 android.Module
1649 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001650 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001651 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001652 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001653 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001654 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001655 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001656}
1657
1658var _ androidApp = (*java.AndroidApp)(nil)
1659var _ androidApp = (*java.AndroidAppImport)(nil)
1660
Oriol Prieto Gascóa70425f2022-05-20 13:05:34 +00001661func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string {
1662 buildId := ctx.Config().BuildId()
1663
1664 // The build ID is used as a suffix for a filename, so ensure that
1665 // the set of characters being used are sanitized.
1666 // - any word character: [a-zA-Z0-9_]
1667 // - dots: .
1668 // - dashes: -
1669 validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`)
1670 if !validRegex.MatchString(buildId) {
1671 ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId)
1672 }
1673 return buildId
1674}
Jingwen Chen11cca672022-03-25 02:57:49 +00001675
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001676func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001677 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001679 appDir = "priv-app"
1680 }
Jingwen Chen11cca672022-03-25 02:57:49 +00001681
1682 // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed
1683 // so that PackageManager correctly invalidates the existing installed apk
1684 // in favour of the new APK-in-APEX. See bugs for more information.
Oriol Prieto Gascóa70425f2022-05-20 13:05:34 +00001685 dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx))
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 fileToCopy := aapp.OutputFile()
Jingwen Chen11cca672022-03-25 02:57:49 +00001687
Yo Chiange8128052020-07-23 20:09:18 +08001688 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001689 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001690 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001691 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001692
1693 if app, ok := aapp.(interface {
1694 OverriddenManifestPackageName() string
1695 }); ok {
1696 af.overriddenPackageName = app.OverriddenManifestPackageName()
1697 }
Jiyong Park618922e2020-01-08 13:35:43 +09001698 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001699}
1700
Jiyong Park69aeba92020-04-24 21:16:36 +09001701func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1702 rroDir := "overlay"
1703 dirInApex := filepath.Join(rroDir, rro.Theme())
1704 fileToCopy := rro.OutputFile()
1705 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1706 af.certificate = rro.Certificate()
1707
1708 if a, ok := rro.(interface {
1709 OverriddenManifestPackageName() string
1710 }); ok {
1711 af.overriddenPackageName = a.OverriddenManifestPackageName()
1712 }
1713 return af
1714}
1715
Ken Chenfad7f9d2021-11-10 22:02:57 +08001716func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1717 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001718 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1719}
1720
Jiyong Park12a719c2021-01-07 15:31:24 +09001721func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1722 dirInApex := filepath.Join("etc", "fs")
1723 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1724}
1725
Paul Duffin064b70c2020-11-02 17:32:38 +00001726// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001727// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1728// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1729// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001730func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001731 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001732 am, ok := child.(android.ApexModule)
1733 if !ok || !am.CanHaveApexVariants() {
1734 return false
1735 }
1736
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001737 // Filter-out unwanted depedendencies
1738 depTag := ctx.OtherModuleDependencyTag(child)
1739 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1740 return false
1741 }
Paul Duffine4713a82022-05-13 13:01:59 +00001742 if dt, ok := depTag.(*dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001743 return false
1744 }
1745
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001746 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001747 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001748
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001749 // Visit actually
1750 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001751 })
1752}
1753
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001754// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1755type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001756
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001757const (
1758 ext4 fsType = iota
1759 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001760 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001761)
Artur Satayev849f8442020-04-28 14:57:42 +01001762
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001763func (f fsType) string() string {
1764 switch f {
1765 case ext4:
1766 return ext4FsType
1767 case f2fs:
1768 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001769 case erofs:
1770 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001771 default:
1772 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001773 }
1774}
1775
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001776// Creates build rules for an APEX. It consists of the following major steps:
1777//
1778// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1779// 2) traverse the dependency tree to collect apexFile structs from them.
1780// 3) some fields in apexBundle struct are configured
1781// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001782func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001783 ////////////////////////////////////////////////////////////////////////////////////////////
1784 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001785 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001786 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001787 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001788 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001789 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001790 if len(a.properties.Tests) > 0 && !a.testApex {
1791 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1792 return
1793 }
Jiyong Park678c8812020-02-07 17:25:49 +09001794
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001795 ////////////////////////////////////////////////////////////////////////////////////////////
1796 // 2) traverse the dependency tree to collect apexFile structs from them.
1797
1798 // all the files that will be included in this APEX
1799 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001800
Jooyung Hane1633032019-08-01 17:41:43 +09001801 // native lib dependencies
1802 var provideNativeLibs []string
1803 var requireNativeLibs []string
1804
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001805 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1806
braleeb0c1f0c2021-06-07 22:49:13 +08001807 // Collect the module directory for IDE info in java/jdeps.go.
1808 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1809
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001810 // TODO(jiyong): do this using WalkPayloadDeps
1811 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001812 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001813 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001814 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1815 return false
1816 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001817 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1818 return false
1819 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001820 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001821 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001822 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001823 case sharedLibTag, jniLibTag:
1824 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001825 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001826 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1827 fi.isJniLib = isJniLib
1828 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001829 // Collect the list of stub-providing libs except:
1830 // - VNDK libs are only for vendors
1831 // - bootstrap bionic libs are treated as provided by system
1832 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001833 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001834 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001835 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001836 } else if r, ok := child.(*rust.Module); ok {
1837 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001838 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001839 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001840 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001841 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001842 propertyName := "native_shared_libs"
1843 if isJniLib {
1844 propertyName = "jni_libs"
1845 }
1846 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001847 }
1848 case executableTag:
1849 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001850 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001851 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001852 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001853 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001854 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001855 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001856 } else if rust, ok := child.(*rust.Module); ok {
1857 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1858 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001859 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001860 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1861 }
1862 case shBinaryTag:
1863 if sh, ok := child.(*sh.ShBinary); ok {
1864 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1865 } else {
1866 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001867 }
Paul Duffin94f19632021-04-20 12:40:07 +01001868 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001869 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001870 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1871 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001872 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001873 return false
1874 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001875
Paul Duffincc33ec82021-04-25 23:14:55 +01001876 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1877 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001878 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1879 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1880 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001881 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001882 }
satayev333a1732021-05-17 21:35:26 +01001883 case sscpfTag:
1884 {
1885 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1886 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1887 return false
1888 }
satayevb98371c2021-06-15 16:49:50 +01001889 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1890 filesInfo = append(filesInfo, *af)
1891 }
satayev333a1732021-05-17 21:35:26 +01001892 return true
1893 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001894 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001895 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001896 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001897 af := apexFileForJavaModule(ctx, child.(javaModule))
1898 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001899 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1900 return false
1901 }
1902 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001903 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001904 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001905 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001906 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001907 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001908 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001909 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001910 return true // track transitive dependencies
1911 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001912 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001913 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001914 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001915 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1916 appDir := "app"
1917 if ap.Privileged() {
1918 appDir = "priv-app"
1919 }
Jingwen Chen11cca672022-03-25 02:57:49 +00001920 // TODO(b/224589412, b/226559955): Ensure that the dirname is
1921 // suffixed so that PackageManager correctly invalidates the
1922 // existing installed apk in favour of the new APK-in-APEX.
1923 // See bugs for more information.
Oriol Prieto Gascóa70425f2022-05-20 13:05:34 +00001924 appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx))
Jingwen Chen11cca672022-03-25 02:57:49 +00001925 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap)
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001926 af.certificate = java.PresignedCertificate
1927 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001928 } else {
1929 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1930 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001931 case rroTag:
1932 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1933 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1934 } else {
1935 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1936 }
markchien2f59ec92020-09-02 16:23:38 +08001937 case bpfTag:
1938 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1939 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001940 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001941 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001942 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001943 }
1944 } else {
1945 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1946 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001947 case fsTag:
1948 if fs, ok := child.(filesystem.Filesystem); ok {
1949 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1950 } else {
1951 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1952 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001953 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001954 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001955 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001956 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001957 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001958 }
Paul Duffin0b817782021-03-17 15:02:19 +00001959 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001960 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1961 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1962 } else {
1963 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1964 }
Roland Levillain630846d2019-06-26 12:48:34 +01001965 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001966 if ccTest, ok := child.(*cc.Module); ok {
1967 if ccTest.IsTestPerSrcAllTestsVariation() {
1968 // Multiple-output test module (where `test_per_src: true`).
1969 //
1970 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1971 // We do not add this variation to `filesInfo`, as it has no output;
1972 // however, we do add the other variations of this module as indirect
1973 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001974 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001975 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001976 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001977 af.class = nativeTest
1978 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001979 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001980 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001981 } else {
1982 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1983 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001984 case keyTag:
1985 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001986 a.privateKeyFile = key.privateKeyFile
1987 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001988 } else {
1989 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001990 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001991 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001992 case certificateTag:
1993 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001994 a.containerCertificateFile = dep.Certificate.Pem
1995 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001996 } else {
1997 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1998 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001999 case android.PrebuiltDepTag:
2000 // If the prebuilt is force disabled, remember to delete the prebuilt file
2001 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002002 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002003 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2004 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002005 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002006 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002007 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002008 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002009 // We cannot use a switch statement on `depTag` here as the checked
2010 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002011 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002012 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09002013 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002014 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002015 return false
2016 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002017 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2018 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002019
2020 // Always track transitive dependencies for host.
2021 if a.Host() {
2022 filesInfo = append(filesInfo, af)
2023 return true
2024 }
2025
Colin Cross56a83212020-09-15 18:30:11 -07002026 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002027 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002028 // If the dependency is a stubs lib, don't include it in this APEX,
2029 // but make sure that the lib is installed on the device.
2030 // In case no APEX is having the lib, the lib is installed to the system
2031 // partition.
2032 //
2033 // Always include if we are a host-apex however since those won't have any
2034 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002035 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002036 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00002037 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002038 if !android.InList(name, a.requiredDeps) {
2039 a.requiredDeps = append(a.requiredDeps, name)
2040 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002041 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002042 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002043 // Don't track further
2044 return false
2045 }
Jiyong Parke3867542020-12-03 17:28:25 +09002046
2047 // If the dep is not considered to be in the same
2048 // apex, don't add it to filesInfo so that it is not
2049 // included in this APEX.
2050 // TODO(jiyong): move this to at the top of the
2051 // else-if clause for the indirect dependencies.
2052 // Currently, that's impossible because we would
2053 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002054 // DepIsInSameAPex is false. We also shouldn't do
2055 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002056 //
2057 // TODO(jiyong): explain why the same module is passed in twice.
2058 // Switching the first am to parent breaks lots of tests.
2059 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002060 return false
2061 }
2062
Jiyong Parkf653b052019-11-18 15:39:01 +09002063 filesInfo = append(filesInfo, af)
2064 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002065 } else if rm, ok := child.(*rust.Module); ok {
2066 af := apexFileForRustLibrary(ctx, rm)
2067 af.transitiveDep = true
2068 filesInfo = append(filesInfo, af)
2069 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002070 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002071 } else if cc.IsTestPerSrcDepTag(depTag) {
2072 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002073 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002074 // Handle modules created as `test_per_src` variations of a single test module:
2075 // use the name of the generated test binary (`fileToCopy`) instead of the name
2076 // of the original test module (`depName`, shared by all `test_per_src`
2077 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002078 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002079 // these are not considered transitive dep
2080 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002081 filesInfo = append(filesInfo, af)
2082 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002083 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002084 } else if cc.IsHeaderDepTag(depTag) {
2085 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002086 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002087 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2088 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002089 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002090 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002091 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2092 }
Jiyong Park99644e92020-11-17 22:21:02 +09002093 } else if rust.IsDylibDepTag(depTag) {
2094 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2095 af := apexFileForRustLibrary(ctx, rustm)
2096 af.transitiveDep = true
2097 filesInfo = append(filesInfo, af)
2098 return true // track transitive dependencies
2099 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002100 } else if rust.IsRlibDepTag(depTag) {
2101 // Rlib is statically linked, but it might have shared lib
2102 // dependencies. Track them.
2103 return true
Paul Duffin65898052021-04-20 22:47:03 +01002104 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002105 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002106 switch child.(type) {
2107 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002108 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002109 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002110 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002111 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002112 return false
2113 }
2114 filesInfo = append(filesInfo, af)
2115 return true // track transitive dependencies
2116 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002117 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 +00002118 }
satayev333a1732021-05-17 21:35:26 +01002119 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2120 // Add the contents of the systemserverclasspath fragment to the apex.
2121 switch child.(type) {
2122 case *java.Library, *java.SdkLibrary:
2123 af := apexFileForJavaModule(ctx, child.(javaModule))
2124 filesInfo = append(filesInfo, af)
2125 return true // track transitive dependencies
2126 default:
2127 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2128 }
Colin Cross56a83212020-09-15 18:30:11 -07002129 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2130 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002131 } else if depTag == android.DarwinUniversalVariantTag {
2132 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002133 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002134 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002135 }
2136 }
2137 }
2138 return false
2139 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002140 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002141 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002142 return
2143 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002144
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002145 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002146 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002147 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002148 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002149 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002150 if e, ok := encountered[dest]; !ok {
2151 encountered[dest] = f
2152 } else {
2153 // If a module is directly included and also transitively depended on
2154 // consider it as directly included.
2155 e.transitiveDep = e.transitiveDep && f.transitiveDep
2156 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002157 }
2158 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002159 var result []apexFile
2160 for _, v := range encountered {
2161 result = append(result, v)
2162 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002163 return result
2164 }
2165 filesInfo = removeDup(filesInfo)
2166
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002167 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002168 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002169 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2170 // changes.
2171 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002172 })
2173
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002174 ////////////////////////////////////////////////////////////////////////////////////////////
2175 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002176 a.installDir = android.PathForModuleInstall(ctx, "apex")
2177 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002178
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002179 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002180 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002181 switch a.properties.ApexType {
2182 case imageApex:
2183 if buildFlattenedAsDefault {
2184 a.suffix = imageApexSuffix
2185 } else {
2186 a.suffix = ""
2187 a.primaryApexType = true
2188
2189 if ctx.Config().InstallExtraFlattenedApexes() {
2190 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2191 }
2192 }
2193 case zipApex:
2194 if proptools.String(a.properties.Payload_type) == "zip" {
2195 a.suffix = ""
2196 a.primaryApexType = true
2197 } else {
2198 a.suffix = zipApexSuffix
2199 }
2200 case flattenedApex:
2201 if buildFlattenedAsDefault {
2202 a.suffix = ""
2203 a.primaryApexType = true
2204 } else {
2205 a.suffix = flattenedSuffix
2206 }
2207 }
2208
Theotime Combes4ba38c12020-06-12 12:46:59 +00002209 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2210 case ext4FsType:
2211 a.payloadFsType = ext4
2212 case f2fsFsType:
2213 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002214 case erofsFsType:
2215 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002216 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002217 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 +00002218 }
2219
Jiyong Park7cd10e32020-01-14 09:22:18 +09002220 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2221 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2222 // the same library in the system partition, thus effectively sharing the same libraries
2223 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2224 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002225 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002226
Jooyung Han85d61762020-06-24 23:50:26 +09002227 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2228 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002229 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002230 a.linkToSystemLib = false
2231 }
2232
Jiyong Park4da07972021-01-05 21:01:11 +09002233 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002234 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002235
Jiyong Park9d677202020-02-19 16:29:35 +09002236 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002237 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002238 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002239 a.linkToSystemLib = false
2240 }
2241
Jiyong Park638d30e2020-02-26 18:27:19 +09002242 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2243 if ctx.Host() {
2244 a.linkToSystemLib = false
2245 }
2246
Colin Cross6340ea52021-11-04 12:01:18 -07002247 if a.properties.ApexType != zipApex {
2248 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2249 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002250
2251 ////////////////////////////////////////////////////////////////////////////////////////////
2252 // 4) generate the build rules to create the APEX. This is done in builder.go.
2253 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002254 if a.properties.ApexType == flattenedApex {
2255 a.buildFlattenedApex(ctx)
2256 } else {
2257 a.buildUnflattenedApex(ctx)
2258 }
Jiyong Park956305c2020-01-09 12:32:06 +09002259 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002260 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002261
2262 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2263 if a.installable() {
2264 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2265 // along with other ordinary files. (Note that this is done by apexer for
2266 // non-flattened APEXes)
2267 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2268
2269 // Place the public key as apex_pubkey. This is also done by apexer for
2270 // non-flattened APEXes case.
2271 // TODO(jiyong): Why do we need this CP rule?
2272 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2273 ctx.Build(pctx, android.BuildParams{
2274 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002275 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002276 Output: copiedPubkey,
2277 })
2278 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2279 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002280}
2281
Paul Duffincc33ec82021-04-25 23:14:55 +01002282// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2283// the bootclasspath_fragment contributes to the apex.
2284func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2285 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2286 var filesToAdd []apexFile
2287
2288 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002289 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2290 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2291 dirInApex := filepath.Join("javalib", arch.String())
2292 for _, f := range files {
2293 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2294 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2295 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2296 filesToAdd = append(filesToAdd, af)
2297 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002298 }
2299 }
2300
satayev3db35472021-05-06 23:59:58 +01002301 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002302 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2303 filesToAdd = append(filesToAdd, *af)
2304 }
satayev3db35472021-05-06 23:59:58 +01002305
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002306 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2307 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2308 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2309
2310 if pathOnHost != nil {
2311 // We need to copy the profile to a temporary path with the right filename because the apexer
2312 // will take the filename as is.
2313 ctx.Build(pctx, android.BuildParams{
2314 Rule: android.Cp,
2315 Input: pathOnHost,
2316 Output: tempPath,
2317 })
2318 } else {
2319 // At this point, the boot image profile cannot be generated. It is probably because the boot
2320 // image profile source file does not exist on the branch, or it is not available for the
2321 // current build target.
2322 // However, we cannot enforce the boot image profile to be generated because some build
2323 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2324 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2325 // only if the APEX is being built.
2326 ctx.Build(pctx, android.BuildParams{
2327 Rule: android.ErrorRule,
2328 Output: tempPath,
2329 Args: map[string]string{
2330 "error": "Boot image profile cannot be generated",
2331 },
2332 })
2333 }
2334
2335 androidMkModuleName := filepath.Base(pathInApex)
2336 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2337 filesToAdd = append(filesToAdd, af)
2338 }
2339
Paul Duffincc33ec82021-04-25 23:14:55 +01002340 return filesToAdd
2341}
2342
satayevb98371c2021-06-15 16:49:50 +01002343// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2344// the module contributes to the apex; or nil if the proto config was not generated.
2345func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2346 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2347 if !info.ClasspathFragmentProtoGenerated {
2348 return nil
2349 }
2350 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2351 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2352 return &af
satayev14e49132021-05-17 21:03:07 +01002353}
2354
Paul Duffincc33ec82021-04-25 23:14:55 +01002355// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2356// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002357func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2358 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2359
2360 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2361 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002362 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2363 if err != nil {
2364 ctx.ModuleErrorf("%s", err)
2365 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002366
2367 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2368 // bootclasspath_fragment.
2369 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2370 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002371}
2372
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002373///////////////////////////////////////////////////////////////////////////////////////////////////
2374// Factory functions
2375//
2376
2377func newApexBundle() *apexBundle {
2378 module := &apexBundle{}
2379
2380 module.AddProperties(&module.properties)
2381 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002382 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002383 module.AddProperties(&module.overridableProperties)
2384
2385 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2386 android.InitDefaultableModule(module)
2387 android.InitSdkAwareModule(module)
2388 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002389 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002390 return module
2391}
2392
Paul Duffineb8051d2021-10-18 17:49:39 +01002393func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002394 bundle := newApexBundle()
2395 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002396 return bundle
2397}
2398
2399// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2400// certain compatibility checks such as apex_available are not done for apex_test.
2401func testApexBundleFactory() android.Module {
2402 bundle := newApexBundle()
2403 bundle.testApex = true
2404 return bundle
2405}
2406
2407// apex packages other modules into an APEX file which is a packaging format for system-level
2408// components like binaries, shared libraries, etc.
2409func BundleFactory() android.Module {
2410 return newApexBundle()
2411}
2412
2413type Defaults struct {
2414 android.ModuleBase
2415 android.DefaultsModuleBase
2416}
2417
2418// apex_defaults provides defaultable properties to other apex modules.
2419func defaultsFactory() android.Module {
2420 return DefaultsFactory()
2421}
2422
2423func DefaultsFactory(props ...interface{}) android.Module {
2424 module := &Defaults{}
2425
2426 module.AddProperties(props...)
2427 module.AddProperties(
2428 &apexBundleProperties{},
2429 &apexTargetBundleProperties{},
2430 &overridableProperties{},
2431 )
2432
2433 android.InitDefaultsModule(module)
2434 return module
2435}
2436
2437type OverrideApex struct {
2438 android.ModuleBase
2439 android.OverrideModuleBase
2440}
2441
2442func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2443 // All the overrides happen in the base module.
2444}
2445
2446// override_apex is used to create an apex module based on another apex module by overriding some of
2447// its properties.
2448func overrideApexFactory() android.Module {
2449 m := &OverrideApex{}
2450
2451 m.AddProperties(&overridableProperties{})
2452
2453 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2454 android.InitOverrideModule(m)
2455 return m
2456}
2457
2458///////////////////////////////////////////////////////////////////////////////////////////////////
2459// Vality check routines
2460//
2461// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2462// certain conditions are not met.
2463//
2464// TODO(jiyong): move these checks to a separate go file.
2465
satayevad991492021-12-03 18:58:32 +00002466var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2467
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002468// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2469// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002470func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002471 if a.testApex || a.vndkApex {
2472 return
2473 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002474 // apexBundle::minSdkVersion reports its own errors.
2475 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002476 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002477}
2478
Albert Martin55ccba22022-03-21 20:11:16 +00002479// Returns apex's min_sdk_version string value, honoring overrides
2480func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
2481 // Only override the minSdkVersion value on Apexes which already specify
2482 // a min_sdk_version (it's optional for non-updatable apexes), and that its
2483 // min_sdk_version value is lower than the one to override with.
2484 overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride()
2485 overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue)
2486 originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
2487 isMinSdkSet := a.properties.Min_sdk_version != nil
2488 isOverrideValueHigher := overrideApiLevel.CompareTo(originalMinApiLevel) > 0
2489 if overrideMinSdkValue != "" && isMinSdkSet && isOverrideValueHigher {
2490 return overrideMinSdkValue
2491 }
2492
2493 return proptools.String(a.properties.Min_sdk_version)
2494}
2495
2496// Returns apex's min_sdk_version SdkSpec, honoring overrides
satayevad991492021-12-03 18:58:32 +00002497func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2498 return android.SdkSpec{
2499 Kind: android.SdkNone,
2500 ApiLevel: a.minSdkVersion(ctx),
Albert Martin55ccba22022-03-21 20:11:16 +00002501 Raw: a.minSdkVersionValue(ctx),
satayevad991492021-12-03 18:58:32 +00002502 }
2503}
2504
Albert Martin55ccba22022-03-21 20:11:16 +00002505// Returns apex's min_sdk_version ApiLevel, honoring overrides
satayevad991492021-12-03 18:58:32 +00002506func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Albert Martin55ccba22022-03-21 20:11:16 +00002507 return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx))
2508}
2509
2510// Construct ApiLevel object from min_sdk_version string value
2511func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel {
2512 if value == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002513 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002514 }
Albert Martin55ccba22022-03-21 20:11:16 +00002515 apiLevel, err := android.ApiLevelFromUser(ctx, value)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002516 if err != nil {
2517 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2518 return android.NoneApiLevel
2519 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002520 return apiLevel
2521}
2522
2523// Ensures that a lib providing stub isn't statically linked
2524func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2525 // Practically, we only care about regular APEXes on the device.
2526 if ctx.Host() || a.testApex || a.vndkApex {
2527 return
2528 }
2529
2530 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2531
2532 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2533 if ccm, ok := to.(*cc.Module); ok {
2534 apexName := ctx.ModuleName()
2535 fromName := ctx.OtherModuleName(from)
2536 toName := ctx.OtherModuleName(to)
2537
2538 // If `to` is not actually in the same APEX as `from` then it does not need
2539 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002540 //
2541 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002542 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2543 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2544 return false
2545 }
2546
2547 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2548 // exception to this rule. It can't make the static dependencies dynamic
2549 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002550 // Same rule should be applied to linkerconfig, because it should be executed
2551 // only with static linked libraries before linker is available with ld.config.txt
2552 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002553 return false
2554 }
2555
2556 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2557 if isStubLibraryFromOtherApex && !externalDep {
2558 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2559 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2560 }
2561
2562 }
2563 return true
2564 })
2565}
2566
satayevb98371c2021-06-15 16:49:50 +01002567// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002568func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2569 if a.Updatable() {
Albert Martin55ccba22022-03-21 20:11:16 +00002570 if a.minSdkVersionValue(ctx) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002571 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2572 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002573 if a.UsePlatformApis() {
2574 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2575 }
Daniel Norman69109112021-12-02 12:52:42 -08002576 if a.SocSpecific() || a.DeviceSpecific() {
2577 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2578 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002579 if a.FutureUpdatable() {
2580 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2581 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002582 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002583 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002584 }
2585}
2586
satayevb98371c2021-06-15 16:49:50 +01002587// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2588func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2589 ctx.VisitDirectDeps(func(module android.Module) {
2590 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2591 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2592 if !info.ClasspathFragmentProtoGenerated {
2593 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2594 }
2595 }
2596 })
2597}
2598
2599// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002600func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002601 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2602 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002603 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2604 tag := ctx.OtherModuleDependencyTag(module)
2605 switch tag {
2606 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002607 if m, ok := module.(interface {
2608 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2609 }); ok {
2610 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002611 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2612 }
2613 }
2614 }
2615 })
2616}
2617
satayevb98371c2021-06-15 16:49:50 +01002618// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002619func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2620 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2621 if ctx.Host() || a.testApex || a.vndkApex {
2622 return
2623 }
2624
2625 // Because APEXes targeting other than system/system_ext partitions can't set
2626 // apex_available, we skip checks for these APEXes
2627 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2628 return
2629 }
2630
2631 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2632 // Requiring them and their transitive depencies with apex_available is not right
2633 // because they just add noise.
2634 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2635 return
2636 }
2637
2638 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2639 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2640 if externalDep {
2641 return false
2642 }
2643
2644 apexName := ctx.ModuleName()
2645 fromName := ctx.OtherModuleName(from)
2646 toName := ctx.OtherModuleName(to)
2647
2648 // If `to` is not actually in the same APEX as `from` then it does not need
2649 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002650 //
2651 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002652 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2653 // As soon as the dependency graph crosses the APEX boundary, don't go
2654 // further.
2655 return false
2656 }
2657
2658 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2659 return true
2660 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002661 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2662 "\n\nDependency path:%s\n\n"+
2663 "Consider adding %q to 'apex_available' property of %q",
2664 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002665 // Visit this module's dependencies to check and report any issues with their availability.
2666 return true
2667 })
2668}
2669
Jiyong Park192600a2021-08-03 07:52:17 +00002670// checkStaticExecutable ensures that executables in an APEX are not static.
2671func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002672 // No need to run this for host APEXes
2673 if ctx.Host() {
2674 return
2675 }
2676
Jiyong Park192600a2021-08-03 07:52:17 +00002677 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2678 if ctx.OtherModuleDependencyTag(module) != executableTag {
2679 return
2680 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002681
2682 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002683 apex := a.ApexVariationName()
2684 exec := ctx.OtherModuleName(module)
2685 if isStaticExecutableAllowed(apex, exec) {
2686 return
2687 }
2688 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2689 }
2690 })
2691}
2692
2693// A small list of exceptions where static executables are allowed in APEXes.
2694func isStaticExecutableAllowed(apex string, exec string) bool {
2695 m := map[string][]string{
2696 "com.android.runtime": []string{
2697 "linker",
2698 "linkerconfig",
2699 },
2700 }
2701 execNames, ok := m[apex]
2702 return ok && android.InList(exec, execNames)
2703}
2704
braleeb0c1f0c2021-06-07 22:49:13 +08002705// Collect information for opening IDE project files in java/jdeps.go.
2706func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Remi NGUYEN VANbe901722022-03-02 21:00:33 +09002707 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
2708 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
2709 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002710 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2711}
2712
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002713var (
2714 apexAvailBaseline = makeApexAvailableBaseline()
2715 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2716)
2717
Colin Cross440e0d02020-06-11 11:32:11 -07002718func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002719 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002720 moduleName = normalizeModuleName(moduleName)
2721
Colin Cross440e0d02020-06-11 11:32:11 -07002722 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002723 return true
2724 }
2725
2726 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002727 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002728 return true
2729 }
2730
2731 return false
2732}
2733
2734func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002735 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2736 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002737 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002738 if strings.HasPrefix(moduleName, "libclang_rt.") {
2739 // This module has many arch variants that depend on the product being built.
2740 // We don't want to list them all
2741 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002742 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002743 if strings.HasPrefix(moduleName, "androidx.") {
2744 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2745 moduleName = "androidx"
2746 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002747 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002748}
2749
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002750// Transform the map of apex -> modules to module -> apexes.
2751func invertApexBaseline(m map[string][]string) map[string][]string {
2752 r := make(map[string][]string)
2753 for apex, modules := range m {
2754 for _, module := range modules {
2755 r[module] = append(r[module], apex)
2756 }
2757 }
2758 return r
2759}
2760
2761// Retrieve the baseline of apexes to which the supplied module belongs.
2762func BaselineApexAvailable(moduleName string) []string {
2763 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2764}
2765
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002766// This is a map from apex to modules, which overrides the apex_available setting for that
2767// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002768// TODO(b/147364041): remove this
2769func makeApexAvailableBaseline() map[string][]string {
2770 // The "Module separator"s below are employed to minimize merge conflicts.
2771 m := make(map[string][]string)
2772 //
2773 // Module separator
2774 //
2775 m["com.android.appsearch"] = []string{
2776 "icing-java-proto-lite",
2777 "libprotobuf-java-lite",
2778 }
2779 //
2780 // Module separator
2781 //
Oriol Prieto Gasco8132fbf2022-06-17 19:44:25 +00002782 m["com.android.btservices"] = []string{
2783 "bluetooth-protos-lite",
2784 "internal_include_headers",
2785 "libaudio-a2dp-hw-utils",
2786 "libaudio-hearing-aid-hw-utils",
2787 "libbluetooth",
2788 "libbluetooth-types",
2789 "libbluetooth-types-header",
2790 "libbluetooth_gd",
2791 "libbluetooth_headers",
2792 "libbluetooth_jni",
2793 "libbt-audio-hal-interface",
2794 "libbt-bta",
2795 "libbt-common",
2796 "libbt-hci",
2797 "libbt-platform-protos-lite",
2798 "libbt-protos-lite",
2799 "libbt-sbc-decoder",
2800 "libbt-sbc-encoder",
2801 "libbt-stack",
2802 "libbt-utils",
2803 "libbtcore",
2804 "libbtdevice",
2805 "libbte",
2806 "libbtif",
2807 "libchrome",
2808 }
2809 //
2810 // Module separator
2811 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002812 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002813 "bluetooth-protos-lite",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002814 "internal_include_headers",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002815 "libaudio-a2dp-hw-utils",
2816 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002817 "libbluetooth",
2818 "libbluetooth-types",
2819 "libbluetooth-types-header",
2820 "libbluetooth_gd",
2821 "libbluetooth_headers",
2822 "libbluetooth_jni",
2823 "libbt-audio-hal-interface",
2824 "libbt-bta",
2825 "libbt-common",
2826 "libbt-hci",
2827 "libbt-platform-protos-lite",
2828 "libbt-protos-lite",
2829 "libbt-sbc-decoder",
2830 "libbt-sbc-encoder",
2831 "libbt-stack",
2832 "libbt-utils",
2833 "libbtcore",
2834 "libbtdevice",
2835 "libbte",
2836 "libbtif",
2837 "libchrome",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002838 }
2839 //
2840 // Module separator
2841 //
2842 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2843 //
2844 // Module separator
2845 //
2846 m["com.android.extservices"] = []string{
2847 "error_prone_annotations",
2848 "ExtServices-core",
2849 "ExtServices",
2850 "libtextclassifier-java",
2851 "libz_current",
2852 "textclassifier-statsd",
2853 "TextClassifierNotificationLibNoManifest",
2854 "TextClassifierServiceLibNoManifest",
2855 }
2856 //
2857 // Module separator
2858 //
2859 m["com.android.neuralnetworks"] = []string{
2860 "android.hardware.neuralnetworks@1.0",
2861 "android.hardware.neuralnetworks@1.1",
2862 "android.hardware.neuralnetworks@1.2",
2863 "android.hardware.neuralnetworks@1.3",
2864 "android.hidl.allocator@1.0",
2865 "android.hidl.memory.token@1.0",
2866 "android.hidl.memory@1.0",
2867 "android.hidl.safe_union@1.0",
2868 "libarect",
2869 "libbuildversion",
2870 "libmath",
2871 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002872 }
2873 //
2874 // Module separator
2875 //
2876 m["com.android.media"] = []string{
Ray Essick5d240fb2022-02-07 11:01:32 -08002877 // empty
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002878 }
2879 //
2880 // Module separator
2881 //
2882 m["com.android.media.swcodec"] = []string{
Ray Essickde1e3002022-02-10 17:37:51 -08002883 // empty
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002884 }
2885 //
2886 // Module separator
2887 //
2888 m["com.android.mediaprovider"] = []string{
2889 "MediaProvider",
2890 "MediaProviderGoogle",
2891 "fmtlib_ndk",
2892 "libbase_ndk",
2893 "libfuse",
2894 "libfuse_jni",
2895 }
2896 //
2897 // Module separator
2898 //
2899 m["com.android.permission"] = []string{
2900 "car-ui-lib",
2901 "iconloader",
2902 "kotlin-annotations",
2903 "kotlin-stdlib",
2904 "kotlin-stdlib-jdk7",
2905 "kotlin-stdlib-jdk8",
2906 "kotlinx-coroutines-android",
2907 "kotlinx-coroutines-android-nodeps",
2908 "kotlinx-coroutines-core",
2909 "kotlinx-coroutines-core-nodeps",
2910 "permissioncontroller-statsd",
2911 "GooglePermissionController",
2912 "PermissionController",
2913 "SettingsLibActionBarShadow",
2914 "SettingsLibAppPreference",
2915 "SettingsLibBarChartPreference",
2916 "SettingsLibLayoutPreference",
2917 "SettingsLibProgressBar",
2918 "SettingsLibSearchWidget",
2919 "SettingsLibSettingsTheme",
2920 "SettingsLibRestrictedLockUtils",
2921 "SettingsLibHelpUtils",
2922 }
2923 //
2924 // Module separator
2925 //
2926 m["com.android.runtime"] = []string{
2927 "bionic_libc_platform_headers",
2928 "libarm-optimized-routines-math",
2929 "libc_aeabi",
2930 "libc_bionic",
2931 "libc_bionic_ndk",
2932 "libc_bootstrap",
2933 "libc_common",
2934 "libc_common_shared",
2935 "libc_common_static",
2936 "libc_dns",
2937 "libc_dynamic_dispatch",
2938 "libc_fortify",
2939 "libc_freebsd",
2940 "libc_freebsd_large_stack",
2941 "libc_gdtoa",
2942 "libc_init_dynamic",
2943 "libc_init_static",
2944 "libc_jemalloc_wrapper",
2945 "libc_netbsd",
2946 "libc_nomalloc",
2947 "libc_nopthread",
2948 "libc_openbsd",
2949 "libc_openbsd_large_stack",
2950 "libc_openbsd_ndk",
2951 "libc_pthread",
2952 "libc_static_dispatch",
2953 "libc_syscalls",
2954 "libc_tzcode",
2955 "libc_unwind_static",
2956 "libdebuggerd",
2957 "libdebuggerd_common_headers",
2958 "libdebuggerd_handler_core",
2959 "libdebuggerd_handler_fallback",
2960 "libdl_static",
2961 "libjemalloc5",
2962 "liblinker_main",
2963 "liblinker_malloc",
2964 "liblz4",
2965 "liblzma",
2966 "libprocinfo",
2967 "libpropertyinfoparser",
2968 "libscudo",
2969 "libstdc++",
2970 "libsystemproperties",
2971 "libtombstoned_client_static",
2972 "libunwindstack",
2973 "libz",
2974 "libziparchive",
2975 }
2976 //
2977 // Module separator
2978 //
2979 m["com.android.tethering"] = []string{
2980 "android.hardware.tetheroffload.config-V1.0-java",
2981 "android.hardware.tetheroffload.control-V1.0-java",
2982 "android.hidl.base-V1.0-java",
2983 "libcgrouprc",
2984 "libcgrouprc_format",
2985 "libtetherutilsjni",
2986 "libvndksupport",
2987 "net-utils-framework-common",
2988 "netd_aidl_interface-V3-java",
2989 "netlink-client",
2990 "networkstack-aidl-interfaces-java",
2991 "tethering-aidl-interfaces-java",
2992 "TetheringApiCurrentLib",
2993 }
2994 //
2995 // Module separator
2996 //
2997 m["com.android.wifi"] = []string{
2998 "PlatformProperties",
2999 "android.hardware.wifi-V1.0-java",
3000 "android.hardware.wifi-V1.0-java-constants",
3001 "android.hardware.wifi-V1.1-java",
3002 "android.hardware.wifi-V1.2-java",
3003 "android.hardware.wifi-V1.3-java",
3004 "android.hardware.wifi-V1.4-java",
3005 "android.hardware.wifi.hostapd-V1.0-java",
3006 "android.hardware.wifi.hostapd-V1.1-java",
3007 "android.hardware.wifi.hostapd-V1.2-java",
3008 "android.hardware.wifi.supplicant-V1.0-java",
3009 "android.hardware.wifi.supplicant-V1.1-java",
3010 "android.hardware.wifi.supplicant-V1.2-java",
3011 "android.hardware.wifi.supplicant-V1.3-java",
3012 "android.hidl.base-V1.0-java",
3013 "android.hidl.manager-V1.0-java",
3014 "android.hidl.manager-V1.1-java",
3015 "android.hidl.manager-V1.2-java",
3016 "bouncycastle-unbundled",
3017 "dnsresolver_aidl_interface-V2-java",
3018 "error_prone_annotations",
3019 "framework-wifi-pre-jarjar",
3020 "framework-wifi-util-lib",
3021 "ipmemorystore-aidl-interfaces-V3-java",
3022 "ipmemorystore-aidl-interfaces-java",
3023 "ksoap2",
3024 "libnanohttpd",
3025 "libwifi-jni",
3026 "net-utils-services-common",
3027 "netd_aidl_interface-V2-java",
3028 "netd_aidl_interface-unstable-java",
3029 "netd_event_listener_interface-java",
3030 "netlink-client",
3031 "networkstack-client",
3032 "services.net",
3033 "wifi-lite-protos",
3034 "wifi-nano-protos",
3035 "wifi-service-pre-jarjar",
3036 "wifi-service-resources",
3037 }
3038 //
3039 // Module separator
3040 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003041 m["com.android.os.statsd"] = []string{
3042 "libstatssocket",
3043 }
3044 //
3045 // Module separator
3046 //
3047 m[android.AvailableToAnyApex] = []string{
3048 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3049 "androidx",
3050 "androidx-constraintlayout_constraintlayout",
3051 "androidx-constraintlayout_constraintlayout-nodeps",
3052 "androidx-constraintlayout_constraintlayout-solver",
3053 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3054 "com.google.android.material_material",
3055 "com.google.android.material_material-nodeps",
3056
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003057 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003058 "libprofile-clang-extras",
3059 "libprofile-clang-extras_ndk",
3060 "libprofile-extras",
3061 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003062 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003063 }
3064 return m
3065}
3066
3067func init() {
Spandan Das440ff962021-11-12 00:01:37 +00003068 android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...)
3069 android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003070}
3071
Spandan Das440ff962021-11-12 00:01:37 +00003072func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule {
3073 rules := make([]android.Rule, 0, len(bcpPermittedPackages))
3074 for jar, permittedPackages := range bcpPermittedPackages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003075 permittedPackagesRule := android.NeverAllow().
Spandan Das440ff962021-11-12 00:01:37 +00003076 With("name", jar).
3077 WithMatcher("permitted_packages", android.NotInList(permittedPackages)).
3078 Because(jar +
3079 " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") +
Anton Hanssonddf8c1b2021-12-23 15:05:38 +00003080 ". Please consider the following alternatives:\n" +
Andrei Onead967aee2022-01-19 15:36:40 +00003081 " 1. If the offending code is from a statically linked library, consider " +
3082 "removing that dependency and using an alternative already in the " +
3083 "bootclasspath, or perhaps a shared library." +
3084 " 2. Move the offending code into an allowed package.\n" +
3085 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3086 "health implications of bundling that code, particularly if the offending jar " +
3087 "is part of the bootclasspath.")
Spandan Das440ff962021-11-12 00:01:37 +00003088
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003089 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003090 }
3091 return rules
3092}
3093
Anton Hanssonddf8c1b2021-12-23 15:05:38 +00003094// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003095// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Das440ff962021-11-12 00:01:37 +00003096func qBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003097 return map[string][]string{
Spandan Das440ff962021-11-12 00:01:37 +00003098 "conscrypt": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003099 "android.net.ssl",
3100 "com.android.org.conscrypt",
3101 },
Spandan Das440ff962021-11-12 00:01:37 +00003102 "updatable-media": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003103 "android.media",
3104 },
3105 }
3106}
3107
Anton Hanssonddf8c1b2021-12-23 15:05:38 +00003108// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003109// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Das440ff962021-11-12 00:01:37 +00003110func rBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003111 return map[string][]string{
Spandan Das440ff962021-11-12 00:01:37 +00003112 "framework-mediaprovider": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003113 "android.provider",
3114 },
Spandan Das440ff962021-11-12 00:01:37 +00003115 "framework-permission": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003116 "android.permission",
3117 "android.app.role",
3118 "com.android.permission",
3119 "com.android.role",
3120 },
Spandan Das440ff962021-11-12 00:01:37 +00003121 "framework-sdkextensions": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003122 "android.os.ext",
3123 },
Spandan Das440ff962021-11-12 00:01:37 +00003124 "framework-statsd": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003125 "android.app",
3126 "android.os",
3127 "android.util",
3128 "com.android.internal.statsd",
3129 "com.android.server.stats",
3130 },
Spandan Das440ff962021-11-12 00:01:37 +00003131 "framework-wifi": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003132 "com.android.server.wifi",
3133 "com.android.wifi.x",
3134 "android.hardware.wifi",
3135 "android.net.wifi",
3136 },
Spandan Das440ff962021-11-12 00:01:37 +00003137 "framework-tethering": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003138 "android.net",
3139 },
3140 }
3141}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003142
3143// For Bazel / bp2build
3144
3145type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003146 Manifest bazel.LabelAttribute
3147 Android_manifest bazel.LabelAttribute
3148 File_contexts bazel.LabelAttribute
3149 Key bazel.LabelAttribute
3150 Certificate bazel.LabelAttribute
3151 Min_sdk_version *string
3152 Updatable bazel.BoolAttribute
3153 Installable bazel.BoolAttribute
3154 Binaries bazel.LabelListAttribute
3155 Prebuilts bazel.LabelListAttribute
3156 Native_shared_libs_32 bazel.LabelListAttribute
3157 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003158 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003159}
3160
3161type convertedNativeSharedLibs struct {
3162 Native_shared_libs_32 bazel.LabelListAttribute
3163 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003164}
3165
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003166// ConvertWithBp2build performs bp2build conversion of an apex
3167func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3168 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003169 if ctx.ModuleType() != "apex" {
3170 return
3171 }
3172
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003173 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003174 if a.properties.Manifest != nil {
3175 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003176 }
3177
3178 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003179 if a.properties.AndroidManifest != nil {
3180 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003181 }
3182
3183 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003184 if a.properties.File_contexts != nil {
3185 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003186 }
3187
Albert Martin55ccba22022-03-21 20:11:16 +00003188 // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
3189 // given it's coming via config, we probably don't want to put it in here.
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003190 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003191 if a.properties.Min_sdk_version != nil {
3192 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003193 }
3194
3195 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003196 if a.overridableProperties.Key != nil {
3197 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003198 }
3199
3200 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003201 if a.overridableProperties.Certificate != nil {
3202 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003203 }
3204
Yu Liu4ae55d12022-01-05 17:17:23 -08003205 nativeSharedLibs := &convertedNativeSharedLibs{
3206 Native_shared_libs_32: bazel.LabelListAttribute{},
3207 Native_shared_libs_64: bazel.LabelListAttribute{},
3208 }
3209 compileMultilib := "both"
3210 if a.CompileMultilib() != nil {
3211 compileMultilib = *a.CompileMultilib()
3212 }
3213
3214 // properties.Native_shared_libs is treated as "both"
3215 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3216 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3217 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3218 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3219 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003220
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003221 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003222 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3223 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3224
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003225 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003226 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003227
3228 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003229 if a.properties.Updatable != nil {
3230 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003231 }
3232
3233 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003234 if a.properties.Installable != nil {
3235 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003236 }
3237
Wei Lif034cb42022-01-19 15:54:31 -08003238 var compressibleAttribute bazel.BoolAttribute
3239 if a.overridableProperties.Compressible != nil {
3240 compressibleAttribute.Value = a.overridableProperties.Compressible
3241 }
3242
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003243 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003244 Manifest: manifestLabelAttribute,
3245 Android_manifest: androidManifestLabelAttribute,
3246 File_contexts: fileContextsLabelAttribute,
3247 Min_sdk_version: minSdkVersion,
3248 Key: keyLabelAttribute,
3249 Certificate: certificateLabelAttribute,
3250 Updatable: updatableAttribute,
3251 Installable: installableAttribute,
3252 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3253 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3254 Binaries: binariesLabelListAttribute,
3255 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003256 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003257 }
3258
3259 props := bazel.BazelTargetModuleProperties{
3260 Rule_class: "apex",
3261 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3262 }
3263
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003264 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003265}
Yu Liu4ae55d12022-01-05 17:17:23 -08003266
3267// The following conversions are based on this table where the rows are the compile_multilib
3268// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3269// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3270// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3271// should not be compiled.
3272// multib/compile_multilib, 32, 64, both, first
3273// 32, 32/32, none/none, 32/32, none/32
3274// 64, none/none, 64/none, 64/none, 64/none
3275// both, 32/32, 64/none, 32&64/32, 64/32
3276// first, 32/32, 64/none, 64/32, 64/32
3277
3278func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3279 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3280 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3281 switch compileMultilb {
3282 case "both", "32":
3283 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3284 case "first":
3285 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3286 case "64":
3287 // Incompatible, ignore
3288 default:
3289 invalidCompileMultilib(ctx, compileMultilb)
3290 }
3291}
3292
3293func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3294 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3295 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3296 switch compileMultilb {
3297 case "both", "64", "first":
3298 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3299 case "32":
3300 // Incompatible, ignore
3301 default:
3302 invalidCompileMultilib(ctx, compileMultilb)
3303 }
3304}
3305
3306func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3307 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3308 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3309 switch compileMultilb {
3310 case "both":
3311 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3312 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3313 case "first":
3314 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3315 case "32":
3316 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3317 case "64":
3318 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3319 default:
3320 invalidCompileMultilib(ctx, compileMultilb)
3321 }
3322}
3323
3324func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3325 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3326 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3327 switch compileMultilb {
3328 case "both", "first":
3329 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3330 case "32":
3331 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3332 case "64":
3333 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3334 default:
3335 invalidCompileMultilib(ctx, compileMultilb)
3336 }
3337}
3338
3339func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3340 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3341 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3342}
3343
3344func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3345 list := bazel.LabelListAttribute{}
3346 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3347 nativeSharedLibs.Native_shared_libs_32.Append(list)
3348}
3349
3350func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3351 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3352 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3353}
3354
3355func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3356 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3357 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3358}
3359
3360func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3361 labelListAttr *bazel.LabelListAttribute) {
3362 list := bazel.LabelListAttribute{}
3363 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3364 labelListAttr.Append(list)
3365}
3366
3367func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3368 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3369}