blob: a28cd725aabfd7e4fbdf64c4c3350fd7fc932d31 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090034 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/java"
36 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090037 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090039)
40
Jiyong Park8e6d52f2020-11-19 14:37:47 +090041func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000042 registerApexBuildComponents(android.InitRegistrationContext)
43}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044
Paul Duffin667893c2021-03-09 22:34:13 +000045func registerApexBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("apex", BundleFactory)
47 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
48 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
49 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
50 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
51 ctx.RegisterModuleType("override_apex", overrideApexFactory)
52 ctx.RegisterModuleType("apex_set", apexSetFactory)
53
Paul Duffin5dda3e32021-05-05 14:13:27 +010054 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.PreDepsMutators(RegisterPreDepsMutators)
56 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090057}
58
Paul Duffin5dda3e32021-05-05 14:13:27 +010059func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
60 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
61}
62
Jiyong Park8e6d52f2020-11-19 14:37:47 +090063func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
64 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
65 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
66}
67
68func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000069 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090070 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
71 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
72 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010073 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
74 // it should create a platform variant.
75 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090076 ctx.BottomUp("apex", apexMutator).Parallel()
77 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
78 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090079}
80
81type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090082 // Json manifest file describing meta info of this APEX bundle. Refer to
83 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090084 Manifest *string `android:"path"`
85
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090086 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
87 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090088 AndroidManifest *string `android:"path"`
89
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090090 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
91 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090092 Apex_name *string
93
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090094 // Determines the file contexts file for setting the security contexts to files in this APEX
95 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
96 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090097 File_contexts *string `android:"path"`
98
99 ApexNativeDependencies
100
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900101 Multilib apexMultilibProperties
102
Paul Duffin4b64ba02021-03-29 11:02:53 +0100103 // List of bootclasspath fragments that are embedded inside this APEX bundle.
104 Bootclasspath_fragments []string
105
satayev333a1732021-05-17 21:35:26 +0100106 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
107 Systemserverclasspath_fragments []string
108
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900109 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900110 Java_libs []string
111
Sundong Ahn80c04892021-11-23 00:57:19 +0000112 // List of sh binaries that are embedded inside this APEX bundle.
113 Sh_binaries []string
114
Paul Duffin3abc1742021-03-15 19:32:23 +0000115 // List of platform_compat_config files that are embedded inside this APEX bundle.
116 Compat_configs []string
117
Jiyong Park12a719c2021-01-07 15:31:24 +0900118 // List of filesystem images that are embedded inside this APEX bundle.
119 Filesystems []string
120
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900121 // The minimum SDK version that this APEX must support at minimum. This is usually set to
122 // the SDK version that the APEX was first introduced.
123 Min_sdk_version *string
124
125 // Whether this APEX is considered updatable or not. When set to true, this will enforce
126 // additional rules for making sure that the APEX is truly updatable. To be updatable,
127 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000128 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900129 Updatable *bool
130
Jiyong Parkf4020582021-11-29 12:37:10 +0900131 // Marks that this APEX is designed to be updatable in the future, although it's not
132 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
133 // updatable APEXes. Currently, this disables the size optimization, so that the size of
134 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
135 // false.
136 Future_updatable *bool
137
Jiyong Park1bc84122021-06-22 20:23:05 +0900138 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
139 // false`. Default is false.
140 Platform_apis *bool
141
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900142 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
143 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900144 Installable *bool
145
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000146 // Whether this APEX can be compressed or not. Setting this property to false means this
147 // APEX will never be compressed. When set to true, APEX will be compressed if other
148 // conditions, e.g, target device needs to support APEX compression, are also fulfilled.
149 // Default: true.
150 Compressible *bool
151
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900152 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
153 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
154 Use_vndk_as_stable *bool
155
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000156 // Whether this is multi-installed APEX should skip installing symbol files.
157 // Multi-installed APEXes share the same apex_name and are installed at the same time.
158 // Default is false.
159 //
160 // Should be set to true for all multi-installed APEXes except the singular
161 // default version within the multi-installed group.
162 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
163 // or else conflicting build rules may be created.
164 Multi_install_skip_symbol_files *bool
165
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900166 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
167 // `name#version` or `name` which is an alias for `name#current`. If left empty,
168 // `platform#current` is implied. This value affects all modules included in this APEX. In
169 // other words, they are also built with the SDKs specified here.
170 Uses_sdks []string
171
172 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
173 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
174 // container. When set to zip, contents are stored in a zip container directly. This type is
175 // mostly for host-side debugging. When set to both, the two types are both built. Default
176 // is 'image'.
177 Payload_type *string
178
Huang Jianan13cac632021-08-02 15:02:17 +0800179 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
180 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900181 Payload_fs_type *string
182
183 // For telling the APEX to ignore special handling for system libraries such as bionic.
184 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900185 Ignore_system_library_special_case *bool
186
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100187 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100188 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100189 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900190
191 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
192 // used in tests.
193 Test_only_unsigned_payload *bool
194
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000195 // Whenever apex should be compressed, regardless of product flag used. Should be only
196 // used in tests.
197 Test_only_force_compression *bool
198
Jooyung Han09c11ad2021-10-27 03:45:31 +0900199 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
200 // with the tool to sign payload contents.
201 Custom_sign_tool *string
202
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100203 // Canonical name of this APEX bundle. Used to determine the path to the
204 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
205 // apex mutator variations. For override_apex modules, this is the name of the
206 // overridden base module.
207 ApexVariationName string `blueprint:"mutated"`
208
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900209 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900210
211 // List of sanitizer names that this APEX is enabled for
212 SanitizerNames []string `blueprint:"mutated"`
213
214 PreventInstall bool `blueprint:"mutated"`
215
216 HideFromMake bool `blueprint:"mutated"`
217
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900218 // Internal package method for this APEX. When payload_type is image, this can be either
219 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
220 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900221 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900222}
223
224type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900225 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900226 Native_shared_libs []string
227
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900228 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900229 Jni_libs []string
230
Jiyong Park99644e92020-11-17 22:21:02 +0900231 // List of rust dyn libraries
232 Rust_dyn_libs []string
233
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900234 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900235 Binaries []string
236
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900237 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900238 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900239
240 // List of filesystem images that are embedded inside this APEX bundle.
241 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900242}
243
244type apexMultilibProperties struct {
245 // Native dependencies whose compile_multilib is "first"
246 First ApexNativeDependencies
247
248 // Native dependencies whose compile_multilib is "both"
249 Both ApexNativeDependencies
250
251 // Native dependencies whose compile_multilib is "prefer32"
252 Prefer32 ApexNativeDependencies
253
254 // Native dependencies whose compile_multilib is "32"
255 Lib32 ApexNativeDependencies
256
257 // Native dependencies whose compile_multilib is "64"
258 Lib64 ApexNativeDependencies
259}
260
261type apexTargetBundleProperties struct {
262 Target struct {
263 // Multilib properties only for android.
264 Android struct {
265 Multilib apexMultilibProperties
266 }
267
268 // Multilib properties only for host.
269 Host struct {
270 Multilib apexMultilibProperties
271 }
272
273 // Multilib properties only for host linux_bionic.
274 Linux_bionic struct {
275 Multilib apexMultilibProperties
276 }
277
278 // Multilib properties only for host linux_glibc.
279 Linux_glibc struct {
280 Multilib apexMultilibProperties
281 }
282 }
283}
284
Jiyong Park59140302020-12-14 18:44:04 +0900285type apexArchBundleProperties struct {
286 Arch struct {
287 Arm struct {
288 ApexNativeDependencies
289 }
290 Arm64 struct {
291 ApexNativeDependencies
292 }
293 X86 struct {
294 ApexNativeDependencies
295 }
296 X86_64 struct {
297 ApexNativeDependencies
298 }
299 }
300}
301
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900302// These properties can be used in override_apex to override the corresponding properties in the
303// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900304type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900305 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900306 Apps []string
307
Daniel Norman5a3ce132021-08-26 15:44:43 -0700308 // List of prebuilt files that are embedded inside this APEX bundle.
309 Prebuilts []string
310
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900311 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900312 Rros []string
313
markchien7c803b82021-08-26 22:10:06 +0800314 // List of BPF programs inside this APEX bundle.
315 Bpfs []string
316
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900317 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
318 // Soong). This does not completely prevent installation of the overridden binaries, but if
319 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
320 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900321 Overrides []string
322
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900323 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900324 Logging_parent string
325
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900326 // Apex Container package name. Override value for attribute package:name in
327 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900328 Package_name string
329
330 // A txt file containing list of files that are allowed to be included in this APEX.
331 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700332
333 // Name of the apex_key module that provides the private key to sign this APEX bundle.
334 Key *string
335
336 // Specifies the certificate and the private key to sign the zip container of this APEX. If
337 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
338 // as the certificate and the private key, respectively. If this is ":module", then the
339 // certificate and the private key are provided from the android_app_certificate module
340 // named "module".
341 Certificate *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900342}
343
344type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900345 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900346 android.ModuleBase
347 android.DefaultableModuleBase
348 android.OverridableModuleBase
349 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400350 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900351
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900352 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900353 properties apexBundleProperties
354 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900355 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900357 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900358
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900359 ///////////////////////////////////////////////////////////////////////////////////////////
360 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800363 publicKeyFile android.Path
364 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900365
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900366 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800367 containerCertificateFile android.Path
368 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900369
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900370 // Flags for special variants of APEX
371 testApex bool
372 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900373
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900374 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
375 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900376 primaryApexType bool
377
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900378 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900379 suffix string
380
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900381 // File system type of apex_payload.img
382 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900384 // Whether to create symlink to the system file instead of having a file inside the apex or
385 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900386 linkToSystemLib bool
387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900388 // List of files to be included in this APEX. This is filled in the first part of
389 // GenerateAndroidBuildActions.
390 filesInfo []apexFile
391
392 // List of other module names that should be installed when this APEX gets installed.
393 requiredDeps []string
394
395 ///////////////////////////////////////////////////////////////////////////////////////////
396 // Outputs (final and intermediates)
397
398 // Processed apex manifest in JSONson format (for Q)
399 manifestJsonOut android.WritablePath
400
401 // Processed apex manifest in PB format (for R+)
402 manifestPbOut android.WritablePath
403
404 // Processed file_contexts files
405 fileContexts android.WritablePath
406
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900407 // Struct holding the merged notice file paths in different formats
408 mergedNotices android.NoticeOutputs
409
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900410 // The built APEX file. This is the main product.
411 outputFile android.WritablePath
412
413 // The built APEX file in app bundle format. This file is not directly installed to the
414 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
415 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
416 // system) to be merged into a single app bundle file that Play accepts. See
417 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
418 bundleModuleFile android.WritablePath
419
Colin Cross6340ea52021-11-04 12:01:18 -0700420 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900421 installDir android.InstallPath
422
Colin Cross6340ea52021-11-04 12:01:18 -0700423 // Path where this APEX was installed.
424 installedFile android.InstallPath
425
426 // Installed locations of symlinks for backward compatibility.
427 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900428
429 // Text file having the list of individual files that are included in this APEX. Used for
430 // debugging purpose.
431 installedFilesFile android.WritablePath
432
433 // List of module names that this APEX is including (to be shown via *-deps-info target).
434 // Used for debugging purpose.
435 android.ApexBundleDepsInfo
436
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900437 // Optional list of lint report zip files for apexes that contain java or app modules
438 lintReports android.Paths
439
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900440 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000441
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000442 isCompressed bool
443
sophiezc80a2b32020-11-12 16:39:19 +0000444 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700445 nativeApisUsedByModuleFile android.ModuleOutPath
446 nativeApisBackedByModuleFile android.ModuleOutPath
447 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800448
449 // Collect the module directory for IDE info in java/jdeps.go.
450 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900451}
452
Colin Cross6340ea52021-11-04 12:01:18 -0700453func (*apexBundle) InstallBypassMake() bool {
454 return true
455}
456
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900457// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900458type apexFileClass int
459
Jooyung Han72bd2f82019-10-23 16:46:38 +0900460const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900461 app apexFileClass = iota
462 appSet
463 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900464 goBinary
465 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900466 nativeExecutable
467 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900468 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900469 pyBinary
470 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900471)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900472
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900473// apexFile represents a file in an APEX bundle. This is created during the first half of
474// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
475// of the function, this is used to create commands that copies the files into a staging directory,
476// where they are packaged into the APEX file. This struct is also used for creating Make modules
477// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900478type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900479 // buildFile is put in the installDir inside the APEX.
480 builtFile android.Path
481 noticeFiles android.Paths
482 installDir string
483 customStem string
484 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900485
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900486 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
487 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
488 // suffix>]
489 androidMkModuleName string // becomes LOCAL_MODULE
490 class apexFileClass // becomes LOCAL_MODULE_CLASS
491 moduleDir string // becomes LOCAL_PATH
492 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
493 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
494 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
495 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900496
497 jacocoReportClassesFile android.Path // only for javalibs and apps
498 lintDepSets java.LintDepSets // only for javalibs and apps
499 certificate java.Certificate // only for apps
500 overriddenPackageName string // only for apps
501
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900502 transitiveDep bool
503 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900504
Jiyong Park57621b22021-01-20 20:33:11 +0900505 multilib string
506
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900507 // TODO(jiyong): remove this
508 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900509}
510
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900511// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900512func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
513 ret := apexFile{
514 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900515 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900516 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900517 class: class,
518 module: module,
519 }
520 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900521 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900522 ret.moduleDir = ctx.OtherModuleDir(module)
523 ret.requiredModuleNames = module.RequiredModuleNames()
524 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
525 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900526 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900527 }
528 return ret
529}
530
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900531func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900532 return af.builtFile != nil && af.builtFile.String() != ""
533}
534
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900535// apexRelativePath returns the relative path of the given path from the install directory of this
536// apexFile.
537// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900538func (af *apexFile) apexRelativePath(path string) string {
539 return filepath.Join(af.installDir, path)
540}
541
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900542// path returns path of this apex file relative to the APEX root
543func (af *apexFile) path() string {
544 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900545}
546
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900547// stem returns the base filename of this apex file
548func (af *apexFile) stem() string {
549 if af.customStem != "" {
550 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900551 }
552 return af.builtFile.Base()
553}
554
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900555// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
556func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900557 var ret []string
558 for _, symlink := range af.symlinks {
559 ret = append(ret, af.apexRelativePath(symlink))
560 }
561 return ret
562}
563
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900564// availableToPlatform tests whether this apexFile is from a module that can be installed to the
565// platform.
566func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900567 if af.module == nil {
568 return false
569 }
570 if am, ok := af.module.(android.ApexModule); ok {
571 return am.AvailableFor(android.AvailableToPlatform)
572 }
573 return false
574}
575
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900576////////////////////////////////////////////////////////////////////////////////////////////////////
577// Mutators
578//
579// Brief description about mutators for APEX. The following three mutators are the most important
580// ones.
581//
582// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
583// to the (direct) dependencies of this APEX bundle.
584//
Paul Duffin949abc02020-12-08 10:34:30 +0000585// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900586// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
587// modules are marked as being included in the APEX via BuildForApex().
588//
Paul Duffin949abc02020-12-08 10:34:30 +0000589// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
590// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900591
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900592type dependencyTag struct {
593 blueprint.BaseDependencyTag
594 name string
595
596 // Determines if the dependent will be part of the APEX payload. Can be false for the
597 // dependencies to the signing key module, etc.
598 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000599
600 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
601 // replacement. This is needed because some prebuilt modules do not provide all the information
602 // needed by the apex.
603 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900604}
605
Paul Duffin8c535da2021-03-17 14:51:03 +0000606func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
607 return !d.sourceOnly
608}
609
610var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
611
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900612var (
Paul Duffin0b817782021-03-17 15:02:19 +0000613 androidAppTag = dependencyTag{name: "androidApp", payload: true}
614 bpfTag = dependencyTag{name: "bpf", payload: true}
615 certificateTag = dependencyTag{name: "certificate"}
616 executableTag = dependencyTag{name: "executable", payload: true}
617 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100618 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100619 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000620 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000621 javaLibTag = dependencyTag{name: "javaLib", payload: true}
622 jniLibTag = dependencyTag{name: "jniLib", payload: true}
623 keyTag = dependencyTag{name: "key"}
624 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
625 rroTag = dependencyTag{name: "rro", payload: true}
626 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
627 testForTag = dependencyTag{name: "test for"}
628 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000629 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900630)
631
632// TODO(jiyong): shorten this function signature
633func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900634 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900635 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900636 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900637
638 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900639 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900640 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
641 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900642 }
643
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900644 // Use *FarVariation* to be able to depend on modules having conflicting variations with
645 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
646 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900648 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900649 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
650 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900651 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900652 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900653}
654
655func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900656 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900657 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
658 } else {
659 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
660 if ctx.Os().Bionic() {
661 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
662 } else {
663 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
664 }
665 }
666}
667
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900668// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
669// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
670func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
671 deviceConfig := ctx.DeviceConfig()
672 if a.vndkApex {
673 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900674 }
675
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900676 var prefix string
677 var vndkVersion string
678 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000679 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900680 prefix = cc.VendorVariationPrefix
681 vndkVersion = deviceConfig.VndkVersion()
682 } else if a.ProductSpecific() {
683 prefix = cc.ProductVariationPrefix
684 vndkVersion = deviceConfig.ProductVndkVersion()
685 }
686 }
687 if vndkVersion == "current" {
688 vndkVersion = deviceConfig.PlatformVndkVersion()
689 }
690 if vndkVersion != "" {
691 return prefix + vndkVersion
692 }
693
694 return android.CoreVariation // The usual case
695}
696
697func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900698 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
699 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
700 // each target os/architectures, appropriate dependencies are selected by their
701 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900702 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900703 imageVariation := a.getImageVariation(ctx)
704
705 a.combineProperties(ctx)
706
707 has32BitTarget := false
708 for _, target := range targets {
709 if target.Arch.ArchType.Multilib == "lib32" {
710 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000711 }
712 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900713 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900714 // Don't include artifacts for the host cross targets because there is no way for us
715 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900716 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900717 continue
718 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000719
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900720 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000721
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900722 // Add native modules targeting both ABIs. When multilib.* is omitted for
723 // native_shared_libs/jni_libs/tests, it implies multilib.both
724 depsList = append(depsList, a.properties.Multilib.Both)
725 depsList = append(depsList, ApexNativeDependencies{
726 Native_shared_libs: a.properties.Native_shared_libs,
727 Tests: a.properties.Tests,
728 Jni_libs: a.properties.Jni_libs,
729 Binaries: nil,
730 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900731
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900732 // Add native modules targeting the first ABI When multilib.* is omitted for
733 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900734 isPrimaryAbi := i == 0
735 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900736 depsList = append(depsList, a.properties.Multilib.First)
737 depsList = append(depsList, ApexNativeDependencies{
738 Native_shared_libs: nil,
739 Tests: nil,
740 Jni_libs: nil,
741 Binaries: a.properties.Binaries,
742 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900743 }
744
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900745 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900746 switch target.Arch.ArchType.Multilib {
747 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900748 depsList = append(depsList, a.properties.Multilib.Lib32)
749 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900750 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900751 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900752 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900753 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900754 }
755 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900756
Jiyong Park59140302020-12-14 18:44:04 +0900757 // Add native modules targeting a specific arch variant
758 switch target.Arch.ArchType {
759 case android.Arm:
760 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
761 case android.Arm64:
762 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
763 case android.X86:
764 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
765 case android.X86_64:
766 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
767 default:
768 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
769 }
770
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900771 for _, d := range depsList {
772 addDependenciesForNativeModules(ctx, d, target, imageVariation)
773 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000774 ctx.AddFarVariationDependencies([]blueprint.Variation{
775 {Mutator: "os", Variation: target.OsVariation()},
776 {Mutator: "arch", Variation: target.ArchVariation()},
777 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900778 }
779
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900780 // Common-arch dependencies come next
781 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100782 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100783 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900784 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900785 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000786 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900787
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900788 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
789 // This field currently isn't used.
790 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900791 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
792 if len(a.properties.Uses_sdks) > 0 {
793 sdkRefs := []android.SdkRef{}
794 for _, str := range a.properties.Uses_sdks {
795 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
796 sdkRefs = append(sdkRefs, parsed)
797 }
798 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100799 }
800}
801
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900802// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900803func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
804 if a.overridableProperties.Allowed_files != nil {
805 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100806 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900807
808 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
809 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800810 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900811 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700812 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
813 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
814 // regardless of the TARGET_PREFER_* setting. See b/144532908
815 arches := ctx.DeviceConfig().Arches()
816 if len(arches) != 0 {
817 archForPrebuiltEtc := arches[0]
818 for _, arch := range arches {
819 // Prefer 64-bit arch if there is any
820 if arch.ArchType.Multilib == "lib64" {
821 archForPrebuiltEtc = arch
822 break
823 }
824 }
825 ctx.AddFarVariationDependencies([]blueprint.Variation{
826 {Mutator: "os", Variation: ctx.Os().String()},
827 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
828 }, prebuiltTag, prebuilts...)
829 }
830 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700831
832 // Dependencies for signing
833 if String(a.overridableProperties.Key) == "" {
834 ctx.PropertyErrorf("key", "missing")
835 return
836 }
837 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
838
839 cert := android.SrcIsModule(a.getCertString(ctx))
840 if cert != "" {
841 ctx.AddDependency(ctx.Module(), certificateTag, cert)
842 // empty cert is not an error. Cert and private keys will be directly found under
843 // PRODUCT_DEFAULT_DEV_CERTIFICATE
844 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100845}
846
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900847type ApexBundleInfo struct {
848 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100849}
850
Paul Duffin949abc02020-12-08 10:34:30 +0000851var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900852
Paul Duffina7d6a892020-12-07 17:39:59 +0000853var _ ApexInfoMutator = (*apexBundle)(nil)
854
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100855func (a *apexBundle) ApexVariationName() string {
856 return a.properties.ApexVariationName
857}
858
Paul Duffina7d6a892020-12-07 17:39:59 +0000859// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900860// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
861// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
862// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
863// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000864//
865// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
866// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
867// The apexMutator uses that list to create module variants for the apexes to which it belongs.
868// The relationship between module variants and apexes is not one-to-one as variants will be
869// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000870func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900871
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900872 // The VNDK APEX is special. For the APEX, the membership is described in a very different
873 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
874 // libraries are self-identified by their vndk.enabled properties. There is no need to run
875 // this mutator for the APEX as nothing will be collected. So, let's return fast.
876 if a.vndkApex {
877 return
878 }
879
880 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
881 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
882 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
883 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
884 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900885 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
886 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
887 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
888 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
889 return
890 }
891
Colin Cross56a83212020-09-15 18:30:11 -0700892 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900893 am, ok := child.(android.ApexModule)
894 if !ok || !am.CanHaveApexVariants() {
895 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900896 }
Paul Duffin573989d2021-03-17 13:25:29 +0000897 depTag := mctx.OtherModuleDependencyTag(child)
898
899 // Check to see if the tag always requires that the child module has an apex variant for every
900 // apex variant of the parent module. If it does not then it is still possible for something
901 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
902 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
903 return true
904 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000905 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900906 return false
907 }
Jooyung Handf78e212020-07-22 15:54:47 +0900908 if excludeVndkLibs {
909 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
910 return false
911 }
912 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900913 // By default, all the transitive dependencies are collected, unless filtered out
914 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700915 return true
916 }
917
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900918 // Records whether a certain module is included in this apexBundle via direct dependency or
919 // inndirect dependency.
920 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700921 mctx.WalkDeps(func(child, parent android.Module) bool {
922 if !continueApexDepsWalk(child, parent) {
923 return false
924 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900925 // If the parent is apexBundle, this child is directly depended.
926 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900927 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700928 contents[depName] = contents[depName].Add(directDep)
929 return true
930 })
931
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900932 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900933 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700934 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
935 Contents: apexContents,
936 })
937
Jooyung Haned124c32021-01-26 11:43:46 +0900938 minSdkVersion := a.minSdkVersion(mctx)
939 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
940 if minSdkVersion.IsNone() {
941 minSdkVersion = android.FutureApiLevel
942 }
943
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900944 // This is the main part of this mutator. Mark the collected dependencies that they need to
945 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900946
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100947 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
948 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700949 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100950 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900951 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700952 RequiredSdks: a.RequiredSdks(),
953 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900954 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100955 InApexVariants: []string{apexVariationName},
956 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700957 ApexContents: []*android.ApexContents{apexContents},
958 }
Colin Cross56a83212020-09-15 18:30:11 -0700959 mctx.WalkDeps(func(child, parent android.Module) bool {
960 if !continueApexDepsWalk(child, parent) {
961 return false
962 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900963 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900964 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900965 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900966}
967
Paul Duffina7d6a892020-12-07 17:39:59 +0000968type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100969 // ApexVariationName returns the name of the APEX variation to use in the apex
970 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
971 ApexVariationName() string
972
Paul Duffina7d6a892020-12-07 17:39:59 +0000973 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
974 // depended upon by an apex and which require an apex specific variant.
975 ApexInfoMutator(android.TopDownMutatorContext)
976}
977
978// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
979// specific variant to modules that support the ApexInfoMutator.
980func apexInfoMutator(mctx android.TopDownMutatorContext) {
981 if !mctx.Module().Enabled() {
982 return
983 }
984
985 if a, ok := mctx.Module().(ApexInfoMutator); ok {
986 a.ApexInfoMutator(mctx)
987 return
988 }
989}
990
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900991// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
992// unique apex variations for this module. See android/apex.go for more about unique apex variant.
993// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700994func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
995 if !mctx.Module().Enabled() {
996 return
997 }
998 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700999 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1000 }
1001}
1002
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001003// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1004// the apex in order to retrieve its contents later.
1005// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001006func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1007 if !mctx.Module().Enabled() {
1008 return
1009 }
Colin Cross56a83212020-09-15 18:30:11 -07001010 if am, ok := mctx.Module().(android.ApexModule); ok {
1011 if testFor := am.TestFor(); len(testFor) > 0 {
1012 mctx.AddFarVariationDependencies([]blueprint.Variation{
1013 {Mutator: "os", Variation: am.Target().OsVariation()},
1014 {"arch", "common"},
1015 }, testForTag, testFor...)
1016 }
1017 }
1018}
1019
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001020// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001021func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1022 if !mctx.Module().Enabled() {
1023 return
1024 }
Colin Cross56a83212020-09-15 18:30:11 -07001025 if _, ok := mctx.Module().(android.ApexModule); ok {
1026 var contents []*android.ApexContents
1027 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1028 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1029 contents = append(contents, abInfo.Contents)
1030 }
1031 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1032 ApexContents: contents,
1033 })
Colin Crossaede88c2020-08-11 12:17:01 -07001034 }
1035}
1036
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001037// markPlatformAvailability marks whether or not a module can be available to platform. A module
1038// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1039// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1040// be) available to platform
1041// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001042func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1043 // Host and recovery are not considered as platform
1044 if mctx.Host() || mctx.Module().InstallInRecovery() {
1045 return
1046 }
1047
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001048 am, ok := mctx.Module().(android.ApexModule)
1049 if !ok {
1050 return
1051 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001052
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001053 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001054
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001055 // If any of the dep is not available to platform, this module is also considered as being
1056 // not available to platform even if it has "//apex_available:platform"
1057 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001058 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001059 // if the dependency crosses apex boundary, don't consider it
1060 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001061 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001062 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1063 availableToPlatform = false
1064 // TODO(b/154889534) trigger an error when 'am' has
1065 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001066 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001067 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001068
Paul Duffinb5769c12021-05-12 16:16:51 +01001069 // Exception 1: check to see if the module always requires it.
1070 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001071 availableToPlatform = true
1072 }
1073
1074 // Exception 2: bootstrap bionic libraries are also always available to platform
1075 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1076 availableToPlatform = true
1077 }
1078
1079 if !availableToPlatform {
1080 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001081 }
1082}
1083
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001084// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001085// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001086func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001087 if !mctx.Module().Enabled() {
1088 return
1089 }
Colin Cross56a83212020-09-15 18:30:11 -07001090
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001091 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001092 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001093 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001094 return
1095 }
1096
1097 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001098 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1099 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001100 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001101 if strings.HasPrefix(apexBundleName, "com.android.art") {
1102 // Create an alias from the platform variant. This is done to make
1103 // test_for dependencies work for modules that are split by the APEX
1104 // mutator, since test_for dependencies always go to the platform variant.
1105 // This doesn't happen for normal APEXes that are disjunct, so only do
1106 // this for the overlapping ART APEXes.
1107 // TODO(b/183882457): Remove this if the test_for functionality is
1108 // refactored to depend on the proper APEX variants instead of platform.
1109 mctx.CreateAliasVariation("", apexBundleName)
1110 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001111 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1112 apexBundleName := o.GetOverriddenModuleName()
1113 if apexBundleName == "" {
1114 mctx.ModuleErrorf("base property is not set")
1115 return
1116 }
1117 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001118 if strings.HasPrefix(apexBundleName, "com.android.art") {
1119 // TODO(b/183882457): See note for CreateAliasVariation above.
1120 mctx.CreateAliasVariation("", apexBundleName)
1121 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001122 }
1123}
Sundong Ahne9b55722019-09-06 17:37:42 +09001124
Paul Duffin6717d882021-06-15 19:09:41 +01001125// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1126// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001127func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001128 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001129 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001130 return !a.vndkApex
1131 }
1132
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001133 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001134}
1135
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001136// See android.UpdateDirectlyInAnyApex
1137// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001138func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1139 if !mctx.Module().Enabled() {
1140 return
1141 }
1142 if am, ok := mctx.Module().(android.ApexModule); ok {
1143 android.UpdateDirectlyInAnyApex(mctx, am)
1144 }
1145}
1146
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001147// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001148type apexPackaging int
1149
1150const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001151 // imageApex is a packaging method where contents are included in a filesystem image which
1152 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001153 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001154
1155 // zipApex is a packaging method where contents are directly included in the zip container.
1156 // This is used for host-side testing - because the contents are easily accessible by
1157 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001158 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001159
1160 // flattendApex is a packaging method where contents are not included in the APEX file, but
1161 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1162 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001163 flattenedApex
1164)
1165
1166const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001167 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001168 imageApexSuffix = ".apex"
1169 imageCapexSuffix = ".capex"
1170 zipApexSuffix = ".zipapex"
1171 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001172
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001173 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001174 imageApexType = "image"
1175 zipApexType = "zip"
1176 flattenedApexType = "flattened"
1177
Dan Willemsen47e1a752021-10-16 18:36:13 -07001178 ext4FsType = "ext4"
1179 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001180 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001181)
1182
1183// The suffix for the output "file", not the module
1184func (a apexPackaging) suffix() string {
1185 switch a {
1186 case imageApex:
1187 return imageApexSuffix
1188 case zipApex:
1189 return zipApexSuffix
1190 default:
1191 panic(fmt.Errorf("unknown APEX type %d", a))
1192 }
1193}
1194
1195func (a apexPackaging) name() string {
1196 switch a {
1197 case imageApex:
1198 return imageApexType
1199 case zipApex:
1200 return zipApexType
1201 default:
1202 panic(fmt.Errorf("unknown APEX type %d", a))
1203 }
1204}
1205
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001206// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1207// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001208func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001209 if !mctx.Module().Enabled() {
1210 return
1211 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001212 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001213 var variants []string
1214 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1215 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001216 // This is the normal case. Note that both image and flattend APEXes are
1217 // created. The image type is installed to the system partition, while the
1218 // flattened APEX is (optionally) installed to the system_ext partition.
1219 // This is mostly for GSI which has to support wide range of devices. If GSI
1220 // is installed on a newer (APEX-capable) device, the image APEX in the
1221 // system will be used. However, if the same GSI is installed on an old
1222 // device which can't support image APEX, the flattened APEX in the
1223 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001224 variants = append(variants, imageApexType, flattenedApexType)
1225 case "zip":
1226 variants = append(variants, zipApexType)
1227 case "both":
1228 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1229 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001230 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001231 return
1232 }
1233
1234 modules := mctx.CreateLocalVariations(variants...)
1235
1236 for i, v := range variants {
1237 switch v {
1238 case imageApexType:
1239 modules[i].(*apexBundle).properties.ApexType = imageApex
1240 case zipApexType:
1241 modules[i].(*apexBundle).properties.ApexType = zipApex
1242 case flattenedApexType:
1243 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001244 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001245 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001246 modules[i].(*apexBundle).MakeAsSystemExt()
1247 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001248 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001249 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001250 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001251 // payload_type is forcibly overridden to "image"
1252 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001253 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001254 }
1255}
1256
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001257var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001258
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001259// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001260func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1261 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001262 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001263 return true
1264}
1265
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001266var _ android.OutputFileProducer = (*apexBundle)(nil)
1267
1268// Implements android.OutputFileProducer
1269func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1270 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001271 case "", android.DefaultDistTag:
1272 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001273 return android.Paths{a.outputFile}, nil
1274 default:
1275 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1276 }
1277}
1278
1279var _ cc.Coverage = (*apexBundle)(nil)
1280
1281// Implements cc.Coverage
1282func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1283 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1284}
1285
1286// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001287func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001288 a.properties.PreventInstall = true
1289}
1290
1291// Implements cc.Coverage
1292func (a *apexBundle) HideFromMake() {
1293 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001294 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1295 // TODO(ccross): untangle these
1296 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001297}
1298
1299// Implements cc.Coverage
1300func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1301 a.properties.IsCoverageVariant = coverage
1302}
1303
1304// Implements cc.Coverage
1305func (a *apexBundle) EnableCoverageIfNeeded() {}
1306
1307var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1308
1309// Implements android.ApexBudleDepsInfoIntf
1310func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001311 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001312}
1313
Jiyong Parkf4020582021-11-29 12:37:10 +09001314func (a *apexBundle) FutureUpdatable() bool {
1315 return proptools.BoolDefault(a.properties.Future_updatable, false)
1316}
1317
Jiyong Park1bc84122021-06-22 20:23:05 +09001318func (a *apexBundle) UsePlatformApis() bool {
1319 return proptools.BoolDefault(a.properties.Platform_apis, false)
1320}
1321
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001322// getCertString returns the name of the cert that should be used to sign this APEX. This is
1323// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001324func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001325 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001326 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1327 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1328 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001329 if a.vndkApex {
1330 moduleName = vndkApexName
1331 }
1332 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001333 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001334 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001335 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001336 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001337}
1338
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001339// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001340func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001341 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001342}
1343
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001344// See the generate_hashtree property
1345func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001346 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001347}
1348
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001349// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001350func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1351 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1352}
1353
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001354// See the test_only_force_compression property
1355func (a *apexBundle) testOnlyShouldForceCompression() bool {
1356 return proptools.Bool(a.properties.Test_only_force_compression)
1357}
1358
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001359// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1360// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1361// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001362
Jiyong Parkf97782b2019-02-13 20:28:58 +09001363func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1364 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1365 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1366 }
1367}
1368
Jiyong Park388ef3f2019-01-28 19:47:32 +09001369func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001370 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1371 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001372 }
1373
1374 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001375 globalSanitizerNames := []string{}
1376 if a.Host() {
1377 globalSanitizerNames = ctx.Config().SanitizeHost()
1378 } else {
1379 arches := ctx.Config().SanitizeDeviceArch()
1380 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1381 globalSanitizerNames = ctx.Config().SanitizeDevice()
1382 }
1383 }
1384 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001385}
1386
Jooyung Han8ce8db92020-05-15 19:05:05 +09001387func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001388 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1389 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001390 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001391 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001392 for _, target := range ctx.MultiTargets() {
1393 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001394 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1395 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1396 Tests: nil,
1397 Jni_libs: nil,
1398 Binaries: nil,
1399 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001400 break
1401 }
1402 }
1403 }
1404}
1405
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001406// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1407// returned apexFile saves information about the Soong module that will be used for creating the
1408// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001409func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001410 // Decide the APEX-local directory by the multilib of the library In the future, we may
1411 // query this to the module.
1412 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001413 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001414 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001415 case "lib32":
1416 dirInApex = "lib"
1417 case "lib64":
1418 dirInApex = "lib64"
1419 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001420 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001421 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001422 }
Jooyung Han35155c42020-02-06 17:33:20 +09001423 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001424 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001425 // Special case for Bionic libs and other libs installed with them. This is to
1426 // prevent those libs from being included in the search path
1427 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1428 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1429 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1430 // will be loaded into the default linker namespace (aka "platform" namespace). If
1431 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1432 // be loaded again into the runtime linker namespace, which will result in double
1433 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001434 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001435 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001436
Jiyong Parkf653b052019-11-18 15:39:01 +09001437 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001438 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1439 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001440}
1441
Jiyong Park1833cef2019-12-13 13:28:36 +09001442func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001443 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001444 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001445 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001446 }
Jooyung Han35155c42020-02-06 17:33:20 +09001447 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001448 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001449 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1450 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001451 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001452 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001453 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001454}
1455
Jiyong Park99644e92020-11-17 22:21:02 +09001456func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1457 dirInApex := "bin"
1458 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1459 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1460 }
1461 fileToCopy := rustm.OutputFile().Path()
1462 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1463 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1464 return af
1465}
1466
1467func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1468 // Decide the APEX-local directory by the multilib of the library
1469 // In the future, we may query this to the module.
1470 var dirInApex string
1471 switch rustm.Arch().ArchType.Multilib {
1472 case "lib32":
1473 dirInApex = "lib"
1474 case "lib64":
1475 dirInApex = "lib64"
1476 }
1477 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1478 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1479 }
1480 fileToCopy := rustm.OutputFile().Path()
1481 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1482 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1483}
1484
Jiyong Park1833cef2019-12-13 13:28:36 +09001485func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001486 dirInApex := "bin"
1487 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001488 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001489}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001490
Jiyong Park1833cef2019-12-13 13:28:36 +09001491func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001492 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001493 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001494 // NB: Since go binaries are static we don't need the module for anything here, which is
1495 // good since the go tool is a blueprint.Module not an android.Module like we would
1496 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001497 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001498}
1499
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001500func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001501 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001502 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1503 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1504 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001505 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001506 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001507 af.symlinks = sh.Symlinks()
1508 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001509}
1510
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001511func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001512 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001513 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001514 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001515}
1516
atrost6e126252020-01-27 17:01:16 +00001517func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1518 dirInApex := filepath.Join("etc", config.SubDir())
1519 fileToCopy := config.CompatConfig()
1520 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1521}
1522
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001523// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1524// way.
1525type javaModule interface {
1526 android.Module
1527 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001528 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001529 JacocoReportClassesFile() android.Path
1530 LintDepSets() java.LintDepSets
1531 Stem() string
1532}
1533
1534var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001535var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001536var _ javaModule = (*java.SdkLibrary)(nil)
1537var _ javaModule = (*java.DexImport)(nil)
1538var _ javaModule = (*java.SdkLibraryImport)(nil)
1539
Paul Duffin190fdef2021-04-26 10:33:59 +01001540// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001541func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001542 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001543}
1544
1545// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1546func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001547 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001548 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001549 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1550 af.lintDepSets = module.LintDepSets()
1551 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001552 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1553 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1554 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1555 }
1556 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001557 return af
1558}
1559
1560// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1561// the same way.
1562type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001563 android.Module
1564 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001565 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001566 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001567 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001568 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001569 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001570 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001571}
1572
1573var _ androidApp = (*java.AndroidApp)(nil)
1574var _ androidApp = (*java.AndroidAppImport)(nil)
1575
1576func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001577 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001578 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001579 appDir = "priv-app"
1580 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001581 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001582 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001583 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001584 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001585 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001586 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001587
1588 if app, ok := aapp.(interface {
1589 OverriddenManifestPackageName() string
1590 }); ok {
1591 af.overriddenPackageName = app.OverriddenManifestPackageName()
1592 }
Jiyong Park618922e2020-01-08 13:35:43 +09001593 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001594}
1595
Jiyong Park69aeba92020-04-24 21:16:36 +09001596func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1597 rroDir := "overlay"
1598 dirInApex := filepath.Join(rroDir, rro.Theme())
1599 fileToCopy := rro.OutputFile()
1600 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1601 af.certificate = rro.Certificate()
1602
1603 if a, ok := rro.(interface {
1604 OverriddenManifestPackageName() string
1605 }); ok {
1606 af.overriddenPackageName = a.OverriddenManifestPackageName()
1607 }
1608 return af
1609}
1610
markchien2f59ec92020-09-02 16:23:38 +08001611func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1612 dirInApex := filepath.Join("etc", "bpf")
1613 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1614}
1615
Jiyong Park12a719c2021-01-07 15:31:24 +09001616func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1617 dirInApex := filepath.Join("etc", "fs")
1618 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1619}
1620
Paul Duffin064b70c2020-11-02 17:32:38 +00001621// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001622// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1623// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1624// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001625func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001626 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001627 am, ok := child.(android.ApexModule)
1628 if !ok || !am.CanHaveApexVariants() {
1629 return false
1630 }
1631
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632 // Filter-out unwanted depedendencies
1633 depTag := ctx.OtherModuleDependencyTag(child)
1634 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1635 return false
1636 }
1637 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001638 return false
1639 }
1640
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001641 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001642 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001643
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001644 // Visit actually
1645 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001646 })
1647}
1648
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001649// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1650type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001651
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001652const (
1653 ext4 fsType = iota
1654 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001655 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001656)
Artur Satayev849f8442020-04-28 14:57:42 +01001657
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001658func (f fsType) string() string {
1659 switch f {
1660 case ext4:
1661 return ext4FsType
1662 case f2fs:
1663 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001664 case erofs:
1665 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001666 default:
1667 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001668 }
1669}
1670
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001671// Creates build rules for an APEX. It consists of the following major steps:
1672//
1673// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1674// 2) traverse the dependency tree to collect apexFile structs from them.
1675// 3) some fields in apexBundle struct are configured
1676// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001677func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001678 ////////////////////////////////////////////////////////////////////////////////////////////
1679 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001680 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001681 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001682 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001683 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001684 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001685 if len(a.properties.Tests) > 0 && !a.testApex {
1686 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1687 return
1688 }
Jiyong Park678c8812020-02-07 17:25:49 +09001689
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001690 ////////////////////////////////////////////////////////////////////////////////////////////
1691 // 2) traverse the dependency tree to collect apexFile structs from them.
1692
1693 // all the files that will be included in this APEX
1694 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001695
Jooyung Hane1633032019-08-01 17:41:43 +09001696 // native lib dependencies
1697 var provideNativeLibs []string
1698 var requireNativeLibs []string
1699
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001700 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1701
braleeb0c1f0c2021-06-07 22:49:13 +08001702 // Collect the module directory for IDE info in java/jdeps.go.
1703 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1704
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001705 // TODO(jiyong): do this using WalkPayloadDeps
1706 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001707 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001708 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001709 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1710 return false
1711 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001712 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1713 return false
1714 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001715 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001717 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001718 case sharedLibTag, jniLibTag:
1719 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001720 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001721 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1722 fi.isJniLib = isJniLib
1723 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001724 // Collect the list of stub-providing libs except:
1725 // - VNDK libs are only for vendors
1726 // - bootstrap bionic libs are treated as provided by system
1727 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001728 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001729 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001730 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001731 } else if r, ok := child.(*rust.Module); ok {
1732 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001733 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001734 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001735 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001736 propertyName := "native_shared_libs"
1737 if isJniLib {
1738 propertyName = "jni_libs"
1739 }
1740 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001741 }
1742 case executableTag:
1743 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001744 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001745 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001746 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001747 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001748 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001749 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001750 } else if rust, ok := child.(*rust.Module); ok {
1751 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1752 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001753 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001754 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1755 }
1756 case shBinaryTag:
1757 if sh, ok := child.(*sh.ShBinary); ok {
1758 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1759 } else {
1760 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001761 }
Paul Duffin94f19632021-04-20 12:40:07 +01001762 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001763 {
Paul Duffin7771eba2021-04-23 14:25:28 +01001764 if _, ok := child.(*java.BootclasspathFragmentModule); !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001765 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001766 return false
1767 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001768
Paul Duffincc33ec82021-04-25 23:14:55 +01001769 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1770 filesInfo = append(filesInfo, filesToAdd...)
Paul Duffin4d101b62021-03-24 15:42:20 +00001771 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001772 }
satayev333a1732021-05-17 21:35:26 +01001773 case sscpfTag:
1774 {
1775 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1776 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1777 return false
1778 }
satayevb98371c2021-06-15 16:49:50 +01001779 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1780 filesInfo = append(filesInfo, *af)
1781 }
satayev333a1732021-05-17 21:35:26 +01001782 return true
1783 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001784 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001785 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001786 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001787 af := apexFileForJavaModule(ctx, child.(javaModule))
1788 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001789 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1790 return false
1791 }
1792 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001793 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001794 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001795 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001796 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001797 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001798 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001799 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001800 return true // track transitive dependencies
1801 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001802 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001803 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001804 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001805 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1806 appDir := "app"
1807 if ap.Privileged() {
1808 appDir = "priv-app"
1809 }
Yo Chiange8128052020-07-23 20:09:18 +08001810 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001811 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1812 af.certificate = java.PresignedCertificate
1813 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001814 } else {
1815 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1816 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001817 case rroTag:
1818 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1819 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1820 } else {
1821 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1822 }
markchien2f59ec92020-09-02 16:23:38 +08001823 case bpfTag:
1824 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1825 filesToCopy, _ := bpfProgram.OutputFiles("")
1826 for _, bpfFile := range filesToCopy {
1827 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1828 }
1829 } else {
1830 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1831 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001832 case fsTag:
1833 if fs, ok := child.(filesystem.Filesystem); ok {
1834 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1835 } else {
1836 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1837 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001838 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001839 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001840 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001841 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001842 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001843 }
Paul Duffin0b817782021-03-17 15:02:19 +00001844 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001845 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1846 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1847 } else {
1848 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1849 }
Roland Levillain630846d2019-06-26 12:48:34 +01001850 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001851 if ccTest, ok := child.(*cc.Module); ok {
1852 if ccTest.IsTestPerSrcAllTestsVariation() {
1853 // Multiple-output test module (where `test_per_src: true`).
1854 //
1855 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1856 // We do not add this variation to `filesInfo`, as it has no output;
1857 // however, we do add the other variations of this module as indirect
1858 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001859 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001860 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001861 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001862 af.class = nativeTest
1863 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001864 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001865 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001866 } else {
1867 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1868 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001869 case keyTag:
1870 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001871 a.privateKeyFile = key.privateKeyFile
1872 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001873 } else {
1874 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001875 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001876 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001877 case certificateTag:
1878 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001879 a.containerCertificateFile = dep.Certificate.Pem
1880 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001881 } else {
1882 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1883 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001884 case android.PrebuiltDepTag:
1885 // If the prebuilt is force disabled, remember to delete the prebuilt file
1886 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001887 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001888 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1889 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001890 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001891 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001892 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001893 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001894 // We cannot use a switch statement on `depTag` here as the checked
1895 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001896 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001897 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001898 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001899 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001900 return false
1901 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001902 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1903 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001904
1905 // Always track transitive dependencies for host.
1906 if a.Host() {
1907 filesInfo = append(filesInfo, af)
1908 return true
1909 }
1910
Colin Cross56a83212020-09-15 18:30:11 -07001911 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001912 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001913 // If the dependency is a stubs lib, don't include it in this APEX,
1914 // but make sure that the lib is installed on the device.
1915 // In case no APEX is having the lib, the lib is installed to the system
1916 // partition.
1917 //
1918 // Always include if we are a host-apex however since those won't have any
1919 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001920 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001921 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001922 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001923 if !android.InList(name, a.requiredDeps) {
1924 a.requiredDeps = append(a.requiredDeps, name)
1925 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001926 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001927 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001928 // Don't track further
1929 return false
1930 }
Jiyong Parke3867542020-12-03 17:28:25 +09001931
1932 // If the dep is not considered to be in the same
1933 // apex, don't add it to filesInfo so that it is not
1934 // included in this APEX.
1935 // TODO(jiyong): move this to at the top of the
1936 // else-if clause for the indirect dependencies.
1937 // Currently, that's impossible because we would
1938 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001939 // DepIsInSameAPex is false. We also shouldn't do
1940 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001941 //
1942 // TODO(jiyong): explain why the same module is passed in twice.
1943 // Switching the first am to parent breaks lots of tests.
1944 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001945 return false
1946 }
1947
Jiyong Parkf653b052019-11-18 15:39:01 +09001948 filesInfo = append(filesInfo, af)
1949 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001950 } else if rm, ok := child.(*rust.Module); ok {
1951 af := apexFileForRustLibrary(ctx, rm)
1952 af.transitiveDep = true
1953 filesInfo = append(filesInfo, af)
1954 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001955 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001956 } else if cc.IsTestPerSrcDepTag(depTag) {
1957 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001958 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001959 // Handle modules created as `test_per_src` variations of a single test module:
1960 // use the name of the generated test binary (`fileToCopy`) instead of the name
1961 // of the original test module (`depName`, shared by all `test_per_src`
1962 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001963 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001964 // these are not considered transitive dep
1965 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001966 filesInfo = append(filesInfo, af)
1967 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001968 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001969 } else if cc.IsHeaderDepTag(depTag) {
1970 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001971 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001972 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1973 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001974 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001975 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001976 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1977 }
Jiyong Park99644e92020-11-17 22:21:02 +09001978 } else if rust.IsDylibDepTag(depTag) {
1979 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1980 af := apexFileForRustLibrary(ctx, rustm)
1981 af.transitiveDep = true
1982 filesInfo = append(filesInfo, af)
1983 return true // track transitive dependencies
1984 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09001985 } else if rust.IsRlibDepTag(depTag) {
1986 // Rlib is statically linked, but it might have shared lib
1987 // dependencies. Track them.
1988 return true
Paul Duffin65898052021-04-20 22:47:03 +01001989 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01001990 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00001991 switch child.(type) {
1992 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01001993 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01001994 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00001995 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01001996 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00001997 return false
1998 }
1999 filesInfo = append(filesInfo, af)
2000 return true // track transitive dependencies
2001 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002002 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 +00002003 }
satayev333a1732021-05-17 21:35:26 +01002004 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2005 // Add the contents of the systemserverclasspath fragment to the apex.
2006 switch child.(type) {
2007 case *java.Library, *java.SdkLibrary:
2008 af := apexFileForJavaModule(ctx, child.(javaModule))
2009 filesInfo = append(filesInfo, af)
2010 return true // track transitive dependencies
2011 default:
2012 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2013 }
Colin Cross56a83212020-09-15 18:30:11 -07002014 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2015 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002016 } else if depTag == android.DarwinUniversalVariantTag {
2017 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002018 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002019 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002020 }
2021 }
2022 }
2023 return false
2024 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002025 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002026 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002027 return
2028 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002029
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002030 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002031 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002032 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002033 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002034 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002035 if e, ok := encountered[dest]; !ok {
2036 encountered[dest] = f
2037 } else {
2038 // If a module is directly included and also transitively depended on
2039 // consider it as directly included.
2040 e.transitiveDep = e.transitiveDep && f.transitiveDep
2041 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002042 }
2043 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002044 var result []apexFile
2045 for _, v := range encountered {
2046 result = append(result, v)
2047 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002048 return result
2049 }
2050 filesInfo = removeDup(filesInfo)
2051
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002052 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002053 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002054 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2055 // changes.
2056 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002057 })
2058
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002059 ////////////////////////////////////////////////////////////////////////////////////////////
2060 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002061 a.installDir = android.PathForModuleInstall(ctx, "apex")
2062 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002063
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002064 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002065 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002066 switch a.properties.ApexType {
2067 case imageApex:
2068 if buildFlattenedAsDefault {
2069 a.suffix = imageApexSuffix
2070 } else {
2071 a.suffix = ""
2072 a.primaryApexType = true
2073
2074 if ctx.Config().InstallExtraFlattenedApexes() {
2075 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2076 }
2077 }
2078 case zipApex:
2079 if proptools.String(a.properties.Payload_type) == "zip" {
2080 a.suffix = ""
2081 a.primaryApexType = true
2082 } else {
2083 a.suffix = zipApexSuffix
2084 }
2085 case flattenedApex:
2086 if buildFlattenedAsDefault {
2087 a.suffix = ""
2088 a.primaryApexType = true
2089 } else {
2090 a.suffix = flattenedSuffix
2091 }
2092 }
2093
Theotime Combes4ba38c12020-06-12 12:46:59 +00002094 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2095 case ext4FsType:
2096 a.payloadFsType = ext4
2097 case f2fsFsType:
2098 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002099 case erofsFsType:
2100 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002101 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002102 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 +00002103 }
2104
Jiyong Park7cd10e32020-01-14 09:22:18 +09002105 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2106 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2107 // the same library in the system partition, thus effectively sharing the same libraries
2108 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2109 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002110 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002111
Jooyung Han85d61762020-06-24 23:50:26 +09002112 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2113 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002114 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002115 a.linkToSystemLib = false
2116 }
2117
Jiyong Park4da07972021-01-05 21:01:11 +09002118 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002119 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002120
Jiyong Park9d677202020-02-19 16:29:35 +09002121 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002122 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002123 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002124 a.linkToSystemLib = false
2125 }
2126
Jiyong Park638d30e2020-02-26 18:27:19 +09002127 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2128 if ctx.Host() {
2129 a.linkToSystemLib = false
2130 }
2131
Colin Cross6340ea52021-11-04 12:01:18 -07002132 if a.properties.ApexType != zipApex {
2133 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2134 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002135
2136 ////////////////////////////////////////////////////////////////////////////////////////////
2137 // 4) generate the build rules to create the APEX. This is done in builder.go.
2138 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002139 if a.properties.ApexType == flattenedApex {
2140 a.buildFlattenedApex(ctx)
2141 } else {
2142 a.buildUnflattenedApex(ctx)
2143 }
Jiyong Park956305c2020-01-09 12:32:06 +09002144 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002145 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002146
2147 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2148 if a.installable() {
2149 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2150 // along with other ordinary files. (Note that this is done by apexer for
2151 // non-flattened APEXes)
2152 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2153
2154 // Place the public key as apex_pubkey. This is also done by apexer for
2155 // non-flattened APEXes case.
2156 // TODO(jiyong): Why do we need this CP rule?
2157 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2158 ctx.Build(pctx, android.BuildParams{
2159 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002160 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002161 Output: copiedPubkey,
2162 })
2163 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2164 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002165}
2166
Paul Duffincc33ec82021-04-25 23:14:55 +01002167// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2168// the bootclasspath_fragment contributes to the apex.
2169func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2170 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2171 var filesToAdd []apexFile
2172
2173 // Add the boot image files, e.g. .art, .oat and .vdex files.
2174 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2175 dirInApex := filepath.Join("javalib", arch.String())
2176 for _, f := range files {
2177 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2178 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2179 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2180 filesToAdd = append(filesToAdd, af)
2181 }
2182 }
2183
satayev3db35472021-05-06 23:59:58 +01002184 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002185 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2186 filesToAdd = append(filesToAdd, *af)
2187 }
satayev3db35472021-05-06 23:59:58 +01002188
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002189 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2190 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2191 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2192
2193 if pathOnHost != nil {
2194 // We need to copy the profile to a temporary path with the right filename because the apexer
2195 // will take the filename as is.
2196 ctx.Build(pctx, android.BuildParams{
2197 Rule: android.Cp,
2198 Input: pathOnHost,
2199 Output: tempPath,
2200 })
2201 } else {
2202 // At this point, the boot image profile cannot be generated. It is probably because the boot
2203 // image profile source file does not exist on the branch, or it is not available for the
2204 // current build target.
2205 // However, we cannot enforce the boot image profile to be generated because some build
2206 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2207 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2208 // only if the APEX is being built.
2209 ctx.Build(pctx, android.BuildParams{
2210 Rule: android.ErrorRule,
2211 Output: tempPath,
2212 Args: map[string]string{
2213 "error": "Boot image profile cannot be generated",
2214 },
2215 })
2216 }
2217
2218 androidMkModuleName := filepath.Base(pathInApex)
2219 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2220 filesToAdd = append(filesToAdd, af)
2221 }
2222
Paul Duffincc33ec82021-04-25 23:14:55 +01002223 return filesToAdd
2224}
2225
satayevb98371c2021-06-15 16:49:50 +01002226// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2227// the module contributes to the apex; or nil if the proto config was not generated.
2228func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2229 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2230 if !info.ClasspathFragmentProtoGenerated {
2231 return nil
2232 }
2233 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2234 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2235 return &af
satayev14e49132021-05-17 21:03:07 +01002236}
2237
Paul Duffincc33ec82021-04-25 23:14:55 +01002238// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2239// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002240func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2241 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2242
2243 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2244 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002245 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2246 if err != nil {
2247 ctx.ModuleErrorf("%s", err)
2248 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002249
2250 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2251 // bootclasspath_fragment.
2252 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2253 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002254}
2255
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002256///////////////////////////////////////////////////////////////////////////////////////////////////
2257// Factory functions
2258//
2259
2260func newApexBundle() *apexBundle {
2261 module := &apexBundle{}
2262
2263 module.AddProperties(&module.properties)
2264 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002265 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002266 module.AddProperties(&module.overridableProperties)
2267
2268 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2269 android.InitDefaultableModule(module)
2270 android.InitSdkAwareModule(module)
2271 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002272 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002273 return module
2274}
2275
Paul Duffineb8051d2021-10-18 17:49:39 +01002276func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002277 bundle := newApexBundle()
2278 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002279 return bundle
2280}
2281
2282// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2283// certain compatibility checks such as apex_available are not done for apex_test.
2284func testApexBundleFactory() android.Module {
2285 bundle := newApexBundle()
2286 bundle.testApex = true
2287 return bundle
2288}
2289
2290// apex packages other modules into an APEX file which is a packaging format for system-level
2291// components like binaries, shared libraries, etc.
2292func BundleFactory() android.Module {
2293 return newApexBundle()
2294}
2295
2296type Defaults struct {
2297 android.ModuleBase
2298 android.DefaultsModuleBase
2299}
2300
2301// apex_defaults provides defaultable properties to other apex modules.
2302func defaultsFactory() android.Module {
2303 return DefaultsFactory()
2304}
2305
2306func DefaultsFactory(props ...interface{}) android.Module {
2307 module := &Defaults{}
2308
2309 module.AddProperties(props...)
2310 module.AddProperties(
2311 &apexBundleProperties{},
2312 &apexTargetBundleProperties{},
2313 &overridableProperties{},
2314 )
2315
2316 android.InitDefaultsModule(module)
2317 return module
2318}
2319
2320type OverrideApex struct {
2321 android.ModuleBase
2322 android.OverrideModuleBase
2323}
2324
2325func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2326 // All the overrides happen in the base module.
2327}
2328
2329// override_apex is used to create an apex module based on another apex module by overriding some of
2330// its properties.
2331func overrideApexFactory() android.Module {
2332 m := &OverrideApex{}
2333
2334 m.AddProperties(&overridableProperties{})
2335
2336 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2337 android.InitOverrideModule(m)
2338 return m
2339}
2340
2341///////////////////////////////////////////////////////////////////////////////////////////////////
2342// Vality check routines
2343//
2344// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2345// certain conditions are not met.
2346//
2347// TODO(jiyong): move these checks to a separate go file.
2348
satayevad991492021-12-03 18:58:32 +00002349var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2350
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002351// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2352// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002353func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002354 if a.testApex || a.vndkApex {
2355 return
2356 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002357 // apexBundle::minSdkVersion reports its own errors.
2358 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002359 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002360}
2361
satayevad991492021-12-03 18:58:32 +00002362func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2363 return android.SdkSpec{
2364 Kind: android.SdkNone,
2365 ApiLevel: a.minSdkVersion(ctx),
2366 Raw: String(a.properties.Min_sdk_version),
2367 }
2368}
2369
2370func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002371 ver := proptools.String(a.properties.Min_sdk_version)
2372 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002373 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002374 }
2375 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2376 if err != nil {
2377 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2378 return android.NoneApiLevel
2379 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002380 return apiLevel
2381}
2382
2383// Ensures that a lib providing stub isn't statically linked
2384func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2385 // Practically, we only care about regular APEXes on the device.
2386 if ctx.Host() || a.testApex || a.vndkApex {
2387 return
2388 }
2389
2390 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2391
2392 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2393 if ccm, ok := to.(*cc.Module); ok {
2394 apexName := ctx.ModuleName()
2395 fromName := ctx.OtherModuleName(from)
2396 toName := ctx.OtherModuleName(to)
2397
2398 // If `to` is not actually in the same APEX as `from` then it does not need
2399 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002400 //
2401 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002402 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2403 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2404 return false
2405 }
2406
2407 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2408 // exception to this rule. It can't make the static dependencies dynamic
2409 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002410 // Same rule should be applied to linkerconfig, because it should be executed
2411 // only with static linked libraries before linker is available with ld.config.txt
2412 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002413 return false
2414 }
2415
2416 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2417 if isStubLibraryFromOtherApex && !externalDep {
2418 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2419 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2420 }
2421
2422 }
2423 return true
2424 })
2425}
2426
satayevb98371c2021-06-15 16:49:50 +01002427// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002428func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2429 if a.Updatable() {
2430 if String(a.properties.Min_sdk_version) == "" {
2431 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2432 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002433 if a.UsePlatformApis() {
2434 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2435 }
Daniel Norman69109112021-12-02 12:52:42 -08002436 if a.SocSpecific() || a.DeviceSpecific() {
2437 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2438 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002439 if a.FutureUpdatable() {
2440 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2441 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002442 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002443 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002444 }
2445}
2446
satayevb98371c2021-06-15 16:49:50 +01002447// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2448func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2449 ctx.VisitDirectDeps(func(module android.Module) {
2450 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2451 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2452 if !info.ClasspathFragmentProtoGenerated {
2453 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2454 }
2455 }
2456 })
2457}
2458
2459// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002460func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002461 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2462 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002463 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2464 tag := ctx.OtherModuleDependencyTag(module)
2465 switch tag {
2466 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002467 if m, ok := module.(interface {
2468 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2469 }); ok {
2470 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002471 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2472 }
2473 }
2474 }
2475 })
2476}
2477
satayevb98371c2021-06-15 16:49:50 +01002478// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002479func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2480 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2481 if ctx.Host() || a.testApex || a.vndkApex {
2482 return
2483 }
2484
2485 // Because APEXes targeting other than system/system_ext partitions can't set
2486 // apex_available, we skip checks for these APEXes
2487 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2488 return
2489 }
2490
2491 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2492 // Requiring them and their transitive depencies with apex_available is not right
2493 // because they just add noise.
2494 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2495 return
2496 }
2497
2498 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2499 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2500 if externalDep {
2501 return false
2502 }
2503
2504 apexName := ctx.ModuleName()
2505 fromName := ctx.OtherModuleName(from)
2506 toName := ctx.OtherModuleName(to)
2507
2508 // If `to` is not actually in the same APEX as `from` then it does not need
2509 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002510 //
2511 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002512 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2513 // As soon as the dependency graph crosses the APEX boundary, don't go
2514 // further.
2515 return false
2516 }
2517
2518 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2519 return true
2520 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002521 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2522 "\n\nDependency path:%s\n\n"+
2523 "Consider adding %q to 'apex_available' property of %q",
2524 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002525 // Visit this module's dependencies to check and report any issues with their availability.
2526 return true
2527 })
2528}
2529
Jiyong Park192600a2021-08-03 07:52:17 +00002530// checkStaticExecutable ensures that executables in an APEX are not static.
2531func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002532 // No need to run this for host APEXes
2533 if ctx.Host() {
2534 return
2535 }
2536
Jiyong Park192600a2021-08-03 07:52:17 +00002537 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2538 if ctx.OtherModuleDependencyTag(module) != executableTag {
2539 return
2540 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002541
2542 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002543 apex := a.ApexVariationName()
2544 exec := ctx.OtherModuleName(module)
2545 if isStaticExecutableAllowed(apex, exec) {
2546 return
2547 }
2548 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2549 }
2550 })
2551}
2552
2553// A small list of exceptions where static executables are allowed in APEXes.
2554func isStaticExecutableAllowed(apex string, exec string) bool {
2555 m := map[string][]string{
2556 "com.android.runtime": []string{
2557 "linker",
2558 "linkerconfig",
2559 },
2560 }
2561 execNames, ok := m[apex]
2562 return ok && android.InList(exec, execNames)
2563}
2564
braleeb0c1f0c2021-06-07 22:49:13 +08002565// Collect information for opening IDE project files in java/jdeps.go.
2566func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2567 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2568 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2569 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2570 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2571}
2572
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002573var (
2574 apexAvailBaseline = makeApexAvailableBaseline()
2575 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2576)
2577
Colin Cross440e0d02020-06-11 11:32:11 -07002578func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002579 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002580 moduleName = normalizeModuleName(moduleName)
2581
Colin Cross440e0d02020-06-11 11:32:11 -07002582 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002583 return true
2584 }
2585
2586 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002587 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002588 return true
2589 }
2590
2591 return false
2592}
2593
2594func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002595 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2596 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002597 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002598 if strings.HasPrefix(moduleName, "libclang_rt.") {
2599 // This module has many arch variants that depend on the product being built.
2600 // We don't want to list them all
2601 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002602 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002603 if strings.HasPrefix(moduleName, "androidx.") {
2604 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2605 moduleName = "androidx"
2606 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002607 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002608}
2609
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002610// Transform the map of apex -> modules to module -> apexes.
2611func invertApexBaseline(m map[string][]string) map[string][]string {
2612 r := make(map[string][]string)
2613 for apex, modules := range m {
2614 for _, module := range modules {
2615 r[module] = append(r[module], apex)
2616 }
2617 }
2618 return r
2619}
2620
2621// Retrieve the baseline of apexes to which the supplied module belongs.
2622func BaselineApexAvailable(moduleName string) []string {
2623 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2624}
2625
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002626// This is a map from apex to modules, which overrides the apex_available setting for that
2627// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002628// TODO(b/147364041): remove this
2629func makeApexAvailableBaseline() map[string][]string {
2630 // The "Module separator"s below are employed to minimize merge conflicts.
2631 m := make(map[string][]string)
2632 //
2633 // Module separator
2634 //
2635 m["com.android.appsearch"] = []string{
2636 "icing-java-proto-lite",
2637 "libprotobuf-java-lite",
2638 }
2639 //
2640 // Module separator
2641 //
2642 m["com.android.bluetooth.updatable"] = []string{
2643 "android.hardware.audio.common@5.0",
2644 "android.hardware.bluetooth.a2dp@1.0",
2645 "android.hardware.bluetooth.audio@2.0",
2646 "android.hardware.bluetooth@1.0",
2647 "android.hardware.bluetooth@1.1",
2648 "android.hardware.graphics.bufferqueue@1.0",
2649 "android.hardware.graphics.bufferqueue@2.0",
2650 "android.hardware.graphics.common@1.0",
2651 "android.hardware.graphics.common@1.1",
2652 "android.hardware.graphics.common@1.2",
2653 "android.hardware.media@1.0",
2654 "android.hidl.safe_union@1.0",
2655 "android.hidl.token@1.0",
2656 "android.hidl.token@1.0-utils",
2657 "avrcp-target-service",
2658 "avrcp_headers",
2659 "bluetooth-protos-lite",
2660 "bluetooth.mapsapi",
2661 "com.android.vcard",
2662 "dnsresolver_aidl_interface-V2-java",
2663 "ipmemorystore-aidl-interfaces-V5-java",
2664 "ipmemorystore-aidl-interfaces-java",
2665 "internal_include_headers",
2666 "lib-bt-packets",
2667 "lib-bt-packets-avrcp",
2668 "lib-bt-packets-base",
2669 "libFraunhoferAAC",
2670 "libaudio-a2dp-hw-utils",
2671 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002672 "libbluetooth",
2673 "libbluetooth-types",
2674 "libbluetooth-types-header",
2675 "libbluetooth_gd",
2676 "libbluetooth_headers",
2677 "libbluetooth_jni",
2678 "libbt-audio-hal-interface",
2679 "libbt-bta",
2680 "libbt-common",
2681 "libbt-hci",
2682 "libbt-platform-protos-lite",
2683 "libbt-protos-lite",
2684 "libbt-sbc-decoder",
2685 "libbt-sbc-encoder",
2686 "libbt-stack",
2687 "libbt-utils",
2688 "libbtcore",
2689 "libbtdevice",
2690 "libbte",
2691 "libbtif",
2692 "libchrome",
2693 "libevent",
2694 "libfmq",
2695 "libg722codec",
2696 "libgui_headers",
2697 "libmedia_headers",
2698 "libmodpb64",
2699 "libosi",
2700 "libstagefright_foundation_headers",
2701 "libstagefright_headers",
2702 "libstatslog",
2703 "libstatssocket",
2704 "libtinyxml2",
2705 "libudrv-uipc",
2706 "libz",
2707 "media_plugin_headers",
2708 "net-utils-services-common",
2709 "netd_aidl_interface-unstable-java",
2710 "netd_event_listener_interface-java",
2711 "netlink-client",
2712 "networkstack-client",
2713 "sap-api-java-static",
2714 "services.net",
2715 }
2716 //
2717 // Module separator
2718 //
2719 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2720 //
2721 // Module separator
2722 //
2723 m["com.android.extservices"] = []string{
2724 "error_prone_annotations",
2725 "ExtServices-core",
2726 "ExtServices",
2727 "libtextclassifier-java",
2728 "libz_current",
2729 "textclassifier-statsd",
2730 "TextClassifierNotificationLibNoManifest",
2731 "TextClassifierServiceLibNoManifest",
2732 }
2733 //
2734 // Module separator
2735 //
2736 m["com.android.neuralnetworks"] = []string{
2737 "android.hardware.neuralnetworks@1.0",
2738 "android.hardware.neuralnetworks@1.1",
2739 "android.hardware.neuralnetworks@1.2",
2740 "android.hardware.neuralnetworks@1.3",
2741 "android.hidl.allocator@1.0",
2742 "android.hidl.memory.token@1.0",
2743 "android.hidl.memory@1.0",
2744 "android.hidl.safe_union@1.0",
2745 "libarect",
2746 "libbuildversion",
2747 "libmath",
2748 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002749 }
2750 //
2751 // Module separator
2752 //
2753 m["com.android.media"] = []string{
2754 "android.frameworks.bufferhub@1.0",
2755 "android.hardware.cas.native@1.0",
2756 "android.hardware.cas@1.0",
2757 "android.hardware.configstore-utils",
2758 "android.hardware.configstore@1.0",
2759 "android.hardware.configstore@1.1",
2760 "android.hardware.graphics.allocator@2.0",
2761 "android.hardware.graphics.allocator@3.0",
2762 "android.hardware.graphics.bufferqueue@1.0",
2763 "android.hardware.graphics.bufferqueue@2.0",
2764 "android.hardware.graphics.common@1.0",
2765 "android.hardware.graphics.common@1.1",
2766 "android.hardware.graphics.common@1.2",
2767 "android.hardware.graphics.mapper@2.0",
2768 "android.hardware.graphics.mapper@2.1",
2769 "android.hardware.graphics.mapper@3.0",
2770 "android.hardware.media.omx@1.0",
2771 "android.hardware.media@1.0",
2772 "android.hidl.allocator@1.0",
2773 "android.hidl.memory.token@1.0",
2774 "android.hidl.memory@1.0",
2775 "android.hidl.token@1.0",
2776 "android.hidl.token@1.0-utils",
2777 "bionic_libc_platform_headers",
2778 "exoplayer2-extractor",
2779 "exoplayer2-extractor-annotation-stubs",
2780 "gl_headers",
2781 "jsr305",
2782 "libEGL",
2783 "libEGL_blobCache",
2784 "libEGL_getProcAddress",
2785 "libFLAC",
2786 "libFLAC-config",
2787 "libFLAC-headers",
2788 "libGLESv2",
2789 "libaacextractor",
2790 "libamrextractor",
2791 "libarect",
2792 "libaudio_system_headers",
2793 "libaudioclient",
2794 "libaudioclient_headers",
2795 "libaudiofoundation",
2796 "libaudiofoundation_headers",
2797 "libaudiomanager",
2798 "libaudiopolicy",
2799 "libaudioutils",
2800 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002801 "libbluetooth-types-header",
2802 "libbufferhub",
2803 "libbufferhub_headers",
2804 "libbufferhubqueue",
2805 "libc_malloc_debug_backtrace",
2806 "libcamera_client",
2807 "libcamera_metadata",
2808 "libdvr_headers",
2809 "libexpat",
2810 "libfifo",
2811 "libflacextractor",
2812 "libgrallocusage",
2813 "libgraphicsenv",
2814 "libgui",
2815 "libgui_headers",
2816 "libhardware_headers",
2817 "libinput",
2818 "liblzma",
2819 "libmath",
2820 "libmedia",
2821 "libmedia_codeclist",
2822 "libmedia_headers",
2823 "libmedia_helper",
2824 "libmedia_helper_headers",
2825 "libmedia_midiiowrapper",
2826 "libmedia_omx",
2827 "libmediautils",
2828 "libmidiextractor",
2829 "libmkvextractor",
2830 "libmp3extractor",
2831 "libmp4extractor",
2832 "libmpeg2extractor",
2833 "libnativebase_headers",
2834 "libnativewindow_headers",
2835 "libnblog",
2836 "liboggextractor",
2837 "libpackagelistparser",
2838 "libpdx",
2839 "libpdx_default_transport",
2840 "libpdx_headers",
2841 "libpdx_uds",
2842 "libprocinfo",
2843 "libspeexresampler",
2844 "libspeexresampler",
2845 "libstagefright_esds",
2846 "libstagefright_flacdec",
2847 "libstagefright_flacdec",
2848 "libstagefright_foundation",
2849 "libstagefright_foundation_headers",
2850 "libstagefright_foundation_without_imemory",
2851 "libstagefright_headers",
2852 "libstagefright_id3",
2853 "libstagefright_metadatautils",
2854 "libstagefright_mpeg2extractor",
2855 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002856 "libui",
2857 "libui_headers",
2858 "libunwindstack",
2859 "libvibrator",
2860 "libvorbisidec",
2861 "libwavextractor",
2862 "libwebm",
2863 "media_ndk_headers",
2864 "media_plugin_headers",
2865 "updatable-media",
2866 }
2867 //
2868 // Module separator
2869 //
2870 m["com.android.media.swcodec"] = []string{
2871 "android.frameworks.bufferhub@1.0",
2872 "android.hardware.common-ndk_platform",
2873 "android.hardware.configstore-utils",
2874 "android.hardware.configstore@1.0",
2875 "android.hardware.configstore@1.1",
2876 "android.hardware.graphics.allocator@2.0",
2877 "android.hardware.graphics.allocator@3.0",
2878 "android.hardware.graphics.allocator@4.0",
2879 "android.hardware.graphics.bufferqueue@1.0",
2880 "android.hardware.graphics.bufferqueue@2.0",
2881 "android.hardware.graphics.common-ndk_platform",
2882 "android.hardware.graphics.common@1.0",
2883 "android.hardware.graphics.common@1.1",
2884 "android.hardware.graphics.common@1.2",
2885 "android.hardware.graphics.mapper@2.0",
2886 "android.hardware.graphics.mapper@2.1",
2887 "android.hardware.graphics.mapper@3.0",
2888 "android.hardware.graphics.mapper@4.0",
2889 "android.hardware.media.bufferpool@2.0",
2890 "android.hardware.media.c2@1.0",
2891 "android.hardware.media.c2@1.1",
2892 "android.hardware.media.omx@1.0",
2893 "android.hardware.media@1.0",
2894 "android.hardware.media@1.0",
2895 "android.hidl.memory.token@1.0",
2896 "android.hidl.memory@1.0",
2897 "android.hidl.safe_union@1.0",
2898 "android.hidl.token@1.0",
2899 "android.hidl.token@1.0-utils",
2900 "libEGL",
2901 "libFLAC",
2902 "libFLAC-config",
2903 "libFLAC-headers",
2904 "libFraunhoferAAC",
2905 "libLibGuiProperties",
2906 "libarect",
2907 "libaudio_system_headers",
2908 "libaudioutils",
2909 "libaudioutils",
2910 "libaudioutils_fixedfft",
2911 "libavcdec",
2912 "libavcenc",
2913 "libavservices_minijail",
2914 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002915 "libbinderthreadstateutils",
2916 "libbluetooth-types-header",
2917 "libbufferhub_headers",
2918 "libcodec2",
2919 "libcodec2_headers",
2920 "libcodec2_hidl@1.0",
2921 "libcodec2_hidl@1.1",
2922 "libcodec2_internal",
2923 "libcodec2_soft_aacdec",
2924 "libcodec2_soft_aacenc",
2925 "libcodec2_soft_amrnbdec",
2926 "libcodec2_soft_amrnbenc",
2927 "libcodec2_soft_amrwbdec",
2928 "libcodec2_soft_amrwbenc",
2929 "libcodec2_soft_av1dec_gav1",
2930 "libcodec2_soft_avcdec",
2931 "libcodec2_soft_avcenc",
2932 "libcodec2_soft_common",
2933 "libcodec2_soft_flacdec",
2934 "libcodec2_soft_flacenc",
2935 "libcodec2_soft_g711alawdec",
2936 "libcodec2_soft_g711mlawdec",
2937 "libcodec2_soft_gsmdec",
2938 "libcodec2_soft_h263dec",
2939 "libcodec2_soft_h263enc",
2940 "libcodec2_soft_hevcdec",
2941 "libcodec2_soft_hevcenc",
2942 "libcodec2_soft_mp3dec",
2943 "libcodec2_soft_mpeg2dec",
2944 "libcodec2_soft_mpeg4dec",
2945 "libcodec2_soft_mpeg4enc",
2946 "libcodec2_soft_opusdec",
2947 "libcodec2_soft_opusenc",
2948 "libcodec2_soft_rawdec",
2949 "libcodec2_soft_vorbisdec",
2950 "libcodec2_soft_vp8dec",
2951 "libcodec2_soft_vp8enc",
2952 "libcodec2_soft_vp9dec",
2953 "libcodec2_soft_vp9enc",
2954 "libcodec2_vndk",
2955 "libdvr_headers",
2956 "libfmq",
2957 "libfmq",
2958 "libgav1",
2959 "libgralloctypes",
2960 "libgrallocusage",
2961 "libgraphicsenv",
2962 "libgsm",
2963 "libgui_bufferqueue_static",
2964 "libgui_headers",
2965 "libhardware",
2966 "libhardware_headers",
2967 "libhevcdec",
2968 "libhevcenc",
2969 "libion",
2970 "libjpeg",
2971 "liblzma",
2972 "libmath",
2973 "libmedia_codecserviceregistrant",
2974 "libmedia_headers",
2975 "libmpeg2dec",
2976 "libnativebase_headers",
2977 "libnativewindow_headers",
2978 "libpdx_headers",
2979 "libscudo_wrapper",
2980 "libsfplugin_ccodec_utils",
2981 "libspeexresampler",
2982 "libstagefright_amrnb_common",
2983 "libstagefright_amrnbdec",
2984 "libstagefright_amrnbenc",
2985 "libstagefright_amrwbdec",
2986 "libstagefright_amrwbenc",
2987 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002988 "libstagefright_enc_common",
2989 "libstagefright_flacdec",
2990 "libstagefright_foundation",
2991 "libstagefright_foundation_headers",
2992 "libstagefright_headers",
2993 "libstagefright_m4vh263dec",
2994 "libstagefright_m4vh263enc",
2995 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002996 "libui",
2997 "libui_headers",
2998 "libunwindstack",
2999 "libvorbisidec",
3000 "libvpx",
3001 "libyuv",
3002 "libyuv_static",
3003 "media_ndk_headers",
3004 "media_plugin_headers",
3005 "mediaswcodec",
3006 }
3007 //
3008 // Module separator
3009 //
3010 m["com.android.mediaprovider"] = []string{
3011 "MediaProvider",
3012 "MediaProviderGoogle",
3013 "fmtlib_ndk",
3014 "libbase_ndk",
3015 "libfuse",
3016 "libfuse_jni",
3017 }
3018 //
3019 // Module separator
3020 //
3021 m["com.android.permission"] = []string{
3022 "car-ui-lib",
3023 "iconloader",
3024 "kotlin-annotations",
3025 "kotlin-stdlib",
3026 "kotlin-stdlib-jdk7",
3027 "kotlin-stdlib-jdk8",
3028 "kotlinx-coroutines-android",
3029 "kotlinx-coroutines-android-nodeps",
3030 "kotlinx-coroutines-core",
3031 "kotlinx-coroutines-core-nodeps",
3032 "permissioncontroller-statsd",
3033 "GooglePermissionController",
3034 "PermissionController",
3035 "SettingsLibActionBarShadow",
3036 "SettingsLibAppPreference",
3037 "SettingsLibBarChartPreference",
3038 "SettingsLibLayoutPreference",
3039 "SettingsLibProgressBar",
3040 "SettingsLibSearchWidget",
3041 "SettingsLibSettingsTheme",
3042 "SettingsLibRestrictedLockUtils",
3043 "SettingsLibHelpUtils",
3044 }
3045 //
3046 // Module separator
3047 //
3048 m["com.android.runtime"] = []string{
3049 "bionic_libc_platform_headers",
3050 "libarm-optimized-routines-math",
3051 "libc_aeabi",
3052 "libc_bionic",
3053 "libc_bionic_ndk",
3054 "libc_bootstrap",
3055 "libc_common",
3056 "libc_common_shared",
3057 "libc_common_static",
3058 "libc_dns",
3059 "libc_dynamic_dispatch",
3060 "libc_fortify",
3061 "libc_freebsd",
3062 "libc_freebsd_large_stack",
3063 "libc_gdtoa",
3064 "libc_init_dynamic",
3065 "libc_init_static",
3066 "libc_jemalloc_wrapper",
3067 "libc_netbsd",
3068 "libc_nomalloc",
3069 "libc_nopthread",
3070 "libc_openbsd",
3071 "libc_openbsd_large_stack",
3072 "libc_openbsd_ndk",
3073 "libc_pthread",
3074 "libc_static_dispatch",
3075 "libc_syscalls",
3076 "libc_tzcode",
3077 "libc_unwind_static",
3078 "libdebuggerd",
3079 "libdebuggerd_common_headers",
3080 "libdebuggerd_handler_core",
3081 "libdebuggerd_handler_fallback",
3082 "libdl_static",
3083 "libjemalloc5",
3084 "liblinker_main",
3085 "liblinker_malloc",
3086 "liblz4",
3087 "liblzma",
3088 "libprocinfo",
3089 "libpropertyinfoparser",
3090 "libscudo",
3091 "libstdc++",
3092 "libsystemproperties",
3093 "libtombstoned_client_static",
3094 "libunwindstack",
3095 "libz",
3096 "libziparchive",
3097 }
3098 //
3099 // Module separator
3100 //
3101 m["com.android.tethering"] = []string{
3102 "android.hardware.tetheroffload.config-V1.0-java",
3103 "android.hardware.tetheroffload.control-V1.0-java",
3104 "android.hidl.base-V1.0-java",
3105 "libcgrouprc",
3106 "libcgrouprc_format",
3107 "libtetherutilsjni",
3108 "libvndksupport",
3109 "net-utils-framework-common",
3110 "netd_aidl_interface-V3-java",
3111 "netlink-client",
3112 "networkstack-aidl-interfaces-java",
3113 "tethering-aidl-interfaces-java",
3114 "TetheringApiCurrentLib",
3115 }
3116 //
3117 // Module separator
3118 //
3119 m["com.android.wifi"] = []string{
3120 "PlatformProperties",
3121 "android.hardware.wifi-V1.0-java",
3122 "android.hardware.wifi-V1.0-java-constants",
3123 "android.hardware.wifi-V1.1-java",
3124 "android.hardware.wifi-V1.2-java",
3125 "android.hardware.wifi-V1.3-java",
3126 "android.hardware.wifi-V1.4-java",
3127 "android.hardware.wifi.hostapd-V1.0-java",
3128 "android.hardware.wifi.hostapd-V1.1-java",
3129 "android.hardware.wifi.hostapd-V1.2-java",
3130 "android.hardware.wifi.supplicant-V1.0-java",
3131 "android.hardware.wifi.supplicant-V1.1-java",
3132 "android.hardware.wifi.supplicant-V1.2-java",
3133 "android.hardware.wifi.supplicant-V1.3-java",
3134 "android.hidl.base-V1.0-java",
3135 "android.hidl.manager-V1.0-java",
3136 "android.hidl.manager-V1.1-java",
3137 "android.hidl.manager-V1.2-java",
3138 "bouncycastle-unbundled",
3139 "dnsresolver_aidl_interface-V2-java",
3140 "error_prone_annotations",
3141 "framework-wifi-pre-jarjar",
3142 "framework-wifi-util-lib",
3143 "ipmemorystore-aidl-interfaces-V3-java",
3144 "ipmemorystore-aidl-interfaces-java",
3145 "ksoap2",
3146 "libnanohttpd",
3147 "libwifi-jni",
3148 "net-utils-services-common",
3149 "netd_aidl_interface-V2-java",
3150 "netd_aidl_interface-unstable-java",
3151 "netd_event_listener_interface-java",
3152 "netlink-client",
3153 "networkstack-client",
3154 "services.net",
3155 "wifi-lite-protos",
3156 "wifi-nano-protos",
3157 "wifi-service-pre-jarjar",
3158 "wifi-service-resources",
3159 }
3160 //
3161 // Module separator
3162 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003163 m["com.android.os.statsd"] = []string{
3164 "libstatssocket",
3165 }
3166 //
3167 // Module separator
3168 //
3169 m[android.AvailableToAnyApex] = []string{
3170 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3171 "androidx",
3172 "androidx-constraintlayout_constraintlayout",
3173 "androidx-constraintlayout_constraintlayout-nodeps",
3174 "androidx-constraintlayout_constraintlayout-solver",
3175 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3176 "com.google.android.material_material",
3177 "com.google.android.material_material-nodeps",
3178
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003179 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003180 "libprofile-clang-extras",
3181 "libprofile-clang-extras_ndk",
3182 "libprofile-extras",
3183 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003184 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003185 }
3186 return m
3187}
3188
3189func init() {
3190 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3191 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3192}
3193
3194func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3195 rules := make([]android.Rule, 0, len(modules_packages))
3196 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003197 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003198 BootclasspathJar().
3199 With("apex_available", module_name).
3200 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003201 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003202 Because("jars that are part of the " + module_name +
3203 " module may only allow these packages: " + strings.Join(module_packages, ",") +
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003204 " with min_sdk < T. Please jarjar or move code around.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003205 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003206 }
3207 return rules
3208}
3209
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003210// 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 +09003211// Adding code to the bootclasspath in new packages will cause issues on module update.
3212func qModulesPackages() map[string][]string {
3213 return map[string][]string{
3214 "com.android.conscrypt": []string{
3215 "android.net.ssl",
3216 "com.android.org.conscrypt",
3217 },
3218 "com.android.media": []string{
3219 "android.media",
3220 },
3221 }
3222}
3223
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003224// 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 +09003225// Adding code to the bootclasspath in new packages will cause issues on module update.
3226func rModulesPackages() map[string][]string {
3227 return map[string][]string{
3228 "com.android.mediaprovider": []string{
3229 "android.provider",
3230 },
3231 "com.android.permission": []string{
3232 "android.permission",
3233 "android.app.role",
3234 "com.android.permission",
3235 "com.android.role",
3236 },
3237 "com.android.sdkext": []string{
3238 "android.os.ext",
3239 },
3240 "com.android.os.statsd": []string{
3241 "android.app",
3242 "android.os",
3243 "android.util",
3244 "com.android.internal.statsd",
3245 "com.android.server.stats",
3246 },
3247 "com.android.wifi": []string{
3248 "com.android.server.wifi",
3249 "com.android.wifi.x",
3250 "android.hardware.wifi",
3251 "android.net.wifi",
3252 },
3253 "com.android.tethering": []string{
3254 "android.net",
3255 },
3256 }
3257}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003258
3259// For Bazel / bp2build
3260
3261type bazelApexBundleAttributes struct {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003262 Manifest bazel.LabelAttribute
3263 Android_manifest bazel.LabelAttribute
3264 File_contexts bazel.LabelAttribute
3265 Key bazel.LabelAttribute
3266 Certificate bazel.LabelAttribute
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003267 Min_sdk_version *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003268 Updatable bazel.BoolAttribute
3269 Installable bazel.BoolAttribute
3270 Native_shared_libs bazel.LabelListAttribute
Jingwen Chenb07c9012021-12-08 10:05:45 +00003271 Binaries bazel.LabelListAttribute
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003272 Prebuilts bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003273}
3274
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003275// ConvertWithBp2build performs bp2build conversion of an apex
3276func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3277 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003278 if ctx.ModuleType() != "apex" {
3279 return
3280 }
3281
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003282 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003283 if a.properties.Manifest != nil {
3284 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003285 }
3286
3287 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003288 if a.properties.AndroidManifest != nil {
3289 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003290 }
3291
3292 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003293 if a.properties.File_contexts != nil {
3294 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003295 }
3296
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003297 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003298 if a.properties.Min_sdk_version != nil {
3299 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003300 }
3301
3302 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003303 if a.overridableProperties.Key != nil {
3304 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003305 }
3306
3307 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003308 if a.overridableProperties.Certificate != nil {
3309 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003310 }
3311
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003312 nativeSharedLibs := a.properties.ApexNativeDependencies.Native_shared_libs
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003313 nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
3314 nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
3315
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003316 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003317 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3318 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3319
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003320 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003321 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003322
3323 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003324 if a.properties.Updatable != nil {
3325 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003326 }
3327
3328 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003329 if a.properties.Installable != nil {
3330 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003331 }
3332
3333 attrs := &bazelApexBundleAttributes{
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003334 Manifest: manifestLabelAttribute,
3335 Android_manifest: androidManifestLabelAttribute,
3336 File_contexts: fileContextsLabelAttribute,
3337 Min_sdk_version: minSdkVersion,
3338 Key: keyLabelAttribute,
3339 Certificate: certificateLabelAttribute,
3340 Updatable: updatableAttribute,
3341 Installable: installableAttribute,
3342 Native_shared_libs: nativeSharedLibsLabelListAttribute,
Jingwen Chenb07c9012021-12-08 10:05:45 +00003343 Binaries: binariesLabelListAttribute,
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003344 Prebuilts: prebuiltsLabelListAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003345 }
3346
3347 props := bazel.BazelTargetModuleProperties{
3348 Rule_class: "apex",
3349 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3350 }
3351
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003352 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003353}