blob: cedc3b3b986a6ef5c6040358637dcc40b6548e39 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090034 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/java"
36 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090037 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090039)
40
Jiyong Park8e6d52f2020-11-19 14:37:47 +090041func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000042 registerApexBuildComponents(android.InitRegistrationContext)
43}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044
Paul Duffin667893c2021-03-09 22:34:13 +000045func registerApexBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("apex", BundleFactory)
47 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
48 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
49 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
50 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
51 ctx.RegisterModuleType("override_apex", overrideApexFactory)
52 ctx.RegisterModuleType("apex_set", apexSetFactory)
53
Paul Duffin5dda3e32021-05-05 14:13:27 +010054 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.PreDepsMutators(RegisterPreDepsMutators)
56 ctx.PostDepsMutators(RegisterPostDepsMutators)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040057
58 android.RegisterBp2BuildMutator("apex", ApexBundleBp2Build)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090059}
60
Paul Duffin5dda3e32021-05-05 14:13:27 +010061func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
62 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
63}
64
Jiyong Park8e6d52f2020-11-19 14:37:47 +090065func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
66 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
67 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
68}
69
70func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000071 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090072 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
73 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
74 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010075 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
76 // it should create a platform variant.
77 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090078 ctx.BottomUp("apex", apexMutator).Parallel()
79 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
80 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090081}
82
83type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090084 // Json manifest file describing meta info of this APEX bundle. Refer to
85 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090086 Manifest *string `android:"path"`
87
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090088 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
89 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090090 AndroidManifest *string `android:"path"`
91
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090092 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
93 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090094 Apex_name *string
95
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090096 // Determines the file contexts file for setting the security contexts to files in this APEX
97 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
98 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090099 File_contexts *string `android:"path"`
100
Jiyong Park038e8522021-12-13 23:56:35 +0900101 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
102 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
103 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
104 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
105 // capability. If this property is not set, or a file is missing in the file, default config
106 // is used.
107 Canned_fs_config *string `android:"path"`
108
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900109 ApexNativeDependencies
110
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900111 Multilib apexMultilibProperties
112
Paul Duffin4b64ba02021-03-29 11:02:53 +0100113 // List of bootclasspath fragments that are embedded inside this APEX bundle.
114 Bootclasspath_fragments []string
115
satayev333a1732021-05-17 21:35:26 +0100116 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
117 Systemserverclasspath_fragments []string
118
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900119 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900120 Java_libs []string
121
Sundong Ahn80c04892021-11-23 00:57:19 +0000122 // List of sh binaries that are embedded inside this APEX bundle.
123 Sh_binaries []string
124
Paul Duffin3abc1742021-03-15 19:32:23 +0000125 // List of platform_compat_config files that are embedded inside this APEX bundle.
126 Compat_configs []string
127
Jiyong Park12a719c2021-01-07 15:31:24 +0900128 // List of filesystem images that are embedded inside this APEX bundle.
129 Filesystems []string
130
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900131 // The minimum SDK version that this APEX must support at minimum. This is usually set to
132 // the SDK version that the APEX was first introduced.
133 Min_sdk_version *string
134
135 // Whether this APEX is considered updatable or not. When set to true, this will enforce
136 // additional rules for making sure that the APEX is truly updatable. To be updatable,
137 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000138 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900139 Updatable *bool
140
Jiyong Parkf4020582021-11-29 12:37:10 +0900141 // Marks that this APEX is designed to be updatable in the future, although it's not
142 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
143 // updatable APEXes. Currently, this disables the size optimization, so that the size of
144 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
145 // false.
146 Future_updatable *bool
147
Jiyong Park1bc84122021-06-22 20:23:05 +0900148 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
149 // false`. Default is false.
150 Platform_apis *bool
151
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900152 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
153 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900154 Installable *bool
155
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000156 // Whether this APEX can be compressed or not. Setting this property to false means this
157 // APEX will never be compressed. When set to true, APEX will be compressed if other
158 // conditions, e.g, target device needs to support APEX compression, are also fulfilled.
159 // Default: true.
160 Compressible *bool
161
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900162 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
163 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
164 Use_vndk_as_stable *bool
165
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000166 // Whether this is multi-installed APEX should skip installing symbol files.
167 // Multi-installed APEXes share the same apex_name and are installed at the same time.
168 // Default is false.
169 //
170 // Should be set to true for all multi-installed APEXes except the singular
171 // default version within the multi-installed group.
172 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
173 // or else conflicting build rules may be created.
174 Multi_install_skip_symbol_files *bool
175
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900176 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
177 // `name#version` or `name` which is an alias for `name#current`. If left empty,
178 // `platform#current` is implied. This value affects all modules included in this APEX. In
179 // other words, they are also built with the SDKs specified here.
180 Uses_sdks []string
181
182 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
183 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
184 // container. When set to zip, contents are stored in a zip container directly. This type is
185 // mostly for host-side debugging. When set to both, the two types are both built. Default
186 // is 'image'.
187 Payload_type *string
188
Huang Jianan13cac632021-08-02 15:02:17 +0800189 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
190 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900191 Payload_fs_type *string
192
193 // For telling the APEX to ignore special handling for system libraries such as bionic.
194 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900195 Ignore_system_library_special_case *bool
196
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100197 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100198 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100199 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900200
201 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
202 // used in tests.
203 Test_only_unsigned_payload *bool
204
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000205 // Whenever apex should be compressed, regardless of product flag used. Should be only
206 // used in tests.
207 Test_only_force_compression *bool
208
Jooyung Han09c11ad2021-10-27 03:45:31 +0900209 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
210 // with the tool to sign payload contents.
211 Custom_sign_tool *string
212
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100213 // Canonical name of this APEX bundle. Used to determine the path to the
214 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
215 // apex mutator variations. For override_apex modules, this is the name of the
216 // overridden base module.
217 ApexVariationName string `blueprint:"mutated"`
218
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900219 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900220
221 // List of sanitizer names that this APEX is enabled for
222 SanitizerNames []string `blueprint:"mutated"`
223
224 PreventInstall bool `blueprint:"mutated"`
225
226 HideFromMake bool `blueprint:"mutated"`
227
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900228 // Internal package method for this APEX. When payload_type is image, this can be either
229 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
230 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900231 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900232}
233
234type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900235 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900236 Native_shared_libs []string
237
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900238 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900239 Jni_libs []string
240
Jiyong Park99644e92020-11-17 22:21:02 +0900241 // List of rust dyn libraries
242 Rust_dyn_libs []string
243
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900244 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900245 Binaries []string
246
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900247 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900248 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900249
250 // List of filesystem images that are embedded inside this APEX bundle.
251 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900252}
253
254type apexMultilibProperties struct {
255 // Native dependencies whose compile_multilib is "first"
256 First ApexNativeDependencies
257
258 // Native dependencies whose compile_multilib is "both"
259 Both ApexNativeDependencies
260
261 // Native dependencies whose compile_multilib is "prefer32"
262 Prefer32 ApexNativeDependencies
263
264 // Native dependencies whose compile_multilib is "32"
265 Lib32 ApexNativeDependencies
266
267 // Native dependencies whose compile_multilib is "64"
268 Lib64 ApexNativeDependencies
269}
270
271type apexTargetBundleProperties struct {
272 Target struct {
273 // Multilib properties only for android.
274 Android struct {
275 Multilib apexMultilibProperties
276 }
277
278 // Multilib properties only for host.
279 Host struct {
280 Multilib apexMultilibProperties
281 }
282
283 // Multilib properties only for host linux_bionic.
284 Linux_bionic struct {
285 Multilib apexMultilibProperties
286 }
287
288 // Multilib properties only for host linux_glibc.
289 Linux_glibc struct {
290 Multilib apexMultilibProperties
291 }
292 }
293}
294
Jiyong Park59140302020-12-14 18:44:04 +0900295type apexArchBundleProperties struct {
296 Arch struct {
297 Arm struct {
298 ApexNativeDependencies
299 }
300 Arm64 struct {
301 ApexNativeDependencies
302 }
303 X86 struct {
304 ApexNativeDependencies
305 }
306 X86_64 struct {
307 ApexNativeDependencies
308 }
309 }
310}
311
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900312// These properties can be used in override_apex to override the corresponding properties in the
313// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900314type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900315 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900316 Apps []string
317
Daniel Norman5a3ce132021-08-26 15:44:43 -0700318 // List of prebuilt files that are embedded inside this APEX bundle.
319 Prebuilts []string
320
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900321 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900322 Rros []string
323
markchien7c803b82021-08-26 22:10:06 +0800324 // List of BPF programs inside this APEX bundle.
325 Bpfs []string
326
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900327 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
328 // Soong). This does not completely prevent installation of the overridden binaries, but if
329 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
330 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900331 Overrides []string
332
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900333 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900334 Logging_parent string
335
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900336 // Apex Container package name. Override value for attribute package:name in
337 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900338 Package_name string
339
340 // A txt file containing list of files that are allowed to be included in this APEX.
341 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700342
343 // Name of the apex_key module that provides the private key to sign this APEX bundle.
344 Key *string
345
346 // Specifies the certificate and the private key to sign the zip container of this APEX. If
347 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
348 // as the certificate and the private key, respectively. If this is ":module", then the
349 // certificate and the private key are provided from the android_app_certificate module
350 // named "module".
351 Certificate *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352}
353
354type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900355 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356 android.ModuleBase
357 android.DefaultableModuleBase
358 android.OverridableModuleBase
359 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400360 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363 properties apexBundleProperties
364 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900365 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900366 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900367 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900368
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 ///////////////////////////////////////////////////////////////////////////////////////////
370 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900372 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800373 publicKeyFile android.Path
374 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900375
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800377 containerCertificateFile android.Path
378 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900379
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900380 // Flags for special variants of APEX
381 testApex bool
382 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900384 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
385 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900386 primaryApexType bool
387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900388 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900389 suffix string
390
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900391 // File system type of apex_payload.img
392 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900393
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900394 // Whether to create symlink to the system file instead of having a file inside the apex or
395 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900396 linkToSystemLib bool
397
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900398 // List of files to be included in this APEX. This is filled in the first part of
399 // GenerateAndroidBuildActions.
400 filesInfo []apexFile
401
402 // List of other module names that should be installed when this APEX gets installed.
403 requiredDeps []string
404
405 ///////////////////////////////////////////////////////////////////////////////////////////
406 // Outputs (final and intermediates)
407
408 // Processed apex manifest in JSONson format (for Q)
409 manifestJsonOut android.WritablePath
410
411 // Processed apex manifest in PB format (for R+)
412 manifestPbOut android.WritablePath
413
414 // Processed file_contexts files
415 fileContexts android.WritablePath
416
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900417 // Struct holding the merged notice file paths in different formats
418 mergedNotices android.NoticeOutputs
419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900420 // The built APEX file. This is the main product.
421 outputFile android.WritablePath
422
423 // The built APEX file in app bundle format. This file is not directly installed to the
424 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
425 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
426 // system) to be merged into a single app bundle file that Play accepts. See
427 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
428 bundleModuleFile android.WritablePath
429
Colin Cross6340ea52021-11-04 12:01:18 -0700430 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900431 installDir android.InstallPath
432
Colin Cross6340ea52021-11-04 12:01:18 -0700433 // Path where this APEX was installed.
434 installedFile android.InstallPath
435
436 // Installed locations of symlinks for backward compatibility.
437 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900438
439 // Text file having the list of individual files that are included in this APEX. Used for
440 // debugging purpose.
441 installedFilesFile android.WritablePath
442
443 // List of module names that this APEX is including (to be shown via *-deps-info target).
444 // Used for debugging purpose.
445 android.ApexBundleDepsInfo
446
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900447 // Optional list of lint report zip files for apexes that contain java or app modules
448 lintReports android.Paths
449
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900450 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000451
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000452 isCompressed bool
453
sophiezc80a2b32020-11-12 16:39:19 +0000454 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700455 nativeApisUsedByModuleFile android.ModuleOutPath
456 nativeApisBackedByModuleFile android.ModuleOutPath
457 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800458
459 // Collect the module directory for IDE info in java/jdeps.go.
460 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900461}
462
Colin Cross6340ea52021-11-04 12:01:18 -0700463func (*apexBundle) InstallBypassMake() bool {
464 return true
465}
466
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900467// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900468type apexFileClass int
469
Jooyung Han72bd2f82019-10-23 16:46:38 +0900470const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900471 app apexFileClass = iota
472 appSet
473 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900474 goBinary
475 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900476 nativeExecutable
477 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900478 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900479 pyBinary
480 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900481)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900482
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900483// apexFile represents a file in an APEX bundle. This is created during the first half of
484// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
485// of the function, this is used to create commands that copies the files into a staging directory,
486// where they are packaged into the APEX file. This struct is also used for creating Make modules
487// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900488type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900489 // buildFile is put in the installDir inside the APEX.
490 builtFile android.Path
491 noticeFiles android.Paths
492 installDir string
493 customStem string
494 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900495
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900496 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
497 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
498 // suffix>]
499 androidMkModuleName string // becomes LOCAL_MODULE
500 class apexFileClass // becomes LOCAL_MODULE_CLASS
501 moduleDir string // becomes LOCAL_PATH
502 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
503 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
504 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
505 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900506
507 jacocoReportClassesFile android.Path // only for javalibs and apps
508 lintDepSets java.LintDepSets // only for javalibs and apps
509 certificate java.Certificate // only for apps
510 overriddenPackageName string // only for apps
511
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900512 transitiveDep bool
513 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900514
Jiyong Park57621b22021-01-20 20:33:11 +0900515 multilib string
516
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900517 // TODO(jiyong): remove this
518 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900519}
520
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900521// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900522func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
523 ret := apexFile{
524 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900525 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900526 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900527 class: class,
528 module: module,
529 }
530 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900531 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900532 ret.moduleDir = ctx.OtherModuleDir(module)
533 ret.requiredModuleNames = module.RequiredModuleNames()
534 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
535 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900536 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900537 }
538 return ret
539}
540
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900541func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900542 return af.builtFile != nil && af.builtFile.String() != ""
543}
544
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900545// apexRelativePath returns the relative path of the given path from the install directory of this
546// apexFile.
547// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900548func (af *apexFile) apexRelativePath(path string) string {
549 return filepath.Join(af.installDir, path)
550}
551
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900552// path returns path of this apex file relative to the APEX root
553func (af *apexFile) path() string {
554 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900555}
556
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900557// stem returns the base filename of this apex file
558func (af *apexFile) stem() string {
559 if af.customStem != "" {
560 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900561 }
562 return af.builtFile.Base()
563}
564
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900565// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
566func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900567 var ret []string
568 for _, symlink := range af.symlinks {
569 ret = append(ret, af.apexRelativePath(symlink))
570 }
571 return ret
572}
573
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900574// availableToPlatform tests whether this apexFile is from a module that can be installed to the
575// platform.
576func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900577 if af.module == nil {
578 return false
579 }
580 if am, ok := af.module.(android.ApexModule); ok {
581 return am.AvailableFor(android.AvailableToPlatform)
582 }
583 return false
584}
585
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900586////////////////////////////////////////////////////////////////////////////////////////////////////
587// Mutators
588//
589// Brief description about mutators for APEX. The following three mutators are the most important
590// ones.
591//
592// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
593// to the (direct) dependencies of this APEX bundle.
594//
Paul Duffin949abc02020-12-08 10:34:30 +0000595// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900596// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
597// modules are marked as being included in the APEX via BuildForApex().
598//
Paul Duffin949abc02020-12-08 10:34:30 +0000599// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
600// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900601
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900602type dependencyTag struct {
603 blueprint.BaseDependencyTag
604 name string
605
606 // Determines if the dependent will be part of the APEX payload. Can be false for the
607 // dependencies to the signing key module, etc.
608 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000609
610 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
611 // replacement. This is needed because some prebuilt modules do not provide all the information
612 // needed by the apex.
613 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900614}
615
Paul Duffin8c535da2021-03-17 14:51:03 +0000616func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
617 return !d.sourceOnly
618}
619
620var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
621
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900622var (
Paul Duffin0b817782021-03-17 15:02:19 +0000623 androidAppTag = dependencyTag{name: "androidApp", payload: true}
624 bpfTag = dependencyTag{name: "bpf", payload: true}
625 certificateTag = dependencyTag{name: "certificate"}
626 executableTag = dependencyTag{name: "executable", payload: true}
627 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100628 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100629 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000630 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000631 javaLibTag = dependencyTag{name: "javaLib", payload: true}
632 jniLibTag = dependencyTag{name: "jniLib", payload: true}
633 keyTag = dependencyTag{name: "key"}
634 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
635 rroTag = dependencyTag{name: "rro", payload: true}
636 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
637 testForTag = dependencyTag{name: "test for"}
638 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000639 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640)
641
642// TODO(jiyong): shorten this function signature
643func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900644 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900645 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900646 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647
648 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900649 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900650 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
651 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 }
653
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900654 // Use *FarVariation* to be able to depend on modules having conflicting variations with
655 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
656 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900657 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900658 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900659 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
660 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900661 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900662 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900663}
664
665func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900666 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
668 } else {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
670 if ctx.Os().Bionic() {
671 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
672 } else {
673 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
674 }
675 }
676}
677
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900678// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
679// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
680func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
681 deviceConfig := ctx.DeviceConfig()
682 if a.vndkApex {
683 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900684 }
685
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900686 var prefix string
687 var vndkVersion string
688 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000689 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900690 prefix = cc.VendorVariationPrefix
691 vndkVersion = deviceConfig.VndkVersion()
692 } else if a.ProductSpecific() {
693 prefix = cc.ProductVariationPrefix
694 vndkVersion = deviceConfig.ProductVndkVersion()
695 }
696 }
697 if vndkVersion == "current" {
698 vndkVersion = deviceConfig.PlatformVndkVersion()
699 }
700 if vndkVersion != "" {
701 return prefix + vndkVersion
702 }
703
704 return android.CoreVariation // The usual case
705}
706
707func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900708 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
709 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
710 // each target os/architectures, appropriate dependencies are selected by their
711 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900712 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900713 imageVariation := a.getImageVariation(ctx)
714
715 a.combineProperties(ctx)
716
717 has32BitTarget := false
718 for _, target := range targets {
719 if target.Arch.ArchType.Multilib == "lib32" {
720 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000721 }
722 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900723 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900724 // Don't include artifacts for the host cross targets because there is no way for us
725 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900726 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900727 continue
728 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000729
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000731
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900732 // Add native modules targeting both ABIs. When multilib.* is omitted for
733 // native_shared_libs/jni_libs/tests, it implies multilib.both
734 depsList = append(depsList, a.properties.Multilib.Both)
735 depsList = append(depsList, ApexNativeDependencies{
736 Native_shared_libs: a.properties.Native_shared_libs,
737 Tests: a.properties.Tests,
738 Jni_libs: a.properties.Jni_libs,
739 Binaries: nil,
740 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900741
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900742 // Add native modules targeting the first ABI When multilib.* is omitted for
743 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900744 isPrimaryAbi := i == 0
745 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900746 depsList = append(depsList, a.properties.Multilib.First)
747 depsList = append(depsList, ApexNativeDependencies{
748 Native_shared_libs: nil,
749 Tests: nil,
750 Jni_libs: nil,
751 Binaries: a.properties.Binaries,
752 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900753 }
754
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900755 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900756 switch target.Arch.ArchType.Multilib {
757 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900758 depsList = append(depsList, a.properties.Multilib.Lib32)
759 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900762 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900763 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900764 }
765 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900766
Jiyong Park59140302020-12-14 18:44:04 +0900767 // Add native modules targeting a specific arch variant
768 switch target.Arch.ArchType {
769 case android.Arm:
770 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
771 case android.Arm64:
772 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
773 case android.X86:
774 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
775 case android.X86_64:
776 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
777 default:
778 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
779 }
780
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900781 for _, d := range depsList {
782 addDependenciesForNativeModules(ctx, d, target, imageVariation)
783 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000784 ctx.AddFarVariationDependencies([]blueprint.Variation{
785 {Mutator: "os", Variation: target.OsVariation()},
786 {Mutator: "arch", Variation: target.ArchVariation()},
787 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900788 }
789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900790 // Common-arch dependencies come next
791 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100792 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100793 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900794 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900795 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000796 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900797
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900798 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
799 // This field currently isn't used.
800 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900801 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
802 if len(a.properties.Uses_sdks) > 0 {
803 sdkRefs := []android.SdkRef{}
804 for _, str := range a.properties.Uses_sdks {
805 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
806 sdkRefs = append(sdkRefs, parsed)
807 }
808 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100809 }
810}
811
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900812// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900813func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
814 if a.overridableProperties.Allowed_files != nil {
815 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100816 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900817
818 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
819 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800820 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900821 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700822 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
823 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
824 // regardless of the TARGET_PREFER_* setting. See b/144532908
825 arches := ctx.DeviceConfig().Arches()
826 if len(arches) != 0 {
827 archForPrebuiltEtc := arches[0]
828 for _, arch := range arches {
829 // Prefer 64-bit arch if there is any
830 if arch.ArchType.Multilib == "lib64" {
831 archForPrebuiltEtc = arch
832 break
833 }
834 }
835 ctx.AddFarVariationDependencies([]blueprint.Variation{
836 {Mutator: "os", Variation: ctx.Os().String()},
837 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
838 }, prebuiltTag, prebuilts...)
839 }
840 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700841
842 // Dependencies for signing
843 if String(a.overridableProperties.Key) == "" {
844 ctx.PropertyErrorf("key", "missing")
845 return
846 }
847 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
848
849 cert := android.SrcIsModule(a.getCertString(ctx))
850 if cert != "" {
851 ctx.AddDependency(ctx.Module(), certificateTag, cert)
852 // empty cert is not an error. Cert and private keys will be directly found under
853 // PRODUCT_DEFAULT_DEV_CERTIFICATE
854 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100855}
856
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900857type ApexBundleInfo struct {
858 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100859}
860
Paul Duffin949abc02020-12-08 10:34:30 +0000861var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862
Paul Duffina7d6a892020-12-07 17:39:59 +0000863var _ ApexInfoMutator = (*apexBundle)(nil)
864
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100865func (a *apexBundle) ApexVariationName() string {
866 return a.properties.ApexVariationName
867}
868
Paul Duffina7d6a892020-12-07 17:39:59 +0000869// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900870// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
871// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
872// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
873// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000874//
875// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
876// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
877// The apexMutator uses that list to create module variants for the apexes to which it belongs.
878// The relationship between module variants and apexes is not one-to-one as variants will be
879// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000880func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900881
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900882 // The VNDK APEX is special. For the APEX, the membership is described in a very different
883 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
884 // libraries are self-identified by their vndk.enabled properties. There is no need to run
885 // this mutator for the APEX as nothing will be collected. So, let's return fast.
886 if a.vndkApex {
887 return
888 }
889
890 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
891 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
892 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
893 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
894 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900895 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
896 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
897 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
898 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
899 return
900 }
901
Colin Cross56a83212020-09-15 18:30:11 -0700902 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900903 am, ok := child.(android.ApexModule)
904 if !ok || !am.CanHaveApexVariants() {
905 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900906 }
Paul Duffin573989d2021-03-17 13:25:29 +0000907 depTag := mctx.OtherModuleDependencyTag(child)
908
909 // Check to see if the tag always requires that the child module has an apex variant for every
910 // apex variant of the parent module. If it does not then it is still possible for something
911 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
912 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
913 return true
914 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000915 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900916 return false
917 }
Jooyung Handf78e212020-07-22 15:54:47 +0900918 if excludeVndkLibs {
919 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
920 return false
921 }
922 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900923 // By default, all the transitive dependencies are collected, unless filtered out
924 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700925 return true
926 }
927
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900928 // Records whether a certain module is included in this apexBundle via direct dependency or
929 // inndirect dependency.
930 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700931 mctx.WalkDeps(func(child, parent android.Module) bool {
932 if !continueApexDepsWalk(child, parent) {
933 return false
934 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900935 // If the parent is apexBundle, this child is directly depended.
936 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900937 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700938 contents[depName] = contents[depName].Add(directDep)
939 return true
940 })
941
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900942 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900943 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700944 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
945 Contents: apexContents,
946 })
947
Jooyung Haned124c32021-01-26 11:43:46 +0900948 minSdkVersion := a.minSdkVersion(mctx)
949 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
950 if minSdkVersion.IsNone() {
951 minSdkVersion = android.FutureApiLevel
952 }
953
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900954 // This is the main part of this mutator. Mark the collected dependencies that they need to
955 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900956
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100957 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
958 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700959 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100960 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900961 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700962 RequiredSdks: a.RequiredSdks(),
963 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900964 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100965 InApexVariants: []string{apexVariationName},
966 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700967 ApexContents: []*android.ApexContents{apexContents},
968 }
Colin Cross56a83212020-09-15 18:30:11 -0700969 mctx.WalkDeps(func(child, parent android.Module) bool {
970 if !continueApexDepsWalk(child, parent) {
971 return false
972 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900973 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900974 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900975 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900976}
977
Paul Duffina7d6a892020-12-07 17:39:59 +0000978type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100979 // ApexVariationName returns the name of the APEX variation to use in the apex
980 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
981 ApexVariationName() string
982
Paul Duffina7d6a892020-12-07 17:39:59 +0000983 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
984 // depended upon by an apex and which require an apex specific variant.
985 ApexInfoMutator(android.TopDownMutatorContext)
986}
987
988// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
989// specific variant to modules that support the ApexInfoMutator.
990func apexInfoMutator(mctx android.TopDownMutatorContext) {
991 if !mctx.Module().Enabled() {
992 return
993 }
994
995 if a, ok := mctx.Module().(ApexInfoMutator); ok {
996 a.ApexInfoMutator(mctx)
997 return
998 }
999}
1000
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001001// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1002// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1003// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001004func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1005 if !mctx.Module().Enabled() {
1006 return
1007 }
1008 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001009 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1010 }
1011}
1012
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001013// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1014// the apex in order to retrieve its contents later.
1015// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001016func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1017 if !mctx.Module().Enabled() {
1018 return
1019 }
Colin Cross56a83212020-09-15 18:30:11 -07001020 if am, ok := mctx.Module().(android.ApexModule); ok {
1021 if testFor := am.TestFor(); len(testFor) > 0 {
1022 mctx.AddFarVariationDependencies([]blueprint.Variation{
1023 {Mutator: "os", Variation: am.Target().OsVariation()},
1024 {"arch", "common"},
1025 }, testForTag, testFor...)
1026 }
1027 }
1028}
1029
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001030// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001031func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1032 if !mctx.Module().Enabled() {
1033 return
1034 }
Colin Cross56a83212020-09-15 18:30:11 -07001035 if _, ok := mctx.Module().(android.ApexModule); ok {
1036 var contents []*android.ApexContents
1037 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1038 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1039 contents = append(contents, abInfo.Contents)
1040 }
1041 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1042 ApexContents: contents,
1043 })
Colin Crossaede88c2020-08-11 12:17:01 -07001044 }
1045}
1046
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001047// markPlatformAvailability marks whether or not a module can be available to platform. A module
1048// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1049// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1050// be) available to platform
1051// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001052func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1053 // Host and recovery are not considered as platform
1054 if mctx.Host() || mctx.Module().InstallInRecovery() {
1055 return
1056 }
1057
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001058 am, ok := mctx.Module().(android.ApexModule)
1059 if !ok {
1060 return
1061 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001062
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001063 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001064
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001065 // If any of the dep is not available to platform, this module is also considered as being
1066 // not available to platform even if it has "//apex_available:platform"
1067 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001068 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001069 // if the dependency crosses apex boundary, don't consider it
1070 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001071 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001072 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1073 availableToPlatform = false
1074 // TODO(b/154889534) trigger an error when 'am' has
1075 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001076 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001077 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001078
Paul Duffinb5769c12021-05-12 16:16:51 +01001079 // Exception 1: check to see if the module always requires it.
1080 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001081 availableToPlatform = true
1082 }
1083
1084 // Exception 2: bootstrap bionic libraries are also always available to platform
1085 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1086 availableToPlatform = true
1087 }
1088
1089 if !availableToPlatform {
1090 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001091 }
1092}
1093
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001094// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001095// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001096func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001097 if !mctx.Module().Enabled() {
1098 return
1099 }
Colin Cross56a83212020-09-15 18:30:11 -07001100
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001101 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001102 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001103 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001104 return
1105 }
1106
1107 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001108 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1109 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001110 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001111 if strings.HasPrefix(apexBundleName, "com.android.art") {
1112 // Create an alias from the platform variant. This is done to make
1113 // test_for dependencies work for modules that are split by the APEX
1114 // mutator, since test_for dependencies always go to the platform variant.
1115 // This doesn't happen for normal APEXes that are disjunct, so only do
1116 // this for the overlapping ART APEXes.
1117 // TODO(b/183882457): Remove this if the test_for functionality is
1118 // refactored to depend on the proper APEX variants instead of platform.
1119 mctx.CreateAliasVariation("", apexBundleName)
1120 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001121 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1122 apexBundleName := o.GetOverriddenModuleName()
1123 if apexBundleName == "" {
1124 mctx.ModuleErrorf("base property is not set")
1125 return
1126 }
1127 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001128 if strings.HasPrefix(apexBundleName, "com.android.art") {
1129 // TODO(b/183882457): See note for CreateAliasVariation above.
1130 mctx.CreateAliasVariation("", apexBundleName)
1131 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001132 }
1133}
Sundong Ahne9b55722019-09-06 17:37:42 +09001134
Paul Duffin6717d882021-06-15 19:09:41 +01001135// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1136// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001137func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001138 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001139 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001140 return !a.vndkApex
1141 }
1142
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001143 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001144}
1145
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001146// See android.UpdateDirectlyInAnyApex
1147// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001148func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1149 if !mctx.Module().Enabled() {
1150 return
1151 }
1152 if am, ok := mctx.Module().(android.ApexModule); ok {
1153 android.UpdateDirectlyInAnyApex(mctx, am)
1154 }
1155}
1156
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001157// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001158type apexPackaging int
1159
1160const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001161 // imageApex is a packaging method where contents are included in a filesystem image which
1162 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001163 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001164
1165 // zipApex is a packaging method where contents are directly included in the zip container.
1166 // This is used for host-side testing - because the contents are easily accessible by
1167 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001168 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001169
1170 // flattendApex is a packaging method where contents are not included in the APEX file, but
1171 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1172 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001173 flattenedApex
1174)
1175
1176const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001177 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001178 imageApexSuffix = ".apex"
1179 imageCapexSuffix = ".capex"
1180 zipApexSuffix = ".zipapex"
1181 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001182
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001183 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001184 imageApexType = "image"
1185 zipApexType = "zip"
1186 flattenedApexType = "flattened"
1187
Dan Willemsen47e1a752021-10-16 18:36:13 -07001188 ext4FsType = "ext4"
1189 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001190 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001191)
1192
1193// The suffix for the output "file", not the module
1194func (a apexPackaging) suffix() string {
1195 switch a {
1196 case imageApex:
1197 return imageApexSuffix
1198 case zipApex:
1199 return zipApexSuffix
1200 default:
1201 panic(fmt.Errorf("unknown APEX type %d", a))
1202 }
1203}
1204
1205func (a apexPackaging) name() string {
1206 switch a {
1207 case imageApex:
1208 return imageApexType
1209 case zipApex:
1210 return zipApexType
1211 default:
1212 panic(fmt.Errorf("unknown APEX type %d", a))
1213 }
1214}
1215
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001216// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1217// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001218func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001219 if !mctx.Module().Enabled() {
1220 return
1221 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001222 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001223 var variants []string
1224 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1225 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001226 // This is the normal case. Note that both image and flattend APEXes are
1227 // created. The image type is installed to the system partition, while the
1228 // flattened APEX is (optionally) installed to the system_ext partition.
1229 // This is mostly for GSI which has to support wide range of devices. If GSI
1230 // is installed on a newer (APEX-capable) device, the image APEX in the
1231 // system will be used. However, if the same GSI is installed on an old
1232 // device which can't support image APEX, the flattened APEX in the
1233 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001234 variants = append(variants, imageApexType, flattenedApexType)
1235 case "zip":
1236 variants = append(variants, zipApexType)
1237 case "both":
1238 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1239 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001240 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001241 return
1242 }
1243
1244 modules := mctx.CreateLocalVariations(variants...)
1245
1246 for i, v := range variants {
1247 switch v {
1248 case imageApexType:
1249 modules[i].(*apexBundle).properties.ApexType = imageApex
1250 case zipApexType:
1251 modules[i].(*apexBundle).properties.ApexType = zipApex
1252 case flattenedApexType:
1253 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001254 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001255 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001256 modules[i].(*apexBundle).MakeAsSystemExt()
1257 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001258 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001259 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001260 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001261 // payload_type is forcibly overridden to "image"
1262 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001263 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001264 }
1265}
1266
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001267var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001268
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001269// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001270func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1271 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001272 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001273 return true
1274}
1275
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001276var _ android.OutputFileProducer = (*apexBundle)(nil)
1277
1278// Implements android.OutputFileProducer
1279func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1280 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001281 case "", android.DefaultDistTag:
1282 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001283 return android.Paths{a.outputFile}, nil
1284 default:
1285 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1286 }
1287}
1288
1289var _ cc.Coverage = (*apexBundle)(nil)
1290
1291// Implements cc.Coverage
1292func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1293 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1294}
1295
1296// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001297func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001298 a.properties.PreventInstall = true
1299}
1300
1301// Implements cc.Coverage
1302func (a *apexBundle) HideFromMake() {
1303 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001304 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1305 // TODO(ccross): untangle these
1306 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001307}
1308
1309// Implements cc.Coverage
1310func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1311 a.properties.IsCoverageVariant = coverage
1312}
1313
1314// Implements cc.Coverage
1315func (a *apexBundle) EnableCoverageIfNeeded() {}
1316
1317var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1318
1319// Implements android.ApexBudleDepsInfoIntf
1320func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001321 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001322}
1323
Jiyong Parkf4020582021-11-29 12:37:10 +09001324func (a *apexBundle) FutureUpdatable() bool {
1325 return proptools.BoolDefault(a.properties.Future_updatable, false)
1326}
1327
Jiyong Park1bc84122021-06-22 20:23:05 +09001328func (a *apexBundle) UsePlatformApis() bool {
1329 return proptools.BoolDefault(a.properties.Platform_apis, false)
1330}
1331
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001332// getCertString returns the name of the cert that should be used to sign this APEX. This is
1333// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001334func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001335 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001336 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1337 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1338 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001339 if a.vndkApex {
1340 moduleName = vndkApexName
1341 }
1342 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001343 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001344 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001345 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001346 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001347}
1348
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001349// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001350func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001351 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001352}
1353
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001354// See the generate_hashtree property
1355func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001356 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001357}
1358
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001359// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001360func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1361 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1362}
1363
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001364// See the test_only_force_compression property
1365func (a *apexBundle) testOnlyShouldForceCompression() bool {
1366 return proptools.Bool(a.properties.Test_only_force_compression)
1367}
1368
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001369// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1370// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1371// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001372
Jiyong Parkf97782b2019-02-13 20:28:58 +09001373func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1374 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1375 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1376 }
1377}
1378
Jiyong Park388ef3f2019-01-28 19:47:32 +09001379func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001380 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1381 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001382 }
1383
1384 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001385 globalSanitizerNames := []string{}
1386 if a.Host() {
1387 globalSanitizerNames = ctx.Config().SanitizeHost()
1388 } else {
1389 arches := ctx.Config().SanitizeDeviceArch()
1390 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1391 globalSanitizerNames = ctx.Config().SanitizeDevice()
1392 }
1393 }
1394 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001395}
1396
Jooyung Han8ce8db92020-05-15 19:05:05 +09001397func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001398 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1399 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001400 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001401 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001402 for _, target := range ctx.MultiTargets() {
1403 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001404 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1405 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1406 Tests: nil,
1407 Jni_libs: nil,
1408 Binaries: nil,
1409 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001410 break
1411 }
1412 }
1413 }
1414}
1415
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001416// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1417// returned apexFile saves information about the Soong module that will be used for creating the
1418// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001419func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001420 // Decide the APEX-local directory by the multilib of the library In the future, we may
1421 // query this to the module.
1422 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001423 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001424 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001425 case "lib32":
1426 dirInApex = "lib"
1427 case "lib64":
1428 dirInApex = "lib64"
1429 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001430 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001431 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001432 }
Jooyung Han35155c42020-02-06 17:33:20 +09001433 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001434 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001435 // Special case for Bionic libs and other libs installed with them. This is to
1436 // prevent those libs from being included in the search path
1437 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1438 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1439 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1440 // will be loaded into the default linker namespace (aka "platform" namespace). If
1441 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1442 // be loaded again into the runtime linker namespace, which will result in double
1443 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001444 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001445 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001446
Jiyong Parkf653b052019-11-18 15:39:01 +09001447 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001448 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1449 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001450}
1451
Jiyong Park1833cef2019-12-13 13:28:36 +09001452func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001453 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001454 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001455 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001456 }
Jooyung Han35155c42020-02-06 17:33:20 +09001457 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001458 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001459 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1460 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001461 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001462 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001463 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001464}
1465
Jiyong Park99644e92020-11-17 22:21:02 +09001466func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1467 dirInApex := "bin"
1468 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1469 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1470 }
1471 fileToCopy := rustm.OutputFile().Path()
1472 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1473 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1474 return af
1475}
1476
1477func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1478 // Decide the APEX-local directory by the multilib of the library
1479 // In the future, we may query this to the module.
1480 var dirInApex string
1481 switch rustm.Arch().ArchType.Multilib {
1482 case "lib32":
1483 dirInApex = "lib"
1484 case "lib64":
1485 dirInApex = "lib64"
1486 }
1487 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1488 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1489 }
1490 fileToCopy := rustm.OutputFile().Path()
1491 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1492 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1493}
1494
Jiyong Park1833cef2019-12-13 13:28:36 +09001495func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001496 dirInApex := "bin"
1497 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001498 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001499}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001500
Jiyong Park1833cef2019-12-13 13:28:36 +09001501func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001502 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001503 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001504 // NB: Since go binaries are static we don't need the module for anything here, which is
1505 // good since the go tool is a blueprint.Module not an android.Module like we would
1506 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001507 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001508}
1509
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001510func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001511 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001512 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1513 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1514 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001515 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001516 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001517 af.symlinks = sh.Symlinks()
1518 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001519}
1520
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001521func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001522 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001523 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001524 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001525}
1526
atrost6e126252020-01-27 17:01:16 +00001527func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1528 dirInApex := filepath.Join("etc", config.SubDir())
1529 fileToCopy := config.CompatConfig()
1530 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1531}
1532
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001533// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1534// way.
1535type javaModule interface {
1536 android.Module
1537 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001538 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001539 JacocoReportClassesFile() android.Path
1540 LintDepSets() java.LintDepSets
1541 Stem() string
1542}
1543
1544var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001545var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001546var _ javaModule = (*java.SdkLibrary)(nil)
1547var _ javaModule = (*java.DexImport)(nil)
1548var _ javaModule = (*java.SdkLibraryImport)(nil)
1549
Paul Duffin190fdef2021-04-26 10:33:59 +01001550// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001551func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001552 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001553}
1554
1555// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1556func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001557 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001558 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001559 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1560 af.lintDepSets = module.LintDepSets()
1561 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001562 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1563 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1564 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1565 }
1566 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001567 return af
1568}
1569
1570// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1571// the same way.
1572type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001573 android.Module
1574 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001575 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001576 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001577 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001578 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001579 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001580 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001581}
1582
1583var _ androidApp = (*java.AndroidApp)(nil)
1584var _ androidApp = (*java.AndroidAppImport)(nil)
1585
1586func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001587 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001588 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001589 appDir = "priv-app"
1590 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001591 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001592 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001593 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001594 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001595 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001596 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001597
1598 if app, ok := aapp.(interface {
1599 OverriddenManifestPackageName() string
1600 }); ok {
1601 af.overriddenPackageName = app.OverriddenManifestPackageName()
1602 }
Jiyong Park618922e2020-01-08 13:35:43 +09001603 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001604}
1605
Jiyong Park69aeba92020-04-24 21:16:36 +09001606func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1607 rroDir := "overlay"
1608 dirInApex := filepath.Join(rroDir, rro.Theme())
1609 fileToCopy := rro.OutputFile()
1610 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1611 af.certificate = rro.Certificate()
1612
1613 if a, ok := rro.(interface {
1614 OverriddenManifestPackageName() string
1615 }); ok {
1616 af.overriddenPackageName = a.OverriddenManifestPackageName()
1617 }
1618 return af
1619}
1620
markchien2f59ec92020-09-02 16:23:38 +08001621func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1622 dirInApex := filepath.Join("etc", "bpf")
1623 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1624}
1625
Jiyong Park12a719c2021-01-07 15:31:24 +09001626func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1627 dirInApex := filepath.Join("etc", "fs")
1628 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1629}
1630
Paul Duffin064b70c2020-11-02 17:32:38 +00001631// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1633// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1634// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001635func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001636 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001637 am, ok := child.(android.ApexModule)
1638 if !ok || !am.CanHaveApexVariants() {
1639 return false
1640 }
1641
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001642 // Filter-out unwanted depedendencies
1643 depTag := ctx.OtherModuleDependencyTag(child)
1644 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1645 return false
1646 }
1647 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001648 return false
1649 }
1650
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001651 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001652 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001653
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001654 // Visit actually
1655 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001656 })
1657}
1658
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001659// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1660type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001661
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001662const (
1663 ext4 fsType = iota
1664 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001665 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001666)
Artur Satayev849f8442020-04-28 14:57:42 +01001667
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001668func (f fsType) string() string {
1669 switch f {
1670 case ext4:
1671 return ext4FsType
1672 case f2fs:
1673 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001674 case erofs:
1675 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001676 default:
1677 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001678 }
1679}
1680
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001681// Creates build rules for an APEX. It consists of the following major steps:
1682//
1683// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1684// 2) traverse the dependency tree to collect apexFile structs from them.
1685// 3) some fields in apexBundle struct are configured
1686// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001687func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001688 ////////////////////////////////////////////////////////////////////////////////////////////
1689 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001690 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001691 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001692 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001693 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001694 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001695 if len(a.properties.Tests) > 0 && !a.testApex {
1696 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1697 return
1698 }
Jiyong Park678c8812020-02-07 17:25:49 +09001699
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001700 ////////////////////////////////////////////////////////////////////////////////////////////
1701 // 2) traverse the dependency tree to collect apexFile structs from them.
1702
1703 // all the files that will be included in this APEX
1704 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001705
Jooyung Hane1633032019-08-01 17:41:43 +09001706 // native lib dependencies
1707 var provideNativeLibs []string
1708 var requireNativeLibs []string
1709
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001710 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1711
braleeb0c1f0c2021-06-07 22:49:13 +08001712 // Collect the module directory for IDE info in java/jdeps.go.
1713 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1714
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001715 // TODO(jiyong): do this using WalkPayloadDeps
1716 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001717 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001718 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001719 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1720 return false
1721 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001722 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1723 return false
1724 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001725 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001727 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001728 case sharedLibTag, jniLibTag:
1729 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001730 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001731 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1732 fi.isJniLib = isJniLib
1733 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001734 // Collect the list of stub-providing libs except:
1735 // - VNDK libs are only for vendors
1736 // - bootstrap bionic libs are treated as provided by system
1737 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001738 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001739 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001740 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001741 } else if r, ok := child.(*rust.Module); ok {
1742 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001743 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001744 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001745 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001746 propertyName := "native_shared_libs"
1747 if isJniLib {
1748 propertyName = "jni_libs"
1749 }
1750 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001751 }
1752 case executableTag:
1753 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001754 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001755 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001756 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001757 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001758 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001759 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001760 } else if rust, ok := child.(*rust.Module); ok {
1761 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1762 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001763 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001764 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1765 }
1766 case shBinaryTag:
1767 if sh, ok := child.(*sh.ShBinary); ok {
1768 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1769 } else {
1770 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001771 }
Paul Duffin94f19632021-04-20 12:40:07 +01001772 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001773 {
Paul Duffin7771eba2021-04-23 14:25:28 +01001774 if _, ok := child.(*java.BootclasspathFragmentModule); !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001775 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001776 return false
1777 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001778
Paul Duffincc33ec82021-04-25 23:14:55 +01001779 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1780 filesInfo = append(filesInfo, filesToAdd...)
Paul Duffin4d101b62021-03-24 15:42:20 +00001781 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001782 }
satayev333a1732021-05-17 21:35:26 +01001783 case sscpfTag:
1784 {
1785 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1786 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1787 return false
1788 }
satayevb98371c2021-06-15 16:49:50 +01001789 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1790 filesInfo = append(filesInfo, *af)
1791 }
satayev333a1732021-05-17 21:35:26 +01001792 return true
1793 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001794 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001795 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001796 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001797 af := apexFileForJavaModule(ctx, child.(javaModule))
1798 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001799 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1800 return false
1801 }
1802 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001803 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001804 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001805 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001806 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001807 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001808 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001809 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001810 return true // track transitive dependencies
1811 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001812 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001813 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001814 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001815 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1816 appDir := "app"
1817 if ap.Privileged() {
1818 appDir = "priv-app"
1819 }
Yo Chiange8128052020-07-23 20:09:18 +08001820 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001821 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1822 af.certificate = java.PresignedCertificate
1823 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001824 } else {
1825 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1826 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001827 case rroTag:
1828 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1829 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1830 } else {
1831 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1832 }
markchien2f59ec92020-09-02 16:23:38 +08001833 case bpfTag:
1834 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1835 filesToCopy, _ := bpfProgram.OutputFiles("")
1836 for _, bpfFile := range filesToCopy {
1837 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1838 }
1839 } else {
1840 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1841 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001842 case fsTag:
1843 if fs, ok := child.(filesystem.Filesystem); ok {
1844 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1845 } else {
1846 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1847 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001848 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001849 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001850 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001851 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001852 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001853 }
Paul Duffin0b817782021-03-17 15:02:19 +00001854 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001855 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1856 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1857 } else {
1858 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1859 }
Roland Levillain630846d2019-06-26 12:48:34 +01001860 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001861 if ccTest, ok := child.(*cc.Module); ok {
1862 if ccTest.IsTestPerSrcAllTestsVariation() {
1863 // Multiple-output test module (where `test_per_src: true`).
1864 //
1865 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1866 // We do not add this variation to `filesInfo`, as it has no output;
1867 // however, we do add the other variations of this module as indirect
1868 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001869 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001870 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001871 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001872 af.class = nativeTest
1873 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001874 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001875 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001876 } else {
1877 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1878 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001879 case keyTag:
1880 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001881 a.privateKeyFile = key.privateKeyFile
1882 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001883 } else {
1884 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001885 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001886 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001887 case certificateTag:
1888 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001889 a.containerCertificateFile = dep.Certificate.Pem
1890 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001891 } else {
1892 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1893 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001894 case android.PrebuiltDepTag:
1895 // If the prebuilt is force disabled, remember to delete the prebuilt file
1896 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001897 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001898 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1899 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001900 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001901 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001902 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001903 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001904 // We cannot use a switch statement on `depTag` here as the checked
1905 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001906 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001907 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001908 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001909 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001910 return false
1911 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001912 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1913 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001914
1915 // Always track transitive dependencies for host.
1916 if a.Host() {
1917 filesInfo = append(filesInfo, af)
1918 return true
1919 }
1920
Colin Cross56a83212020-09-15 18:30:11 -07001921 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001922 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001923 // If the dependency is a stubs lib, don't include it in this APEX,
1924 // but make sure that the lib is installed on the device.
1925 // In case no APEX is having the lib, the lib is installed to the system
1926 // partition.
1927 //
1928 // Always include if we are a host-apex however since those won't have any
1929 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001930 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001931 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001932 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001933 if !android.InList(name, a.requiredDeps) {
1934 a.requiredDeps = append(a.requiredDeps, name)
1935 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001936 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001937 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001938 // Don't track further
1939 return false
1940 }
Jiyong Parke3867542020-12-03 17:28:25 +09001941
1942 // If the dep is not considered to be in the same
1943 // apex, don't add it to filesInfo so that it is not
1944 // included in this APEX.
1945 // TODO(jiyong): move this to at the top of the
1946 // else-if clause for the indirect dependencies.
1947 // Currently, that's impossible because we would
1948 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001949 // DepIsInSameAPex is false. We also shouldn't do
1950 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001951 //
1952 // TODO(jiyong): explain why the same module is passed in twice.
1953 // Switching the first am to parent breaks lots of tests.
1954 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001955 return false
1956 }
1957
Jiyong Parkf653b052019-11-18 15:39:01 +09001958 filesInfo = append(filesInfo, af)
1959 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001960 } else if rm, ok := child.(*rust.Module); ok {
1961 af := apexFileForRustLibrary(ctx, rm)
1962 af.transitiveDep = true
1963 filesInfo = append(filesInfo, af)
1964 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001965 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001966 } else if cc.IsTestPerSrcDepTag(depTag) {
1967 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001968 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001969 // Handle modules created as `test_per_src` variations of a single test module:
1970 // use the name of the generated test binary (`fileToCopy`) instead of the name
1971 // of the original test module (`depName`, shared by all `test_per_src`
1972 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001973 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001974 // these are not considered transitive dep
1975 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001976 filesInfo = append(filesInfo, af)
1977 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001978 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001979 } else if cc.IsHeaderDepTag(depTag) {
1980 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001981 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001982 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1983 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001984 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001985 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001986 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1987 }
Jiyong Park99644e92020-11-17 22:21:02 +09001988 } else if rust.IsDylibDepTag(depTag) {
1989 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1990 af := apexFileForRustLibrary(ctx, rustm)
1991 af.transitiveDep = true
1992 filesInfo = append(filesInfo, af)
1993 return true // track transitive dependencies
1994 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09001995 } else if rust.IsRlibDepTag(depTag) {
1996 // Rlib is statically linked, but it might have shared lib
1997 // dependencies. Track them.
1998 return true
Paul Duffin65898052021-04-20 22:47:03 +01001999 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002000 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002001 switch child.(type) {
2002 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002003 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002004 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002005 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002006 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002007 return false
2008 }
2009 filesInfo = append(filesInfo, af)
2010 return true // track transitive dependencies
2011 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002012 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 +00002013 }
satayev333a1732021-05-17 21:35:26 +01002014 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2015 // Add the contents of the systemserverclasspath fragment to the apex.
2016 switch child.(type) {
2017 case *java.Library, *java.SdkLibrary:
2018 af := apexFileForJavaModule(ctx, child.(javaModule))
2019 filesInfo = append(filesInfo, af)
2020 return true // track transitive dependencies
2021 default:
2022 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2023 }
Colin Cross56a83212020-09-15 18:30:11 -07002024 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2025 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002026 } else if depTag == android.DarwinUniversalVariantTag {
2027 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002028 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002029 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002030 }
2031 }
2032 }
2033 return false
2034 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002035 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002036 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002037 return
2038 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002039
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002040 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002041 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002042 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002043 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002044 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002045 if e, ok := encountered[dest]; !ok {
2046 encountered[dest] = f
2047 } else {
2048 // If a module is directly included and also transitively depended on
2049 // consider it as directly included.
2050 e.transitiveDep = e.transitiveDep && f.transitiveDep
2051 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002052 }
2053 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002054 var result []apexFile
2055 for _, v := range encountered {
2056 result = append(result, v)
2057 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002058 return result
2059 }
2060 filesInfo = removeDup(filesInfo)
2061
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002062 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002063 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002064 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2065 // changes.
2066 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002067 })
2068
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002069 ////////////////////////////////////////////////////////////////////////////////////////////
2070 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002071 a.installDir = android.PathForModuleInstall(ctx, "apex")
2072 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002073
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002074 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002075 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002076 switch a.properties.ApexType {
2077 case imageApex:
2078 if buildFlattenedAsDefault {
2079 a.suffix = imageApexSuffix
2080 } else {
2081 a.suffix = ""
2082 a.primaryApexType = true
2083
2084 if ctx.Config().InstallExtraFlattenedApexes() {
2085 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2086 }
2087 }
2088 case zipApex:
2089 if proptools.String(a.properties.Payload_type) == "zip" {
2090 a.suffix = ""
2091 a.primaryApexType = true
2092 } else {
2093 a.suffix = zipApexSuffix
2094 }
2095 case flattenedApex:
2096 if buildFlattenedAsDefault {
2097 a.suffix = ""
2098 a.primaryApexType = true
2099 } else {
2100 a.suffix = flattenedSuffix
2101 }
2102 }
2103
Theotime Combes4ba38c12020-06-12 12:46:59 +00002104 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2105 case ext4FsType:
2106 a.payloadFsType = ext4
2107 case f2fsFsType:
2108 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002109 case erofsFsType:
2110 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002111 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002112 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 +00002113 }
2114
Jiyong Park7cd10e32020-01-14 09:22:18 +09002115 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2116 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2117 // the same library in the system partition, thus effectively sharing the same libraries
2118 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2119 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002120 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002121
Jooyung Han85d61762020-06-24 23:50:26 +09002122 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2123 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002124 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002125 a.linkToSystemLib = false
2126 }
2127
Jiyong Park4da07972021-01-05 21:01:11 +09002128 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002129 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002130
Jiyong Park9d677202020-02-19 16:29:35 +09002131 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002132 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002133 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002134 a.linkToSystemLib = false
2135 }
2136
Jiyong Park638d30e2020-02-26 18:27:19 +09002137 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2138 if ctx.Host() {
2139 a.linkToSystemLib = false
2140 }
2141
Colin Cross6340ea52021-11-04 12:01:18 -07002142 if a.properties.ApexType != zipApex {
2143 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2144 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002145
2146 ////////////////////////////////////////////////////////////////////////////////////////////
2147 // 4) generate the build rules to create the APEX. This is done in builder.go.
2148 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002149 if a.properties.ApexType == flattenedApex {
2150 a.buildFlattenedApex(ctx)
2151 } else {
2152 a.buildUnflattenedApex(ctx)
2153 }
Jiyong Park956305c2020-01-09 12:32:06 +09002154 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002155 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002156
2157 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2158 if a.installable() {
2159 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2160 // along with other ordinary files. (Note that this is done by apexer for
2161 // non-flattened APEXes)
2162 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2163
2164 // Place the public key as apex_pubkey. This is also done by apexer for
2165 // non-flattened APEXes case.
2166 // TODO(jiyong): Why do we need this CP rule?
2167 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2168 ctx.Build(pctx, android.BuildParams{
2169 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002170 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002171 Output: copiedPubkey,
2172 })
2173 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2174 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002175}
2176
Paul Duffincc33ec82021-04-25 23:14:55 +01002177// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2178// the bootclasspath_fragment contributes to the apex.
2179func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2180 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2181 var filesToAdd []apexFile
2182
2183 // Add the boot image files, e.g. .art, .oat and .vdex files.
2184 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2185 dirInApex := filepath.Join("javalib", arch.String())
2186 for _, f := range files {
2187 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2188 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2189 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2190 filesToAdd = append(filesToAdd, af)
2191 }
2192 }
2193
satayev3db35472021-05-06 23:59:58 +01002194 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002195 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2196 filesToAdd = append(filesToAdd, *af)
2197 }
satayev3db35472021-05-06 23:59:58 +01002198
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002199 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2200 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2201 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2202
2203 if pathOnHost != nil {
2204 // We need to copy the profile to a temporary path with the right filename because the apexer
2205 // will take the filename as is.
2206 ctx.Build(pctx, android.BuildParams{
2207 Rule: android.Cp,
2208 Input: pathOnHost,
2209 Output: tempPath,
2210 })
2211 } else {
2212 // At this point, the boot image profile cannot be generated. It is probably because the boot
2213 // image profile source file does not exist on the branch, or it is not available for the
2214 // current build target.
2215 // However, we cannot enforce the boot image profile to be generated because some build
2216 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2217 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2218 // only if the APEX is being built.
2219 ctx.Build(pctx, android.BuildParams{
2220 Rule: android.ErrorRule,
2221 Output: tempPath,
2222 Args: map[string]string{
2223 "error": "Boot image profile cannot be generated",
2224 },
2225 })
2226 }
2227
2228 androidMkModuleName := filepath.Base(pathInApex)
2229 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2230 filesToAdd = append(filesToAdd, af)
2231 }
2232
Paul Duffincc33ec82021-04-25 23:14:55 +01002233 return filesToAdd
2234}
2235
satayevb98371c2021-06-15 16:49:50 +01002236// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2237// the module contributes to the apex; or nil if the proto config was not generated.
2238func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2239 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2240 if !info.ClasspathFragmentProtoGenerated {
2241 return nil
2242 }
2243 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2244 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2245 return &af
satayev14e49132021-05-17 21:03:07 +01002246}
2247
Paul Duffincc33ec82021-04-25 23:14:55 +01002248// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2249// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002250func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2251 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2252
2253 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2254 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002255 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2256 if err != nil {
2257 ctx.ModuleErrorf("%s", err)
2258 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002259
2260 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2261 // bootclasspath_fragment.
2262 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2263 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002264}
2265
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002266///////////////////////////////////////////////////////////////////////////////////////////////////
2267// Factory functions
2268//
2269
2270func newApexBundle() *apexBundle {
2271 module := &apexBundle{}
2272
2273 module.AddProperties(&module.properties)
2274 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002275 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002276 module.AddProperties(&module.overridableProperties)
2277
2278 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2279 android.InitDefaultableModule(module)
2280 android.InitSdkAwareModule(module)
2281 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002282 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002283 return module
2284}
2285
Paul Duffineb8051d2021-10-18 17:49:39 +01002286func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002287 bundle := newApexBundle()
2288 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002289 return bundle
2290}
2291
2292// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2293// certain compatibility checks such as apex_available are not done for apex_test.
2294func testApexBundleFactory() android.Module {
2295 bundle := newApexBundle()
2296 bundle.testApex = true
2297 return bundle
2298}
2299
2300// apex packages other modules into an APEX file which is a packaging format for system-level
2301// components like binaries, shared libraries, etc.
2302func BundleFactory() android.Module {
2303 return newApexBundle()
2304}
2305
2306type Defaults struct {
2307 android.ModuleBase
2308 android.DefaultsModuleBase
2309}
2310
2311// apex_defaults provides defaultable properties to other apex modules.
2312func defaultsFactory() android.Module {
2313 return DefaultsFactory()
2314}
2315
2316func DefaultsFactory(props ...interface{}) android.Module {
2317 module := &Defaults{}
2318
2319 module.AddProperties(props...)
2320 module.AddProperties(
2321 &apexBundleProperties{},
2322 &apexTargetBundleProperties{},
2323 &overridableProperties{},
2324 )
2325
2326 android.InitDefaultsModule(module)
2327 return module
2328}
2329
2330type OverrideApex struct {
2331 android.ModuleBase
2332 android.OverrideModuleBase
2333}
2334
2335func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2336 // All the overrides happen in the base module.
2337}
2338
2339// override_apex is used to create an apex module based on another apex module by overriding some of
2340// its properties.
2341func overrideApexFactory() android.Module {
2342 m := &OverrideApex{}
2343
2344 m.AddProperties(&overridableProperties{})
2345
2346 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2347 android.InitOverrideModule(m)
2348 return m
2349}
2350
2351///////////////////////////////////////////////////////////////////////////////////////////////////
2352// Vality check routines
2353//
2354// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2355// certain conditions are not met.
2356//
2357// TODO(jiyong): move these checks to a separate go file.
2358
satayevad991492021-12-03 18:58:32 +00002359var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2360
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002361// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2362// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002363func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002364 if a.testApex || a.vndkApex {
2365 return
2366 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002367 // apexBundle::minSdkVersion reports its own errors.
2368 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002369 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002370}
2371
satayevad991492021-12-03 18:58:32 +00002372func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2373 return android.SdkSpec{
2374 Kind: android.SdkNone,
2375 ApiLevel: a.minSdkVersion(ctx),
2376 Raw: String(a.properties.Min_sdk_version),
2377 }
2378}
2379
2380func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002381 ver := proptools.String(a.properties.Min_sdk_version)
2382 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002383 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002384 }
2385 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2386 if err != nil {
2387 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2388 return android.NoneApiLevel
2389 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002390 return apiLevel
2391}
2392
2393// Ensures that a lib providing stub isn't statically linked
2394func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2395 // Practically, we only care about regular APEXes on the device.
2396 if ctx.Host() || a.testApex || a.vndkApex {
2397 return
2398 }
2399
2400 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2401
2402 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2403 if ccm, ok := to.(*cc.Module); ok {
2404 apexName := ctx.ModuleName()
2405 fromName := ctx.OtherModuleName(from)
2406 toName := ctx.OtherModuleName(to)
2407
2408 // If `to` is not actually in the same APEX as `from` then it does not need
2409 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002410 //
2411 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002412 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2413 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2414 return false
2415 }
2416
2417 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2418 // exception to this rule. It can't make the static dependencies dynamic
2419 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002420 // Same rule should be applied to linkerconfig, because it should be executed
2421 // only with static linked libraries before linker is available with ld.config.txt
2422 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002423 return false
2424 }
2425
2426 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2427 if isStubLibraryFromOtherApex && !externalDep {
2428 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2429 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2430 }
2431
2432 }
2433 return true
2434 })
2435}
2436
satayevb98371c2021-06-15 16:49:50 +01002437// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002438func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2439 if a.Updatable() {
2440 if String(a.properties.Min_sdk_version) == "" {
2441 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2442 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002443 if a.UsePlatformApis() {
2444 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2445 }
Daniel Norman69109112021-12-02 12:52:42 -08002446 if a.SocSpecific() || a.DeviceSpecific() {
2447 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2448 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002449 if a.FutureUpdatable() {
2450 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2451 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002452 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002453 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002454 }
2455}
2456
satayevb98371c2021-06-15 16:49:50 +01002457// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2458func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2459 ctx.VisitDirectDeps(func(module android.Module) {
2460 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2461 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2462 if !info.ClasspathFragmentProtoGenerated {
2463 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2464 }
2465 }
2466 })
2467}
2468
2469// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002470func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002471 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2472 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002473 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2474 tag := ctx.OtherModuleDependencyTag(module)
2475 switch tag {
2476 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002477 if m, ok := module.(interface {
2478 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2479 }); ok {
2480 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002481 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2482 }
2483 }
2484 }
2485 })
2486}
2487
satayevb98371c2021-06-15 16:49:50 +01002488// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002489func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2490 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2491 if ctx.Host() || a.testApex || a.vndkApex {
2492 return
2493 }
2494
2495 // Because APEXes targeting other than system/system_ext partitions can't set
2496 // apex_available, we skip checks for these APEXes
2497 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2498 return
2499 }
2500
2501 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2502 // Requiring them and their transitive depencies with apex_available is not right
2503 // because they just add noise.
2504 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2505 return
2506 }
2507
2508 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2509 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2510 if externalDep {
2511 return false
2512 }
2513
2514 apexName := ctx.ModuleName()
2515 fromName := ctx.OtherModuleName(from)
2516 toName := ctx.OtherModuleName(to)
2517
2518 // If `to` is not actually in the same APEX as `from` then it does not need
2519 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002520 //
2521 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002522 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2523 // As soon as the dependency graph crosses the APEX boundary, don't go
2524 // further.
2525 return false
2526 }
2527
2528 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2529 return true
2530 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002531 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2532 "\n\nDependency path:%s\n\n"+
2533 "Consider adding %q to 'apex_available' property of %q",
2534 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002535 // Visit this module's dependencies to check and report any issues with their availability.
2536 return true
2537 })
2538}
2539
Jiyong Park192600a2021-08-03 07:52:17 +00002540// checkStaticExecutable ensures that executables in an APEX are not static.
2541func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002542 // No need to run this for host APEXes
2543 if ctx.Host() {
2544 return
2545 }
2546
Jiyong Park192600a2021-08-03 07:52:17 +00002547 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2548 if ctx.OtherModuleDependencyTag(module) != executableTag {
2549 return
2550 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002551
2552 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002553 apex := a.ApexVariationName()
2554 exec := ctx.OtherModuleName(module)
2555 if isStaticExecutableAllowed(apex, exec) {
2556 return
2557 }
2558 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2559 }
2560 })
2561}
2562
2563// A small list of exceptions where static executables are allowed in APEXes.
2564func isStaticExecutableAllowed(apex string, exec string) bool {
2565 m := map[string][]string{
2566 "com.android.runtime": []string{
2567 "linker",
2568 "linkerconfig",
2569 },
2570 }
2571 execNames, ok := m[apex]
2572 return ok && android.InList(exec, execNames)
2573}
2574
braleeb0c1f0c2021-06-07 22:49:13 +08002575// Collect information for opening IDE project files in java/jdeps.go.
2576func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2577 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2578 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2579 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2580 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2581}
2582
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002583var (
2584 apexAvailBaseline = makeApexAvailableBaseline()
2585 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2586)
2587
Colin Cross440e0d02020-06-11 11:32:11 -07002588func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002589 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002590 moduleName = normalizeModuleName(moduleName)
2591
Colin Cross440e0d02020-06-11 11:32:11 -07002592 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002593 return true
2594 }
2595
2596 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002597 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002598 return true
2599 }
2600
2601 return false
2602}
2603
2604func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002605 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2606 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002607 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002608 if strings.HasPrefix(moduleName, "libclang_rt.") {
2609 // This module has many arch variants that depend on the product being built.
2610 // We don't want to list them all
2611 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002612 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002613 if strings.HasPrefix(moduleName, "androidx.") {
2614 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2615 moduleName = "androidx"
2616 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002617 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002618}
2619
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002620// Transform the map of apex -> modules to module -> apexes.
2621func invertApexBaseline(m map[string][]string) map[string][]string {
2622 r := make(map[string][]string)
2623 for apex, modules := range m {
2624 for _, module := range modules {
2625 r[module] = append(r[module], apex)
2626 }
2627 }
2628 return r
2629}
2630
2631// Retrieve the baseline of apexes to which the supplied module belongs.
2632func BaselineApexAvailable(moduleName string) []string {
2633 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2634}
2635
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002636// This is a map from apex to modules, which overrides the apex_available setting for that
2637// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002638// TODO(b/147364041): remove this
2639func makeApexAvailableBaseline() map[string][]string {
2640 // The "Module separator"s below are employed to minimize merge conflicts.
2641 m := make(map[string][]string)
2642 //
2643 // Module separator
2644 //
2645 m["com.android.appsearch"] = []string{
2646 "icing-java-proto-lite",
2647 "libprotobuf-java-lite",
2648 }
2649 //
2650 // Module separator
2651 //
2652 m["com.android.bluetooth.updatable"] = []string{
2653 "android.hardware.audio.common@5.0",
2654 "android.hardware.bluetooth.a2dp@1.0",
2655 "android.hardware.bluetooth.audio@2.0",
2656 "android.hardware.bluetooth@1.0",
2657 "android.hardware.bluetooth@1.1",
2658 "android.hardware.graphics.bufferqueue@1.0",
2659 "android.hardware.graphics.bufferqueue@2.0",
2660 "android.hardware.graphics.common@1.0",
2661 "android.hardware.graphics.common@1.1",
2662 "android.hardware.graphics.common@1.2",
2663 "android.hardware.media@1.0",
2664 "android.hidl.safe_union@1.0",
2665 "android.hidl.token@1.0",
2666 "android.hidl.token@1.0-utils",
2667 "avrcp-target-service",
2668 "avrcp_headers",
2669 "bluetooth-protos-lite",
2670 "bluetooth.mapsapi",
2671 "com.android.vcard",
2672 "dnsresolver_aidl_interface-V2-java",
2673 "ipmemorystore-aidl-interfaces-V5-java",
2674 "ipmemorystore-aidl-interfaces-java",
2675 "internal_include_headers",
2676 "lib-bt-packets",
2677 "lib-bt-packets-avrcp",
2678 "lib-bt-packets-base",
2679 "libFraunhoferAAC",
2680 "libaudio-a2dp-hw-utils",
2681 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002682 "libbluetooth",
2683 "libbluetooth-types",
2684 "libbluetooth-types-header",
2685 "libbluetooth_gd",
2686 "libbluetooth_headers",
2687 "libbluetooth_jni",
2688 "libbt-audio-hal-interface",
2689 "libbt-bta",
2690 "libbt-common",
2691 "libbt-hci",
2692 "libbt-platform-protos-lite",
2693 "libbt-protos-lite",
2694 "libbt-sbc-decoder",
2695 "libbt-sbc-encoder",
2696 "libbt-stack",
2697 "libbt-utils",
2698 "libbtcore",
2699 "libbtdevice",
2700 "libbte",
2701 "libbtif",
2702 "libchrome",
2703 "libevent",
2704 "libfmq",
2705 "libg722codec",
2706 "libgui_headers",
2707 "libmedia_headers",
2708 "libmodpb64",
2709 "libosi",
2710 "libstagefright_foundation_headers",
2711 "libstagefright_headers",
2712 "libstatslog",
2713 "libstatssocket",
2714 "libtinyxml2",
2715 "libudrv-uipc",
2716 "libz",
2717 "media_plugin_headers",
2718 "net-utils-services-common",
2719 "netd_aidl_interface-unstable-java",
2720 "netd_event_listener_interface-java",
2721 "netlink-client",
2722 "networkstack-client",
2723 "sap-api-java-static",
2724 "services.net",
2725 }
2726 //
2727 // Module separator
2728 //
2729 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2730 //
2731 // Module separator
2732 //
2733 m["com.android.extservices"] = []string{
2734 "error_prone_annotations",
2735 "ExtServices-core",
2736 "ExtServices",
2737 "libtextclassifier-java",
2738 "libz_current",
2739 "textclassifier-statsd",
2740 "TextClassifierNotificationLibNoManifest",
2741 "TextClassifierServiceLibNoManifest",
2742 }
2743 //
2744 // Module separator
2745 //
2746 m["com.android.neuralnetworks"] = []string{
2747 "android.hardware.neuralnetworks@1.0",
2748 "android.hardware.neuralnetworks@1.1",
2749 "android.hardware.neuralnetworks@1.2",
2750 "android.hardware.neuralnetworks@1.3",
2751 "android.hidl.allocator@1.0",
2752 "android.hidl.memory.token@1.0",
2753 "android.hidl.memory@1.0",
2754 "android.hidl.safe_union@1.0",
2755 "libarect",
2756 "libbuildversion",
2757 "libmath",
2758 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002759 }
2760 //
2761 // Module separator
2762 //
2763 m["com.android.media"] = []string{
2764 "android.frameworks.bufferhub@1.0",
2765 "android.hardware.cas.native@1.0",
2766 "android.hardware.cas@1.0",
2767 "android.hardware.configstore-utils",
2768 "android.hardware.configstore@1.0",
2769 "android.hardware.configstore@1.1",
2770 "android.hardware.graphics.allocator@2.0",
2771 "android.hardware.graphics.allocator@3.0",
2772 "android.hardware.graphics.bufferqueue@1.0",
2773 "android.hardware.graphics.bufferqueue@2.0",
2774 "android.hardware.graphics.common@1.0",
2775 "android.hardware.graphics.common@1.1",
2776 "android.hardware.graphics.common@1.2",
2777 "android.hardware.graphics.mapper@2.0",
2778 "android.hardware.graphics.mapper@2.1",
2779 "android.hardware.graphics.mapper@3.0",
2780 "android.hardware.media.omx@1.0",
2781 "android.hardware.media@1.0",
2782 "android.hidl.allocator@1.0",
2783 "android.hidl.memory.token@1.0",
2784 "android.hidl.memory@1.0",
2785 "android.hidl.token@1.0",
2786 "android.hidl.token@1.0-utils",
2787 "bionic_libc_platform_headers",
2788 "exoplayer2-extractor",
2789 "exoplayer2-extractor-annotation-stubs",
2790 "gl_headers",
2791 "jsr305",
2792 "libEGL",
2793 "libEGL_blobCache",
2794 "libEGL_getProcAddress",
2795 "libFLAC",
2796 "libFLAC-config",
2797 "libFLAC-headers",
2798 "libGLESv2",
2799 "libaacextractor",
2800 "libamrextractor",
2801 "libarect",
2802 "libaudio_system_headers",
2803 "libaudioclient",
2804 "libaudioclient_headers",
2805 "libaudiofoundation",
2806 "libaudiofoundation_headers",
2807 "libaudiomanager",
2808 "libaudiopolicy",
2809 "libaudioutils",
2810 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002811 "libbluetooth-types-header",
2812 "libbufferhub",
2813 "libbufferhub_headers",
2814 "libbufferhubqueue",
2815 "libc_malloc_debug_backtrace",
2816 "libcamera_client",
2817 "libcamera_metadata",
2818 "libdvr_headers",
2819 "libexpat",
2820 "libfifo",
2821 "libflacextractor",
2822 "libgrallocusage",
2823 "libgraphicsenv",
2824 "libgui",
2825 "libgui_headers",
2826 "libhardware_headers",
2827 "libinput",
2828 "liblzma",
2829 "libmath",
2830 "libmedia",
2831 "libmedia_codeclist",
2832 "libmedia_headers",
2833 "libmedia_helper",
2834 "libmedia_helper_headers",
2835 "libmedia_midiiowrapper",
2836 "libmedia_omx",
2837 "libmediautils",
2838 "libmidiextractor",
2839 "libmkvextractor",
2840 "libmp3extractor",
2841 "libmp4extractor",
2842 "libmpeg2extractor",
2843 "libnativebase_headers",
2844 "libnativewindow_headers",
2845 "libnblog",
2846 "liboggextractor",
2847 "libpackagelistparser",
2848 "libpdx",
2849 "libpdx_default_transport",
2850 "libpdx_headers",
2851 "libpdx_uds",
2852 "libprocinfo",
2853 "libspeexresampler",
2854 "libspeexresampler",
2855 "libstagefright_esds",
2856 "libstagefright_flacdec",
2857 "libstagefright_flacdec",
2858 "libstagefright_foundation",
2859 "libstagefright_foundation_headers",
2860 "libstagefright_foundation_without_imemory",
2861 "libstagefright_headers",
2862 "libstagefright_id3",
2863 "libstagefright_metadatautils",
2864 "libstagefright_mpeg2extractor",
2865 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002866 "libui",
2867 "libui_headers",
2868 "libunwindstack",
2869 "libvibrator",
2870 "libvorbisidec",
2871 "libwavextractor",
2872 "libwebm",
2873 "media_ndk_headers",
2874 "media_plugin_headers",
2875 "updatable-media",
2876 }
2877 //
2878 // Module separator
2879 //
2880 m["com.android.media.swcodec"] = []string{
2881 "android.frameworks.bufferhub@1.0",
2882 "android.hardware.common-ndk_platform",
2883 "android.hardware.configstore-utils",
2884 "android.hardware.configstore@1.0",
2885 "android.hardware.configstore@1.1",
2886 "android.hardware.graphics.allocator@2.0",
2887 "android.hardware.graphics.allocator@3.0",
2888 "android.hardware.graphics.allocator@4.0",
2889 "android.hardware.graphics.bufferqueue@1.0",
2890 "android.hardware.graphics.bufferqueue@2.0",
2891 "android.hardware.graphics.common-ndk_platform",
2892 "android.hardware.graphics.common@1.0",
2893 "android.hardware.graphics.common@1.1",
2894 "android.hardware.graphics.common@1.2",
2895 "android.hardware.graphics.mapper@2.0",
2896 "android.hardware.graphics.mapper@2.1",
2897 "android.hardware.graphics.mapper@3.0",
2898 "android.hardware.graphics.mapper@4.0",
2899 "android.hardware.media.bufferpool@2.0",
2900 "android.hardware.media.c2@1.0",
2901 "android.hardware.media.c2@1.1",
2902 "android.hardware.media.omx@1.0",
2903 "android.hardware.media@1.0",
2904 "android.hardware.media@1.0",
2905 "android.hidl.memory.token@1.0",
2906 "android.hidl.memory@1.0",
2907 "android.hidl.safe_union@1.0",
2908 "android.hidl.token@1.0",
2909 "android.hidl.token@1.0-utils",
2910 "libEGL",
2911 "libFLAC",
2912 "libFLAC-config",
2913 "libFLAC-headers",
2914 "libFraunhoferAAC",
2915 "libLibGuiProperties",
2916 "libarect",
2917 "libaudio_system_headers",
2918 "libaudioutils",
2919 "libaudioutils",
2920 "libaudioutils_fixedfft",
2921 "libavcdec",
2922 "libavcenc",
2923 "libavservices_minijail",
2924 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002925 "libbinderthreadstateutils",
2926 "libbluetooth-types-header",
2927 "libbufferhub_headers",
2928 "libcodec2",
2929 "libcodec2_headers",
2930 "libcodec2_hidl@1.0",
2931 "libcodec2_hidl@1.1",
2932 "libcodec2_internal",
2933 "libcodec2_soft_aacdec",
2934 "libcodec2_soft_aacenc",
2935 "libcodec2_soft_amrnbdec",
2936 "libcodec2_soft_amrnbenc",
2937 "libcodec2_soft_amrwbdec",
2938 "libcodec2_soft_amrwbenc",
2939 "libcodec2_soft_av1dec_gav1",
2940 "libcodec2_soft_avcdec",
2941 "libcodec2_soft_avcenc",
2942 "libcodec2_soft_common",
2943 "libcodec2_soft_flacdec",
2944 "libcodec2_soft_flacenc",
2945 "libcodec2_soft_g711alawdec",
2946 "libcodec2_soft_g711mlawdec",
2947 "libcodec2_soft_gsmdec",
2948 "libcodec2_soft_h263dec",
2949 "libcodec2_soft_h263enc",
2950 "libcodec2_soft_hevcdec",
2951 "libcodec2_soft_hevcenc",
2952 "libcodec2_soft_mp3dec",
2953 "libcodec2_soft_mpeg2dec",
2954 "libcodec2_soft_mpeg4dec",
2955 "libcodec2_soft_mpeg4enc",
2956 "libcodec2_soft_opusdec",
2957 "libcodec2_soft_opusenc",
2958 "libcodec2_soft_rawdec",
2959 "libcodec2_soft_vorbisdec",
2960 "libcodec2_soft_vp8dec",
2961 "libcodec2_soft_vp8enc",
2962 "libcodec2_soft_vp9dec",
2963 "libcodec2_soft_vp9enc",
2964 "libcodec2_vndk",
2965 "libdvr_headers",
2966 "libfmq",
2967 "libfmq",
2968 "libgav1",
2969 "libgralloctypes",
2970 "libgrallocusage",
2971 "libgraphicsenv",
2972 "libgsm",
2973 "libgui_bufferqueue_static",
2974 "libgui_headers",
2975 "libhardware",
2976 "libhardware_headers",
2977 "libhevcdec",
2978 "libhevcenc",
2979 "libion",
2980 "libjpeg",
2981 "liblzma",
2982 "libmath",
2983 "libmedia_codecserviceregistrant",
2984 "libmedia_headers",
2985 "libmpeg2dec",
2986 "libnativebase_headers",
2987 "libnativewindow_headers",
2988 "libpdx_headers",
2989 "libscudo_wrapper",
2990 "libsfplugin_ccodec_utils",
2991 "libspeexresampler",
2992 "libstagefright_amrnb_common",
2993 "libstagefright_amrnbdec",
2994 "libstagefright_amrnbenc",
2995 "libstagefright_amrwbdec",
2996 "libstagefright_amrwbenc",
2997 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002998 "libstagefright_enc_common",
2999 "libstagefright_flacdec",
3000 "libstagefright_foundation",
3001 "libstagefright_foundation_headers",
3002 "libstagefright_headers",
3003 "libstagefright_m4vh263dec",
3004 "libstagefright_m4vh263enc",
3005 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003006 "libui",
3007 "libui_headers",
3008 "libunwindstack",
3009 "libvorbisidec",
3010 "libvpx",
3011 "libyuv",
3012 "libyuv_static",
3013 "media_ndk_headers",
3014 "media_plugin_headers",
3015 "mediaswcodec",
3016 }
3017 //
3018 // Module separator
3019 //
3020 m["com.android.mediaprovider"] = []string{
3021 "MediaProvider",
3022 "MediaProviderGoogle",
3023 "fmtlib_ndk",
3024 "libbase_ndk",
3025 "libfuse",
3026 "libfuse_jni",
3027 }
3028 //
3029 // Module separator
3030 //
3031 m["com.android.permission"] = []string{
3032 "car-ui-lib",
3033 "iconloader",
3034 "kotlin-annotations",
3035 "kotlin-stdlib",
3036 "kotlin-stdlib-jdk7",
3037 "kotlin-stdlib-jdk8",
3038 "kotlinx-coroutines-android",
3039 "kotlinx-coroutines-android-nodeps",
3040 "kotlinx-coroutines-core",
3041 "kotlinx-coroutines-core-nodeps",
3042 "permissioncontroller-statsd",
3043 "GooglePermissionController",
3044 "PermissionController",
3045 "SettingsLibActionBarShadow",
3046 "SettingsLibAppPreference",
3047 "SettingsLibBarChartPreference",
3048 "SettingsLibLayoutPreference",
3049 "SettingsLibProgressBar",
3050 "SettingsLibSearchWidget",
3051 "SettingsLibSettingsTheme",
3052 "SettingsLibRestrictedLockUtils",
3053 "SettingsLibHelpUtils",
3054 }
3055 //
3056 // Module separator
3057 //
3058 m["com.android.runtime"] = []string{
3059 "bionic_libc_platform_headers",
3060 "libarm-optimized-routines-math",
3061 "libc_aeabi",
3062 "libc_bionic",
3063 "libc_bionic_ndk",
3064 "libc_bootstrap",
3065 "libc_common",
3066 "libc_common_shared",
3067 "libc_common_static",
3068 "libc_dns",
3069 "libc_dynamic_dispatch",
3070 "libc_fortify",
3071 "libc_freebsd",
3072 "libc_freebsd_large_stack",
3073 "libc_gdtoa",
3074 "libc_init_dynamic",
3075 "libc_init_static",
3076 "libc_jemalloc_wrapper",
3077 "libc_netbsd",
3078 "libc_nomalloc",
3079 "libc_nopthread",
3080 "libc_openbsd",
3081 "libc_openbsd_large_stack",
3082 "libc_openbsd_ndk",
3083 "libc_pthread",
3084 "libc_static_dispatch",
3085 "libc_syscalls",
3086 "libc_tzcode",
3087 "libc_unwind_static",
3088 "libdebuggerd",
3089 "libdebuggerd_common_headers",
3090 "libdebuggerd_handler_core",
3091 "libdebuggerd_handler_fallback",
3092 "libdl_static",
3093 "libjemalloc5",
3094 "liblinker_main",
3095 "liblinker_malloc",
3096 "liblz4",
3097 "liblzma",
3098 "libprocinfo",
3099 "libpropertyinfoparser",
3100 "libscudo",
3101 "libstdc++",
3102 "libsystemproperties",
3103 "libtombstoned_client_static",
3104 "libunwindstack",
3105 "libz",
3106 "libziparchive",
3107 }
3108 //
3109 // Module separator
3110 //
3111 m["com.android.tethering"] = []string{
3112 "android.hardware.tetheroffload.config-V1.0-java",
3113 "android.hardware.tetheroffload.control-V1.0-java",
3114 "android.hidl.base-V1.0-java",
3115 "libcgrouprc",
3116 "libcgrouprc_format",
3117 "libtetherutilsjni",
3118 "libvndksupport",
3119 "net-utils-framework-common",
3120 "netd_aidl_interface-V3-java",
3121 "netlink-client",
3122 "networkstack-aidl-interfaces-java",
3123 "tethering-aidl-interfaces-java",
3124 "TetheringApiCurrentLib",
3125 }
3126 //
3127 // Module separator
3128 //
3129 m["com.android.wifi"] = []string{
3130 "PlatformProperties",
3131 "android.hardware.wifi-V1.0-java",
3132 "android.hardware.wifi-V1.0-java-constants",
3133 "android.hardware.wifi-V1.1-java",
3134 "android.hardware.wifi-V1.2-java",
3135 "android.hardware.wifi-V1.3-java",
3136 "android.hardware.wifi-V1.4-java",
3137 "android.hardware.wifi.hostapd-V1.0-java",
3138 "android.hardware.wifi.hostapd-V1.1-java",
3139 "android.hardware.wifi.hostapd-V1.2-java",
3140 "android.hardware.wifi.supplicant-V1.0-java",
3141 "android.hardware.wifi.supplicant-V1.1-java",
3142 "android.hardware.wifi.supplicant-V1.2-java",
3143 "android.hardware.wifi.supplicant-V1.3-java",
3144 "android.hidl.base-V1.0-java",
3145 "android.hidl.manager-V1.0-java",
3146 "android.hidl.manager-V1.1-java",
3147 "android.hidl.manager-V1.2-java",
3148 "bouncycastle-unbundled",
3149 "dnsresolver_aidl_interface-V2-java",
3150 "error_prone_annotations",
3151 "framework-wifi-pre-jarjar",
3152 "framework-wifi-util-lib",
3153 "ipmemorystore-aidl-interfaces-V3-java",
3154 "ipmemorystore-aidl-interfaces-java",
3155 "ksoap2",
3156 "libnanohttpd",
3157 "libwifi-jni",
3158 "net-utils-services-common",
3159 "netd_aidl_interface-V2-java",
3160 "netd_aidl_interface-unstable-java",
3161 "netd_event_listener_interface-java",
3162 "netlink-client",
3163 "networkstack-client",
3164 "services.net",
3165 "wifi-lite-protos",
3166 "wifi-nano-protos",
3167 "wifi-service-pre-jarjar",
3168 "wifi-service-resources",
3169 }
3170 //
3171 // Module separator
3172 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003173 m["com.android.os.statsd"] = []string{
3174 "libstatssocket",
3175 }
3176 //
3177 // Module separator
3178 //
3179 m[android.AvailableToAnyApex] = []string{
3180 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3181 "androidx",
3182 "androidx-constraintlayout_constraintlayout",
3183 "androidx-constraintlayout_constraintlayout-nodeps",
3184 "androidx-constraintlayout_constraintlayout-solver",
3185 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3186 "com.google.android.material_material",
3187 "com.google.android.material_material-nodeps",
3188
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003189 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003190 "libprofile-clang-extras",
3191 "libprofile-clang-extras_ndk",
3192 "libprofile-extras",
3193 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003194 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003195 }
3196 return m
3197}
3198
3199func init() {
3200 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3201 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3202}
3203
3204func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3205 rules := make([]android.Rule, 0, len(modules_packages))
3206 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003207 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003208 BootclasspathJar().
3209 With("apex_available", module_name).
3210 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003211 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003212 Because("jars that are part of the " + module_name +
3213 " module may only allow these packages: " + strings.Join(module_packages, ",") +
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003214 " with min_sdk < T. Please jarjar or move code around.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003215 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003216 }
3217 return rules
3218}
3219
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003220// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on Q/R/S.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003221// Adding code to the bootclasspath in new packages will cause issues on module update.
3222func qModulesPackages() map[string][]string {
3223 return map[string][]string{
3224 "com.android.conscrypt": []string{
3225 "android.net.ssl",
3226 "com.android.org.conscrypt",
3227 },
3228 "com.android.media": []string{
3229 "android.media",
3230 },
3231 }
3232}
3233
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003234// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on R/S.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003235// Adding code to the bootclasspath in new packages will cause issues on module update.
3236func rModulesPackages() map[string][]string {
3237 return map[string][]string{
3238 "com.android.mediaprovider": []string{
3239 "android.provider",
3240 },
3241 "com.android.permission": []string{
3242 "android.permission",
3243 "android.app.role",
3244 "com.android.permission",
3245 "com.android.role",
3246 },
3247 "com.android.sdkext": []string{
3248 "android.os.ext",
3249 },
3250 "com.android.os.statsd": []string{
3251 "android.app",
3252 "android.os",
3253 "android.util",
3254 "com.android.internal.statsd",
3255 "com.android.server.stats",
3256 },
3257 "com.android.wifi": []string{
3258 "com.android.server.wifi",
3259 "com.android.wifi.x",
3260 "android.hardware.wifi",
3261 "android.net.wifi",
3262 },
3263 "com.android.tethering": []string{
3264 "android.net",
3265 },
3266 }
3267}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003268
3269// For Bazel / bp2build
3270
3271type bazelApexBundleAttributes struct {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003272 Manifest bazel.LabelAttribute
3273 Android_manifest bazel.LabelAttribute
3274 File_contexts bazel.LabelAttribute
3275 Key bazel.LabelAttribute
3276 Certificate bazel.LabelAttribute
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003277 Min_sdk_version *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003278 Updatable bazel.BoolAttribute
3279 Installable bazel.BoolAttribute
3280 Native_shared_libs bazel.LabelListAttribute
3281 Binaries bazel.StringListAttribute
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003282 Prebuilts bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003283}
3284
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003285func ApexBundleBp2Build(ctx android.TopDownMutatorContext) {
3286 module, ok := ctx.Module().(*apexBundle)
3287 if !ok {
3288 // Not an APEX bundle
3289 return
3290 }
3291 if !module.ConvertWithBp2build(ctx) {
3292 return
3293 }
3294 if ctx.ModuleType() != "apex" {
3295 return
3296 }
3297
3298 apexBundleBp2BuildInternal(ctx, module)
3299}
3300
3301func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) {
3302 var manifestLabelAttribute bazel.LabelAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003303 if module.properties.Manifest != nil {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003304 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Manifest))
3305 }
3306
3307 var androidManifestLabelAttribute bazel.LabelAttribute
3308 if module.properties.AndroidManifest != nil {
3309 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.AndroidManifest))
3310 }
3311
3312 var fileContextsLabelAttribute bazel.LabelAttribute
3313 if module.properties.File_contexts != nil {
3314 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.File_contexts))
3315 }
3316
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003317 var minSdkVersion *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003318 if module.properties.Min_sdk_version != nil {
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003319 minSdkVersion = module.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003320 }
3321
3322 var keyLabelAttribute bazel.LabelAttribute
3323 if module.overridableProperties.Key != nil {
3324 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Key))
3325 }
3326
3327 var certificateLabelAttribute bazel.LabelAttribute
3328 if module.overridableProperties.Certificate != nil {
3329 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Certificate))
3330 }
3331
3332 nativeSharedLibs := module.properties.ApexNativeDependencies.Native_shared_libs
3333 nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
3334 nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
3335
Daniel Norman5a3ce132021-08-26 15:44:43 -07003336 prebuilts := module.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003337 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3338 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3339
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003340 binaries := module.properties.ApexNativeDependencies.Binaries
3341 binariesStringListAttribute := bazel.MakeStringListAttribute(binaries)
3342
3343 var updatableAttribute bazel.BoolAttribute
3344 if module.properties.Updatable != nil {
3345 updatableAttribute.Value = module.properties.Updatable
3346 }
3347
3348 var installableAttribute bazel.BoolAttribute
3349 if module.properties.Installable != nil {
3350 installableAttribute.Value = module.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003351 }
3352
3353 attrs := &bazelApexBundleAttributes{
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003354 Manifest: manifestLabelAttribute,
3355 Android_manifest: androidManifestLabelAttribute,
3356 File_contexts: fileContextsLabelAttribute,
3357 Min_sdk_version: minSdkVersion,
3358 Key: keyLabelAttribute,
3359 Certificate: certificateLabelAttribute,
3360 Updatable: updatableAttribute,
3361 Installable: installableAttribute,
3362 Native_shared_libs: nativeSharedLibsLabelListAttribute,
3363 Binaries: binariesStringListAttribute,
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003364 Prebuilts: prebuiltsLabelListAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003365 }
3366
3367 props := bazel.BazelTargetModuleProperties{
3368 Rule_class: "apex",
3369 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3370 }
3371
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +00003372 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003373}