blob: 75cff7dde47e4a351ebc9b09f7d2567aa765e810 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090034 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/java"
36 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090037 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090039)
40
Jiyong Park8e6d52f2020-11-19 14:37:47 +090041func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000042 registerApexBuildComponents(android.InitRegistrationContext)
43}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044
Paul Duffin667893c2021-03-09 22:34:13 +000045func registerApexBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("apex", BundleFactory)
47 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
48 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
49 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
50 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
51 ctx.RegisterModuleType("override_apex", overrideApexFactory)
52 ctx.RegisterModuleType("apex_set", apexSetFactory)
53
Paul Duffin5dda3e32021-05-05 14:13:27 +010054 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.PreDepsMutators(RegisterPreDepsMutators)
56 ctx.PostDepsMutators(RegisterPostDepsMutators)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040057
58 android.RegisterBp2BuildMutator("apex", ApexBundleBp2Build)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090059}
60
Paul Duffin5dda3e32021-05-05 14:13:27 +010061func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
62 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
63}
64
Jiyong Park8e6d52f2020-11-19 14:37:47 +090065func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
66 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
67 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
68}
69
70func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000071 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090072 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
73 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
74 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010075 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
76 // it should create a platform variant.
77 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090078 ctx.BottomUp("apex", apexMutator).Parallel()
79 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
80 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090081}
82
83type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090084 // Json manifest file describing meta info of this APEX bundle. Refer to
85 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090086 Manifest *string `android:"path"`
87
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090088 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
89 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090090 AndroidManifest *string `android:"path"`
91
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090092 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
93 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090094 Apex_name *string
95
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090096 // Determines the file contexts file for setting the security contexts to files in this APEX
97 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
98 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090099 File_contexts *string `android:"path"`
100
101 ApexNativeDependencies
102
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900103 Multilib apexMultilibProperties
104
Paul Duffin4b64ba02021-03-29 11:02:53 +0100105 // List of bootclasspath fragments that are embedded inside this APEX bundle.
106 Bootclasspath_fragments []string
107
satayev333a1732021-05-17 21:35:26 +0100108 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
109 Systemserverclasspath_fragments []string
110
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900111 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900112 Java_libs []string
113
Sundong Ahn80c04892021-11-23 00:57:19 +0000114 // List of sh binaries that are embedded inside this APEX bundle.
115 Sh_binaries []string
116
Paul Duffin3abc1742021-03-15 19:32:23 +0000117 // List of platform_compat_config files that are embedded inside this APEX bundle.
118 Compat_configs []string
119
Jiyong Park12a719c2021-01-07 15:31:24 +0900120 // List of filesystem images that are embedded inside this APEX bundle.
121 Filesystems []string
122
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900123 // The minimum SDK version that this APEX must support at minimum. This is usually set to
124 // the SDK version that the APEX was first introduced.
125 Min_sdk_version *string
126
127 // Whether this APEX is considered updatable or not. When set to true, this will enforce
128 // additional rules for making sure that the APEX is truly updatable. To be updatable,
129 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000130 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900131 Updatable *bool
132
Jiyong Park1bc84122021-06-22 20:23:05 +0900133 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
134 // false`. Default is false.
135 Platform_apis *bool
136
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900137 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
138 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900139 Installable *bool
140
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000141 // Whether this APEX can be compressed or not. Setting this property to false means this
142 // APEX will never be compressed. When set to true, APEX will be compressed if other
143 // conditions, e.g, target device needs to support APEX compression, are also fulfilled.
144 // Default: true.
145 Compressible *bool
146
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900147 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
148 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
149 Use_vndk_as_stable *bool
150
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000151 // Whether this is multi-installed APEX should skip installing symbol files.
152 // Multi-installed APEXes share the same apex_name and are installed at the same time.
153 // Default is false.
154 //
155 // Should be set to true for all multi-installed APEXes except the singular
156 // default version within the multi-installed group.
157 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
158 // or else conflicting build rules may be created.
159 Multi_install_skip_symbol_files *bool
160
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900161 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
162 // `name#version` or `name` which is an alias for `name#current`. If left empty,
163 // `platform#current` is implied. This value affects all modules included in this APEX. In
164 // other words, they are also built with the SDKs specified here.
165 Uses_sdks []string
166
167 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
168 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
169 // container. When set to zip, contents are stored in a zip container directly. This type is
170 // mostly for host-side debugging. When set to both, the two types are both built. Default
171 // is 'image'.
172 Payload_type *string
173
Huang Jianan13cac632021-08-02 15:02:17 +0800174 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
175 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900176 Payload_fs_type *string
177
178 // For telling the APEX to ignore special handling for system libraries such as bionic.
179 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900180 Ignore_system_library_special_case *bool
181
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100182 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100183 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100184 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900185
186 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
187 // used in tests.
188 Test_only_unsigned_payload *bool
189
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000190 // Whenever apex should be compressed, regardless of product flag used. Should be only
191 // used in tests.
192 Test_only_force_compression *bool
193
Jooyung Han09c11ad2021-10-27 03:45:31 +0900194 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
195 // with the tool to sign payload contents.
196 Custom_sign_tool *string
197
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100198 // Canonical name of this APEX bundle. Used to determine the path to the
199 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
200 // apex mutator variations. For override_apex modules, this is the name of the
201 // overridden base module.
202 ApexVariationName string `blueprint:"mutated"`
203
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900204 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900205
206 // List of sanitizer names that this APEX is enabled for
207 SanitizerNames []string `blueprint:"mutated"`
208
209 PreventInstall bool `blueprint:"mutated"`
210
211 HideFromMake bool `blueprint:"mutated"`
212
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900213 // Internal package method for this APEX. When payload_type is image, this can be either
214 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
215 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900216 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900217}
218
219type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900220 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900221 Native_shared_libs []string
222
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900223 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900224 Jni_libs []string
225
Jiyong Park99644e92020-11-17 22:21:02 +0900226 // List of rust dyn libraries
227 Rust_dyn_libs []string
228
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900229 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900230 Binaries []string
231
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900232 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900233 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900234
235 // List of filesystem images that are embedded inside this APEX bundle.
236 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900237}
238
239type apexMultilibProperties struct {
240 // Native dependencies whose compile_multilib is "first"
241 First ApexNativeDependencies
242
243 // Native dependencies whose compile_multilib is "both"
244 Both ApexNativeDependencies
245
246 // Native dependencies whose compile_multilib is "prefer32"
247 Prefer32 ApexNativeDependencies
248
249 // Native dependencies whose compile_multilib is "32"
250 Lib32 ApexNativeDependencies
251
252 // Native dependencies whose compile_multilib is "64"
253 Lib64 ApexNativeDependencies
254}
255
256type apexTargetBundleProperties struct {
257 Target struct {
258 // Multilib properties only for android.
259 Android struct {
260 Multilib apexMultilibProperties
261 }
262
263 // Multilib properties only for host.
264 Host struct {
265 Multilib apexMultilibProperties
266 }
267
268 // Multilib properties only for host linux_bionic.
269 Linux_bionic struct {
270 Multilib apexMultilibProperties
271 }
272
273 // Multilib properties only for host linux_glibc.
274 Linux_glibc struct {
275 Multilib apexMultilibProperties
276 }
277 }
278}
279
Jiyong Park59140302020-12-14 18:44:04 +0900280type apexArchBundleProperties struct {
281 Arch struct {
282 Arm struct {
283 ApexNativeDependencies
284 }
285 Arm64 struct {
286 ApexNativeDependencies
287 }
288 X86 struct {
289 ApexNativeDependencies
290 }
291 X86_64 struct {
292 ApexNativeDependencies
293 }
294 }
295}
296
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900297// These properties can be used in override_apex to override the corresponding properties in the
298// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900299type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900300 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900301 Apps []string
302
Daniel Norman5a3ce132021-08-26 15:44:43 -0700303 // List of prebuilt files that are embedded inside this APEX bundle.
304 Prebuilts []string
305
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900306 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900307 Rros []string
308
markchien7c803b82021-08-26 22:10:06 +0800309 // List of BPF programs inside this APEX bundle.
310 Bpfs []string
311
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900312 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
313 // Soong). This does not completely prevent installation of the overridden binaries, but if
314 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
315 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900316 Overrides []string
317
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900318 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900319 Logging_parent string
320
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900321 // Apex Container package name. Override value for attribute package:name in
322 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900323 Package_name string
324
325 // A txt file containing list of files that are allowed to be included in this APEX.
326 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700327
328 // Name of the apex_key module that provides the private key to sign this APEX bundle.
329 Key *string
330
331 // Specifies the certificate and the private key to sign the zip container of this APEX. If
332 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
333 // as the certificate and the private key, respectively. If this is ":module", then the
334 // certificate and the private key are provided from the android_app_certificate module
335 // named "module".
336 Certificate *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900337}
338
339type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900340 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900341 android.ModuleBase
342 android.DefaultableModuleBase
343 android.OverridableModuleBase
344 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400345 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900346
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900347 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900348 properties apexBundleProperties
349 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900350 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900351 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900352 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900353
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900354 ///////////////////////////////////////////////////////////////////////////////////////////
355 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900357 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800358 publicKeyFile android.Path
359 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900360
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900361 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800362 containerCertificateFile android.Path
363 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900364
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900365 // Flags for special variants of APEX
366 testApex bool
367 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900368
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
370 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900371 primaryApexType bool
372
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900373 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900374 suffix string
375
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376 // File system type of apex_payload.img
377 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900378
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900379 // Whether to create symlink to the system file instead of having a file inside the apex or
380 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381 linkToSystemLib bool
382
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900383 // List of files to be included in this APEX. This is filled in the first part of
384 // GenerateAndroidBuildActions.
385 filesInfo []apexFile
386
387 // List of other module names that should be installed when this APEX gets installed.
388 requiredDeps []string
389
390 ///////////////////////////////////////////////////////////////////////////////////////////
391 // Outputs (final and intermediates)
392
393 // Processed apex manifest in JSONson format (for Q)
394 manifestJsonOut android.WritablePath
395
396 // Processed apex manifest in PB format (for R+)
397 manifestPbOut android.WritablePath
398
399 // Processed file_contexts files
400 fileContexts android.WritablePath
401
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900402 // Struct holding the merged notice file paths in different formats
403 mergedNotices android.NoticeOutputs
404
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900405 // The built APEX file. This is the main product.
406 outputFile android.WritablePath
407
408 // The built APEX file in app bundle format. This file is not directly installed to the
409 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
410 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
411 // system) to be merged into a single app bundle file that Play accepts. See
412 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
413 bundleModuleFile android.WritablePath
414
Colin Cross6340ea52021-11-04 12:01:18 -0700415 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900416 installDir android.InstallPath
417
Colin Cross6340ea52021-11-04 12:01:18 -0700418 // Path where this APEX was installed.
419 installedFile android.InstallPath
420
421 // Installed locations of symlinks for backward compatibility.
422 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900423
424 // Text file having the list of individual files that are included in this APEX. Used for
425 // debugging purpose.
426 installedFilesFile android.WritablePath
427
428 // List of module names that this APEX is including (to be shown via *-deps-info target).
429 // Used for debugging purpose.
430 android.ApexBundleDepsInfo
431
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900432 // Optional list of lint report zip files for apexes that contain java or app modules
433 lintReports android.Paths
434
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900435 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000436
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000437 isCompressed bool
438
sophiezc80a2b32020-11-12 16:39:19 +0000439 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700440 nativeApisUsedByModuleFile android.ModuleOutPath
441 nativeApisBackedByModuleFile android.ModuleOutPath
442 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800443
444 // Collect the module directory for IDE info in java/jdeps.go.
445 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900446}
447
Colin Cross6340ea52021-11-04 12:01:18 -0700448func (*apexBundle) InstallBypassMake() bool {
449 return true
450}
451
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900452// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900453type apexFileClass int
454
Jooyung Han72bd2f82019-10-23 16:46:38 +0900455const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900456 app apexFileClass = iota
457 appSet
458 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900459 goBinary
460 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900461 nativeExecutable
462 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900463 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900464 pyBinary
465 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900466)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900467
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900468// apexFile represents a file in an APEX bundle. This is created during the first half of
469// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
470// of the function, this is used to create commands that copies the files into a staging directory,
471// where they are packaged into the APEX file. This struct is also used for creating Make modules
472// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900473type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900474 // buildFile is put in the installDir inside the APEX.
475 builtFile android.Path
476 noticeFiles android.Paths
477 installDir string
478 customStem string
479 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900480
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900481 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
482 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
483 // suffix>]
484 androidMkModuleName string // becomes LOCAL_MODULE
485 class apexFileClass // becomes LOCAL_MODULE_CLASS
486 moduleDir string // becomes LOCAL_PATH
487 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
488 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
489 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
490 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900491
492 jacocoReportClassesFile android.Path // only for javalibs and apps
493 lintDepSets java.LintDepSets // only for javalibs and apps
494 certificate java.Certificate // only for apps
495 overriddenPackageName string // only for apps
496
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900497 transitiveDep bool
498 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900499
Jiyong Park57621b22021-01-20 20:33:11 +0900500 multilib string
501
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900502 // TODO(jiyong): remove this
503 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900504}
505
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900506// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900507func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
508 ret := apexFile{
509 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900510 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900511 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900512 class: class,
513 module: module,
514 }
515 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900516 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900517 ret.moduleDir = ctx.OtherModuleDir(module)
518 ret.requiredModuleNames = module.RequiredModuleNames()
519 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
520 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900521 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900522 }
523 return ret
524}
525
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900526func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900527 return af.builtFile != nil && af.builtFile.String() != ""
528}
529
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900530// apexRelativePath returns the relative path of the given path from the install directory of this
531// apexFile.
532// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900533func (af *apexFile) apexRelativePath(path string) string {
534 return filepath.Join(af.installDir, path)
535}
536
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900537// path returns path of this apex file relative to the APEX root
538func (af *apexFile) path() string {
539 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900540}
541
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900542// stem returns the base filename of this apex file
543func (af *apexFile) stem() string {
544 if af.customStem != "" {
545 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900546 }
547 return af.builtFile.Base()
548}
549
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900550// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
551func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900552 var ret []string
553 for _, symlink := range af.symlinks {
554 ret = append(ret, af.apexRelativePath(symlink))
555 }
556 return ret
557}
558
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900559// availableToPlatform tests whether this apexFile is from a module that can be installed to the
560// platform.
561func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900562 if af.module == nil {
563 return false
564 }
565 if am, ok := af.module.(android.ApexModule); ok {
566 return am.AvailableFor(android.AvailableToPlatform)
567 }
568 return false
569}
570
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900571////////////////////////////////////////////////////////////////////////////////////////////////////
572// Mutators
573//
574// Brief description about mutators for APEX. The following three mutators are the most important
575// ones.
576//
577// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
578// to the (direct) dependencies of this APEX bundle.
579//
Paul Duffin949abc02020-12-08 10:34:30 +0000580// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900581// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
582// modules are marked as being included in the APEX via BuildForApex().
583//
Paul Duffin949abc02020-12-08 10:34:30 +0000584// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
585// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900586
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900587type dependencyTag struct {
588 blueprint.BaseDependencyTag
589 name string
590
591 // Determines if the dependent will be part of the APEX payload. Can be false for the
592 // dependencies to the signing key module, etc.
593 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000594
595 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
596 // replacement. This is needed because some prebuilt modules do not provide all the information
597 // needed by the apex.
598 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900599}
600
Paul Duffin8c535da2021-03-17 14:51:03 +0000601func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
602 return !d.sourceOnly
603}
604
605var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
606
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900607var (
Paul Duffin0b817782021-03-17 15:02:19 +0000608 androidAppTag = dependencyTag{name: "androidApp", payload: true}
609 bpfTag = dependencyTag{name: "bpf", payload: true}
610 certificateTag = dependencyTag{name: "certificate"}
611 executableTag = dependencyTag{name: "executable", payload: true}
612 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100613 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100614 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000615 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000616 javaLibTag = dependencyTag{name: "javaLib", payload: true}
617 jniLibTag = dependencyTag{name: "jniLib", payload: true}
618 keyTag = dependencyTag{name: "key"}
619 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
620 rroTag = dependencyTag{name: "rro", payload: true}
621 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
622 testForTag = dependencyTag{name: "test for"}
623 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000624 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900625)
626
627// TODO(jiyong): shorten this function signature
628func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900629 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900630 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900631 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900632
633 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900634 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900635 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
636 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900637 }
638
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900639 // Use *FarVariation* to be able to depend on modules having conflicting variations with
640 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
641 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900642 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900643 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900644 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
645 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900646 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900647 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900648}
649
650func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900651 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
653 } else {
654 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
655 if ctx.Os().Bionic() {
656 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
657 } else {
658 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
659 }
660 }
661}
662
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900663// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
664// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
665func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
666 deviceConfig := ctx.DeviceConfig()
667 if a.vndkApex {
668 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900669 }
670
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900671 var prefix string
672 var vndkVersion string
673 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000674 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900675 prefix = cc.VendorVariationPrefix
676 vndkVersion = deviceConfig.VndkVersion()
677 } else if a.ProductSpecific() {
678 prefix = cc.ProductVariationPrefix
679 vndkVersion = deviceConfig.ProductVndkVersion()
680 }
681 }
682 if vndkVersion == "current" {
683 vndkVersion = deviceConfig.PlatformVndkVersion()
684 }
685 if vndkVersion != "" {
686 return prefix + vndkVersion
687 }
688
689 return android.CoreVariation // The usual case
690}
691
692func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900693 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
694 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
695 // each target os/architectures, appropriate dependencies are selected by their
696 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900697 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900698 imageVariation := a.getImageVariation(ctx)
699
700 a.combineProperties(ctx)
701
702 has32BitTarget := false
703 for _, target := range targets {
704 if target.Arch.ArchType.Multilib == "lib32" {
705 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000706 }
707 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900708 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900709 // Don't include artifacts for the host cross targets because there is no way for us
710 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900711 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900712 continue
713 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000714
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900715 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000716
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900717 // Add native modules targeting both ABIs. When multilib.* is omitted for
718 // native_shared_libs/jni_libs/tests, it implies multilib.both
719 depsList = append(depsList, a.properties.Multilib.Both)
720 depsList = append(depsList, ApexNativeDependencies{
721 Native_shared_libs: a.properties.Native_shared_libs,
722 Tests: a.properties.Tests,
723 Jni_libs: a.properties.Jni_libs,
724 Binaries: nil,
725 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900726
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900727 // Add native modules targeting the first ABI When multilib.* is omitted for
728 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900729 isPrimaryAbi := i == 0
730 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900731 depsList = append(depsList, a.properties.Multilib.First)
732 depsList = append(depsList, ApexNativeDependencies{
733 Native_shared_libs: nil,
734 Tests: nil,
735 Jni_libs: nil,
736 Binaries: a.properties.Binaries,
737 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900738 }
739
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900740 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900741 switch target.Arch.ArchType.Multilib {
742 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900743 depsList = append(depsList, a.properties.Multilib.Lib32)
744 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900745 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900746 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900747 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900748 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900749 }
750 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900751
Jiyong Park59140302020-12-14 18:44:04 +0900752 // Add native modules targeting a specific arch variant
753 switch target.Arch.ArchType {
754 case android.Arm:
755 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
756 case android.Arm64:
757 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
758 case android.X86:
759 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
760 case android.X86_64:
761 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
762 default:
763 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
764 }
765
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900766 for _, d := range depsList {
767 addDependenciesForNativeModules(ctx, d, target, imageVariation)
768 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000769 ctx.AddFarVariationDependencies([]blueprint.Variation{
770 {Mutator: "os", Variation: target.OsVariation()},
771 {Mutator: "arch", Variation: target.ArchVariation()},
772 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900773 }
774
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900775 // Common-arch dependencies come next
776 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100777 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100778 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900779 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900780 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000781 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900782
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900783 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
784 // This field currently isn't used.
785 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900786 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
787 if len(a.properties.Uses_sdks) > 0 {
788 sdkRefs := []android.SdkRef{}
789 for _, str := range a.properties.Uses_sdks {
790 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
791 sdkRefs = append(sdkRefs, parsed)
792 }
793 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100794 }
795}
796
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900797// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900798func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
799 if a.overridableProperties.Allowed_files != nil {
800 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100801 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900802
803 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
804 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800805 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900806 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700807 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
808 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
809 // regardless of the TARGET_PREFER_* setting. See b/144532908
810 arches := ctx.DeviceConfig().Arches()
811 if len(arches) != 0 {
812 archForPrebuiltEtc := arches[0]
813 for _, arch := range arches {
814 // Prefer 64-bit arch if there is any
815 if arch.ArchType.Multilib == "lib64" {
816 archForPrebuiltEtc = arch
817 break
818 }
819 }
820 ctx.AddFarVariationDependencies([]blueprint.Variation{
821 {Mutator: "os", Variation: ctx.Os().String()},
822 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
823 }, prebuiltTag, prebuilts...)
824 }
825 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700826
827 // Dependencies for signing
828 if String(a.overridableProperties.Key) == "" {
829 ctx.PropertyErrorf("key", "missing")
830 return
831 }
832 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
833
834 cert := android.SrcIsModule(a.getCertString(ctx))
835 if cert != "" {
836 ctx.AddDependency(ctx.Module(), certificateTag, cert)
837 // empty cert is not an error. Cert and private keys will be directly found under
838 // PRODUCT_DEFAULT_DEV_CERTIFICATE
839 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100840}
841
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900842type ApexBundleInfo struct {
843 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100844}
845
Paul Duffin949abc02020-12-08 10:34:30 +0000846var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847
Paul Duffina7d6a892020-12-07 17:39:59 +0000848var _ ApexInfoMutator = (*apexBundle)(nil)
849
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100850func (a *apexBundle) ApexVariationName() string {
851 return a.properties.ApexVariationName
852}
853
Paul Duffina7d6a892020-12-07 17:39:59 +0000854// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900855// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
856// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
857// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
858// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000859//
860// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
861// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
862// The apexMutator uses that list to create module variants for the apexes to which it belongs.
863// The relationship between module variants and apexes is not one-to-one as variants will be
864// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000865func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900866
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900867 // The VNDK APEX is special. For the APEX, the membership is described in a very different
868 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
869 // libraries are self-identified by their vndk.enabled properties. There is no need to run
870 // this mutator for the APEX as nothing will be collected. So, let's return fast.
871 if a.vndkApex {
872 return
873 }
874
875 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
876 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
877 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
878 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
879 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900880 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
881 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
882 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
883 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
884 return
885 }
886
Colin Cross56a83212020-09-15 18:30:11 -0700887 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900888 am, ok := child.(android.ApexModule)
889 if !ok || !am.CanHaveApexVariants() {
890 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900891 }
Paul Duffin573989d2021-03-17 13:25:29 +0000892 depTag := mctx.OtherModuleDependencyTag(child)
893
894 // Check to see if the tag always requires that the child module has an apex variant for every
895 // apex variant of the parent module. If it does not then it is still possible for something
896 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
897 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
898 return true
899 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000900 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900901 return false
902 }
Jooyung Handf78e212020-07-22 15:54:47 +0900903 if excludeVndkLibs {
904 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
905 return false
906 }
907 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900908 // By default, all the transitive dependencies are collected, unless filtered out
909 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700910 return true
911 }
912
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900913 // Records whether a certain module is included in this apexBundle via direct dependency or
914 // inndirect dependency.
915 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700916 mctx.WalkDeps(func(child, parent android.Module) bool {
917 if !continueApexDepsWalk(child, parent) {
918 return false
919 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900920 // If the parent is apexBundle, this child is directly depended.
921 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900922 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700923 contents[depName] = contents[depName].Add(directDep)
924 return true
925 })
926
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900927 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900928 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700929 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
930 Contents: apexContents,
931 })
932
Jooyung Haned124c32021-01-26 11:43:46 +0900933 minSdkVersion := a.minSdkVersion(mctx)
934 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
935 if minSdkVersion.IsNone() {
936 minSdkVersion = android.FutureApiLevel
937 }
938
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900939 // This is the main part of this mutator. Mark the collected dependencies that they need to
940 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900941
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100942 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
943 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700944 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100945 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900946 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700947 RequiredSdks: a.RequiredSdks(),
948 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900949 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100950 InApexVariants: []string{apexVariationName},
951 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700952 ApexContents: []*android.ApexContents{apexContents},
953 }
Colin Cross56a83212020-09-15 18:30:11 -0700954 mctx.WalkDeps(func(child, parent android.Module) bool {
955 if !continueApexDepsWalk(child, parent) {
956 return false
957 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900958 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900959 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900960 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961}
962
Paul Duffina7d6a892020-12-07 17:39:59 +0000963type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100964 // ApexVariationName returns the name of the APEX variation to use in the apex
965 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
966 ApexVariationName() string
967
Paul Duffina7d6a892020-12-07 17:39:59 +0000968 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
969 // depended upon by an apex and which require an apex specific variant.
970 ApexInfoMutator(android.TopDownMutatorContext)
971}
972
973// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
974// specific variant to modules that support the ApexInfoMutator.
975func apexInfoMutator(mctx android.TopDownMutatorContext) {
976 if !mctx.Module().Enabled() {
977 return
978 }
979
980 if a, ok := mctx.Module().(ApexInfoMutator); ok {
981 a.ApexInfoMutator(mctx)
982 return
983 }
984}
985
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900986// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
987// unique apex variations for this module. See android/apex.go for more about unique apex variant.
988// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700989func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
990 if !mctx.Module().Enabled() {
991 return
992 }
993 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700994 android.UpdateUniqueApexVariationsForDeps(mctx, am)
995 }
996}
997
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900998// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
999// the apex in order to retrieve its contents later.
1000// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001001func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1002 if !mctx.Module().Enabled() {
1003 return
1004 }
Colin Cross56a83212020-09-15 18:30:11 -07001005 if am, ok := mctx.Module().(android.ApexModule); ok {
1006 if testFor := am.TestFor(); len(testFor) > 0 {
1007 mctx.AddFarVariationDependencies([]blueprint.Variation{
1008 {Mutator: "os", Variation: am.Target().OsVariation()},
1009 {"arch", "common"},
1010 }, testForTag, testFor...)
1011 }
1012 }
1013}
1014
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001015// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001016func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1017 if !mctx.Module().Enabled() {
1018 return
1019 }
Colin Cross56a83212020-09-15 18:30:11 -07001020 if _, ok := mctx.Module().(android.ApexModule); ok {
1021 var contents []*android.ApexContents
1022 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1023 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1024 contents = append(contents, abInfo.Contents)
1025 }
1026 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1027 ApexContents: contents,
1028 })
Colin Crossaede88c2020-08-11 12:17:01 -07001029 }
1030}
1031
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001032// markPlatformAvailability marks whether or not a module can be available to platform. A module
1033// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1034// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1035// be) available to platform
1036// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001037func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1038 // Host and recovery are not considered as platform
1039 if mctx.Host() || mctx.Module().InstallInRecovery() {
1040 return
1041 }
1042
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001043 am, ok := mctx.Module().(android.ApexModule)
1044 if !ok {
1045 return
1046 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001047
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001048 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001049
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001050 // If any of the dep is not available to platform, this module is also considered as being
1051 // not available to platform even if it has "//apex_available:platform"
1052 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001053 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001054 // if the dependency crosses apex boundary, don't consider it
1055 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001056 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001057 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1058 availableToPlatform = false
1059 // TODO(b/154889534) trigger an error when 'am' has
1060 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001061 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001062 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001063
Paul Duffinb5769c12021-05-12 16:16:51 +01001064 // Exception 1: check to see if the module always requires it.
1065 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001066 availableToPlatform = true
1067 }
1068
1069 // Exception 2: bootstrap bionic libraries are also always available to platform
1070 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1071 availableToPlatform = true
1072 }
1073
1074 if !availableToPlatform {
1075 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001076 }
1077}
1078
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001079// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001080// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001081func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001082 if !mctx.Module().Enabled() {
1083 return
1084 }
Colin Cross56a83212020-09-15 18:30:11 -07001085
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001086 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001087 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001088 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001089 return
1090 }
1091
1092 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001093 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1094 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001095 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001096 if strings.HasPrefix(apexBundleName, "com.android.art") {
1097 // Create an alias from the platform variant. This is done to make
1098 // test_for dependencies work for modules that are split by the APEX
1099 // mutator, since test_for dependencies always go to the platform variant.
1100 // This doesn't happen for normal APEXes that are disjunct, so only do
1101 // this for the overlapping ART APEXes.
1102 // TODO(b/183882457): Remove this if the test_for functionality is
1103 // refactored to depend on the proper APEX variants instead of platform.
1104 mctx.CreateAliasVariation("", apexBundleName)
1105 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001106 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1107 apexBundleName := o.GetOverriddenModuleName()
1108 if apexBundleName == "" {
1109 mctx.ModuleErrorf("base property is not set")
1110 return
1111 }
1112 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001113 if strings.HasPrefix(apexBundleName, "com.android.art") {
1114 // TODO(b/183882457): See note for CreateAliasVariation above.
1115 mctx.CreateAliasVariation("", apexBundleName)
1116 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001117 }
1118}
Sundong Ahne9b55722019-09-06 17:37:42 +09001119
Paul Duffin6717d882021-06-15 19:09:41 +01001120// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1121// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001122func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001123 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001124 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001125 return !a.vndkApex
1126 }
1127
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001128 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001129}
1130
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001131// See android.UpdateDirectlyInAnyApex
1132// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001133func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1134 if !mctx.Module().Enabled() {
1135 return
1136 }
1137 if am, ok := mctx.Module().(android.ApexModule); ok {
1138 android.UpdateDirectlyInAnyApex(mctx, am)
1139 }
1140}
1141
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001142// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001143type apexPackaging int
1144
1145const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001146 // imageApex is a packaging method where contents are included in a filesystem image which
1147 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001148 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001149
1150 // zipApex is a packaging method where contents are directly included in the zip container.
1151 // This is used for host-side testing - because the contents are easily accessible by
1152 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001153 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001154
1155 // flattendApex is a packaging method where contents are not included in the APEX file, but
1156 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1157 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001158 flattenedApex
1159)
1160
1161const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001162 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001163 imageApexSuffix = ".apex"
1164 imageCapexSuffix = ".capex"
1165 zipApexSuffix = ".zipapex"
1166 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001167
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001168 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001169 imageApexType = "image"
1170 zipApexType = "zip"
1171 flattenedApexType = "flattened"
1172
Dan Willemsen47e1a752021-10-16 18:36:13 -07001173 ext4FsType = "ext4"
1174 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001175 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001176)
1177
1178// The suffix for the output "file", not the module
1179func (a apexPackaging) suffix() string {
1180 switch a {
1181 case imageApex:
1182 return imageApexSuffix
1183 case zipApex:
1184 return zipApexSuffix
1185 default:
1186 panic(fmt.Errorf("unknown APEX type %d", a))
1187 }
1188}
1189
1190func (a apexPackaging) name() string {
1191 switch a {
1192 case imageApex:
1193 return imageApexType
1194 case zipApex:
1195 return zipApexType
1196 default:
1197 panic(fmt.Errorf("unknown APEX type %d", a))
1198 }
1199}
1200
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001201// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1202// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001203func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001204 if !mctx.Module().Enabled() {
1205 return
1206 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001207 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001208 var variants []string
1209 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1210 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001211 // This is the normal case. Note that both image and flattend APEXes are
1212 // created. The image type is installed to the system partition, while the
1213 // flattened APEX is (optionally) installed to the system_ext partition.
1214 // This is mostly for GSI which has to support wide range of devices. If GSI
1215 // is installed on a newer (APEX-capable) device, the image APEX in the
1216 // system will be used. However, if the same GSI is installed on an old
1217 // device which can't support image APEX, the flattened APEX in the
1218 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001219 variants = append(variants, imageApexType, flattenedApexType)
1220 case "zip":
1221 variants = append(variants, zipApexType)
1222 case "both":
1223 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1224 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001225 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001226 return
1227 }
1228
1229 modules := mctx.CreateLocalVariations(variants...)
1230
1231 for i, v := range variants {
1232 switch v {
1233 case imageApexType:
1234 modules[i].(*apexBundle).properties.ApexType = imageApex
1235 case zipApexType:
1236 modules[i].(*apexBundle).properties.ApexType = zipApex
1237 case flattenedApexType:
1238 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001239 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001240 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001241 modules[i].(*apexBundle).MakeAsSystemExt()
1242 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001243 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001244 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001245 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 // payload_type is forcibly overridden to "image"
1247 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001248 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001249 }
1250}
1251
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001252var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001253
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001254// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001255func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1256 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001257 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001258 return true
1259}
1260
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001261var _ android.OutputFileProducer = (*apexBundle)(nil)
1262
1263// Implements android.OutputFileProducer
1264func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1265 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001266 case "", android.DefaultDistTag:
1267 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001268 return android.Paths{a.outputFile}, nil
1269 default:
1270 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1271 }
1272}
1273
1274var _ cc.Coverage = (*apexBundle)(nil)
1275
1276// Implements cc.Coverage
1277func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1278 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1279}
1280
1281// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001282func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001283 a.properties.PreventInstall = true
1284}
1285
1286// Implements cc.Coverage
1287func (a *apexBundle) HideFromMake() {
1288 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001289 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1290 // TODO(ccross): untangle these
1291 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001292}
1293
1294// Implements cc.Coverage
1295func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1296 a.properties.IsCoverageVariant = coverage
1297}
1298
1299// Implements cc.Coverage
1300func (a *apexBundle) EnableCoverageIfNeeded() {}
1301
1302var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1303
1304// Implements android.ApexBudleDepsInfoIntf
1305func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001306 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001307}
1308
Jiyong Park1bc84122021-06-22 20:23:05 +09001309func (a *apexBundle) UsePlatformApis() bool {
1310 return proptools.BoolDefault(a.properties.Platform_apis, false)
1311}
1312
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001313// getCertString returns the name of the cert that should be used to sign this APEX. This is
1314// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001315func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001316 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001317 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1318 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1319 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001320 if a.vndkApex {
1321 moduleName = vndkApexName
1322 }
1323 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001324 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001325 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001326 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001327 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001328}
1329
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001330// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001331func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001332 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001333}
1334
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001335// See the generate_hashtree property
1336func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001337 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001338}
1339
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001340// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001341func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1342 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1343}
1344
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001345// See the test_only_force_compression property
1346func (a *apexBundle) testOnlyShouldForceCompression() bool {
1347 return proptools.Bool(a.properties.Test_only_force_compression)
1348}
1349
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001350// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1351// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1352// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001353
Jiyong Parkf97782b2019-02-13 20:28:58 +09001354func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1355 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1356 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1357 }
1358}
1359
Jiyong Park388ef3f2019-01-28 19:47:32 +09001360func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001361 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1362 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001363 }
1364
1365 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001366 globalSanitizerNames := []string{}
1367 if a.Host() {
1368 globalSanitizerNames = ctx.Config().SanitizeHost()
1369 } else {
1370 arches := ctx.Config().SanitizeDeviceArch()
1371 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1372 globalSanitizerNames = ctx.Config().SanitizeDevice()
1373 }
1374 }
1375 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001376}
1377
Jooyung Han8ce8db92020-05-15 19:05:05 +09001378func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001379 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1380 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001381 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001382 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001383 for _, target := range ctx.MultiTargets() {
1384 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001385 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1386 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1387 Tests: nil,
1388 Jni_libs: nil,
1389 Binaries: nil,
1390 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001391 break
1392 }
1393 }
1394 }
1395}
1396
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1398// returned apexFile saves information about the Soong module that will be used for creating the
1399// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001400func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001401 // Decide the APEX-local directory by the multilib of the library In the future, we may
1402 // query this to the module.
1403 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001404 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001405 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001406 case "lib32":
1407 dirInApex = "lib"
1408 case "lib64":
1409 dirInApex = "lib64"
1410 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001411 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001412 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001413 }
Jooyung Han35155c42020-02-06 17:33:20 +09001414 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001415 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001416 // Special case for Bionic libs and other libs installed with them. This is to
1417 // prevent those libs from being included in the search path
1418 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1419 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1420 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1421 // will be loaded into the default linker namespace (aka "platform" namespace). If
1422 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1423 // be loaded again into the runtime linker namespace, which will result in double
1424 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001425 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001426 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001427
Jiyong Parkf653b052019-11-18 15:39:01 +09001428 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001429 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1430 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001431}
1432
Jiyong Park1833cef2019-12-13 13:28:36 +09001433func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001434 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001435 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001436 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001437 }
Jooyung Han35155c42020-02-06 17:33:20 +09001438 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001439 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001440 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1441 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001442 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001443 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001444 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001445}
1446
Jiyong Park99644e92020-11-17 22:21:02 +09001447func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1448 dirInApex := "bin"
1449 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1450 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1451 }
1452 fileToCopy := rustm.OutputFile().Path()
1453 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1454 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1455 return af
1456}
1457
1458func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1459 // Decide the APEX-local directory by the multilib of the library
1460 // In the future, we may query this to the module.
1461 var dirInApex string
1462 switch rustm.Arch().ArchType.Multilib {
1463 case "lib32":
1464 dirInApex = "lib"
1465 case "lib64":
1466 dirInApex = "lib64"
1467 }
1468 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1469 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1470 }
1471 fileToCopy := rustm.OutputFile().Path()
1472 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1473 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1474}
1475
Jiyong Park1833cef2019-12-13 13:28:36 +09001476func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001477 dirInApex := "bin"
1478 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001479 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001480}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001481
Jiyong Park1833cef2019-12-13 13:28:36 +09001482func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001483 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001484 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001485 // NB: Since go binaries are static we don't need the module for anything here, which is
1486 // good since the go tool is a blueprint.Module not an android.Module like we would
1487 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001488 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001489}
1490
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001491func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001492 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001493 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1494 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1495 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001496 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001497 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001498 af.symlinks = sh.Symlinks()
1499 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001500}
1501
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001502func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001503 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001504 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001505 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001506}
1507
atrost6e126252020-01-27 17:01:16 +00001508func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1509 dirInApex := filepath.Join("etc", config.SubDir())
1510 fileToCopy := config.CompatConfig()
1511 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1512}
1513
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001514// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1515// way.
1516type javaModule interface {
1517 android.Module
1518 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001519 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001520 JacocoReportClassesFile() android.Path
1521 LintDepSets() java.LintDepSets
1522 Stem() string
1523}
1524
1525var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001526var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001527var _ javaModule = (*java.SdkLibrary)(nil)
1528var _ javaModule = (*java.DexImport)(nil)
1529var _ javaModule = (*java.SdkLibraryImport)(nil)
1530
Paul Duffin190fdef2021-04-26 10:33:59 +01001531// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001532func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001533 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001534}
1535
1536// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1537func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001538 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001539 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001540 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1541 af.lintDepSets = module.LintDepSets()
1542 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001543 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1544 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1545 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1546 }
1547 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001548 return af
1549}
1550
1551// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1552// the same way.
1553type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001554 android.Module
1555 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001556 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001557 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001558 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001559 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001560 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001561 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001562}
1563
1564var _ androidApp = (*java.AndroidApp)(nil)
1565var _ androidApp = (*java.AndroidAppImport)(nil)
1566
1567func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001568 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001569 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001570 appDir = "priv-app"
1571 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001572 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001573 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001574 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001575 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001576 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001577 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001578
1579 if app, ok := aapp.(interface {
1580 OverriddenManifestPackageName() string
1581 }); ok {
1582 af.overriddenPackageName = app.OverriddenManifestPackageName()
1583 }
Jiyong Park618922e2020-01-08 13:35:43 +09001584 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001585}
1586
Jiyong Park69aeba92020-04-24 21:16:36 +09001587func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1588 rroDir := "overlay"
1589 dirInApex := filepath.Join(rroDir, rro.Theme())
1590 fileToCopy := rro.OutputFile()
1591 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1592 af.certificate = rro.Certificate()
1593
1594 if a, ok := rro.(interface {
1595 OverriddenManifestPackageName() string
1596 }); ok {
1597 af.overriddenPackageName = a.OverriddenManifestPackageName()
1598 }
1599 return af
1600}
1601
markchien2f59ec92020-09-02 16:23:38 +08001602func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1603 dirInApex := filepath.Join("etc", "bpf")
1604 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1605}
1606
Jiyong Park12a719c2021-01-07 15:31:24 +09001607func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1608 dirInApex := filepath.Join("etc", "fs")
1609 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1610}
1611
Paul Duffin064b70c2020-11-02 17:32:38 +00001612// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001613// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1614// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1615// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001616func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001617 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001618 am, ok := child.(android.ApexModule)
1619 if !ok || !am.CanHaveApexVariants() {
1620 return false
1621 }
1622
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001623 // Filter-out unwanted depedendencies
1624 depTag := ctx.OtherModuleDependencyTag(child)
1625 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1626 return false
1627 }
1628 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001629 return false
1630 }
1631
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001633 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001634
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001635 // Visit actually
1636 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001637 })
1638}
1639
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001640// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1641type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001642
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001643const (
1644 ext4 fsType = iota
1645 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001646 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001647)
Artur Satayev849f8442020-04-28 14:57:42 +01001648
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001649func (f fsType) string() string {
1650 switch f {
1651 case ext4:
1652 return ext4FsType
1653 case f2fs:
1654 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001655 case erofs:
1656 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001657 default:
1658 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001659 }
1660}
1661
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001662// Creates build rules for an APEX. It consists of the following major steps:
1663//
1664// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1665// 2) traverse the dependency tree to collect apexFile structs from them.
1666// 3) some fields in apexBundle struct are configured
1667// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001668func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001669 ////////////////////////////////////////////////////////////////////////////////////////////
1670 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001671 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001672 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001673 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001674 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001675 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001676 if len(a.properties.Tests) > 0 && !a.testApex {
1677 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1678 return
1679 }
Jiyong Park678c8812020-02-07 17:25:49 +09001680
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001681 ////////////////////////////////////////////////////////////////////////////////////////////
1682 // 2) traverse the dependency tree to collect apexFile structs from them.
1683
1684 // all the files that will be included in this APEX
1685 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001686
Jooyung Hane1633032019-08-01 17:41:43 +09001687 // native lib dependencies
1688 var provideNativeLibs []string
1689 var requireNativeLibs []string
1690
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001691 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1692
braleeb0c1f0c2021-06-07 22:49:13 +08001693 // Collect the module directory for IDE info in java/jdeps.go.
1694 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1695
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001696 // TODO(jiyong): do this using WalkPayloadDeps
1697 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001698 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001699 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001700 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1701 return false
1702 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001703 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1704 return false
1705 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001706 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001707 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001708 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001709 case sharedLibTag, jniLibTag:
1710 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001711 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001712 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1713 fi.isJniLib = isJniLib
1714 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001715 // Collect the list of stub-providing libs except:
1716 // - VNDK libs are only for vendors
1717 // - bootstrap bionic libs are treated as provided by system
1718 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001719 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001720 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001721 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001722 } else if r, ok := child.(*rust.Module); ok {
1723 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001724 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001725 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001726 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001727 propertyName := "native_shared_libs"
1728 if isJniLib {
1729 propertyName = "jni_libs"
1730 }
1731 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001732 }
1733 case executableTag:
1734 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001735 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001736 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001737 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001738 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001739 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001740 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001741 } else if rust, ok := child.(*rust.Module); ok {
1742 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1743 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001744 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001745 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1746 }
1747 case shBinaryTag:
1748 if sh, ok := child.(*sh.ShBinary); ok {
1749 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1750 } else {
1751 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001752 }
Paul Duffin94f19632021-04-20 12:40:07 +01001753 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001754 {
Paul Duffin7771eba2021-04-23 14:25:28 +01001755 if _, ok := child.(*java.BootclasspathFragmentModule); !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001756 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001757 return false
1758 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001759
Paul Duffincc33ec82021-04-25 23:14:55 +01001760 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1761 filesInfo = append(filesInfo, filesToAdd...)
Paul Duffin4d101b62021-03-24 15:42:20 +00001762 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001763 }
satayev333a1732021-05-17 21:35:26 +01001764 case sscpfTag:
1765 {
1766 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1767 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1768 return false
1769 }
satayevb98371c2021-06-15 16:49:50 +01001770 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1771 filesInfo = append(filesInfo, *af)
1772 }
satayev333a1732021-05-17 21:35:26 +01001773 return true
1774 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001775 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001776 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001777 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001778 af := apexFileForJavaModule(ctx, child.(javaModule))
1779 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001780 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1781 return false
1782 }
1783 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001784 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001785 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001786 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001787 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001788 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001789 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001790 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001791 return true // track transitive dependencies
1792 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001793 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001794 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001795 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001796 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1797 appDir := "app"
1798 if ap.Privileged() {
1799 appDir = "priv-app"
1800 }
Yo Chiange8128052020-07-23 20:09:18 +08001801 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001802 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1803 af.certificate = java.PresignedCertificate
1804 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001805 } else {
1806 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1807 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001808 case rroTag:
1809 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1810 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1811 } else {
1812 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1813 }
markchien2f59ec92020-09-02 16:23:38 +08001814 case bpfTag:
1815 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1816 filesToCopy, _ := bpfProgram.OutputFiles("")
1817 for _, bpfFile := range filesToCopy {
1818 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1819 }
1820 } else {
1821 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1822 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001823 case fsTag:
1824 if fs, ok := child.(filesystem.Filesystem); ok {
1825 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1826 } else {
1827 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1828 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001829 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001830 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001831 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001832 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001833 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001834 }
Paul Duffin0b817782021-03-17 15:02:19 +00001835 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001836 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1837 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1838 } else {
1839 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1840 }
Roland Levillain630846d2019-06-26 12:48:34 +01001841 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001842 if ccTest, ok := child.(*cc.Module); ok {
1843 if ccTest.IsTestPerSrcAllTestsVariation() {
1844 // Multiple-output test module (where `test_per_src: true`).
1845 //
1846 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1847 // We do not add this variation to `filesInfo`, as it has no output;
1848 // however, we do add the other variations of this module as indirect
1849 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001850 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001851 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001852 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001853 af.class = nativeTest
1854 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001855 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001856 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001857 } else {
1858 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1859 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001860 case keyTag:
1861 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001862 a.privateKeyFile = key.privateKeyFile
1863 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001864 } else {
1865 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001866 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001867 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001868 case certificateTag:
1869 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001870 a.containerCertificateFile = dep.Certificate.Pem
1871 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001872 } else {
1873 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1874 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001875 case android.PrebuiltDepTag:
1876 // If the prebuilt is force disabled, remember to delete the prebuilt file
1877 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001878 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001879 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1880 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001881 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001882 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001883 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001884 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001885 // We cannot use a switch statement on `depTag` here as the checked
1886 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001887 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001888 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001889 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001890 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001891 return false
1892 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001893 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1894 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001895
1896 // Always track transitive dependencies for host.
1897 if a.Host() {
1898 filesInfo = append(filesInfo, af)
1899 return true
1900 }
1901
Colin Cross56a83212020-09-15 18:30:11 -07001902 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001903 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001904 // If the dependency is a stubs lib, don't include it in this APEX,
1905 // but make sure that the lib is installed on the device.
1906 // In case no APEX is having the lib, the lib is installed to the system
1907 // partition.
1908 //
1909 // Always include if we are a host-apex however since those won't have any
1910 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001911 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001912 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001913 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001914 if !android.InList(name, a.requiredDeps) {
1915 a.requiredDeps = append(a.requiredDeps, name)
1916 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001917 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001918 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001919 // Don't track further
1920 return false
1921 }
Jiyong Parke3867542020-12-03 17:28:25 +09001922
1923 // If the dep is not considered to be in the same
1924 // apex, don't add it to filesInfo so that it is not
1925 // included in this APEX.
1926 // TODO(jiyong): move this to at the top of the
1927 // else-if clause for the indirect dependencies.
1928 // Currently, that's impossible because we would
1929 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001930 // DepIsInSameAPex is false. We also shouldn't do
1931 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001932 //
1933 // TODO(jiyong): explain why the same module is passed in twice.
1934 // Switching the first am to parent breaks lots of tests.
1935 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001936 return false
1937 }
1938
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 filesInfo = append(filesInfo, af)
1940 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001941 } else if rm, ok := child.(*rust.Module); ok {
1942 af := apexFileForRustLibrary(ctx, rm)
1943 af.transitiveDep = true
1944 filesInfo = append(filesInfo, af)
1945 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001946 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001947 } else if cc.IsTestPerSrcDepTag(depTag) {
1948 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001949 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001950 // Handle modules created as `test_per_src` variations of a single test module:
1951 // use the name of the generated test binary (`fileToCopy`) instead of the name
1952 // of the original test module (`depName`, shared by all `test_per_src`
1953 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001954 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001955 // these are not considered transitive dep
1956 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001957 filesInfo = append(filesInfo, af)
1958 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001959 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001960 } else if cc.IsHeaderDepTag(depTag) {
1961 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001962 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001963 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1964 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001965 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001966 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001967 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1968 }
Jiyong Park99644e92020-11-17 22:21:02 +09001969 } else if rust.IsDylibDepTag(depTag) {
1970 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1971 af := apexFileForRustLibrary(ctx, rustm)
1972 af.transitiveDep = true
1973 filesInfo = append(filesInfo, af)
1974 return true // track transitive dependencies
1975 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09001976 } else if rust.IsRlibDepTag(depTag) {
1977 // Rlib is statically linked, but it might have shared lib
1978 // dependencies. Track them.
1979 return true
Paul Duffin65898052021-04-20 22:47:03 +01001980 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01001981 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00001982 switch child.(type) {
1983 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01001984 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01001985 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00001986 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01001987 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00001988 return false
1989 }
1990 filesInfo = append(filesInfo, af)
1991 return true // track transitive dependencies
1992 default:
Paul Duffin94f19632021-04-20 12:40:07 +01001993 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 +00001994 }
satayev333a1732021-05-17 21:35:26 +01001995 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
1996 // Add the contents of the systemserverclasspath fragment to the apex.
1997 switch child.(type) {
1998 case *java.Library, *java.SdkLibrary:
1999 af := apexFileForJavaModule(ctx, child.(javaModule))
2000 filesInfo = append(filesInfo, af)
2001 return true // track transitive dependencies
2002 default:
2003 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2004 }
Colin Cross56a83212020-09-15 18:30:11 -07002005 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2006 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002007 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002008 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002009 }
2010 }
2011 }
2012 return false
2013 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002014 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002015 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002016 return
2017 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002018
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002019 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002020 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002021 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002022 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002023 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002024 if e, ok := encountered[dest]; !ok {
2025 encountered[dest] = f
2026 } else {
2027 // If a module is directly included and also transitively depended on
2028 // consider it as directly included.
2029 e.transitiveDep = e.transitiveDep && f.transitiveDep
2030 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002031 }
2032 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002033 var result []apexFile
2034 for _, v := range encountered {
2035 result = append(result, v)
2036 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002037 return result
2038 }
2039 filesInfo = removeDup(filesInfo)
2040
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002041 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002042 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002043 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2044 // changes.
2045 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002046 })
2047
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002048 ////////////////////////////////////////////////////////////////////////////////////////////
2049 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002050 a.installDir = android.PathForModuleInstall(ctx, "apex")
2051 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002052
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002053 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002054 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002055 switch a.properties.ApexType {
2056 case imageApex:
2057 if buildFlattenedAsDefault {
2058 a.suffix = imageApexSuffix
2059 } else {
2060 a.suffix = ""
2061 a.primaryApexType = true
2062
2063 if ctx.Config().InstallExtraFlattenedApexes() {
2064 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2065 }
2066 }
2067 case zipApex:
2068 if proptools.String(a.properties.Payload_type) == "zip" {
2069 a.suffix = ""
2070 a.primaryApexType = true
2071 } else {
2072 a.suffix = zipApexSuffix
2073 }
2074 case flattenedApex:
2075 if buildFlattenedAsDefault {
2076 a.suffix = ""
2077 a.primaryApexType = true
2078 } else {
2079 a.suffix = flattenedSuffix
2080 }
2081 }
2082
Theotime Combes4ba38c12020-06-12 12:46:59 +00002083 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2084 case ext4FsType:
2085 a.payloadFsType = ext4
2086 case f2fsFsType:
2087 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002088 case erofsFsType:
2089 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002090 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002091 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 +00002092 }
2093
Jiyong Park7cd10e32020-01-14 09:22:18 +09002094 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2095 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2096 // the same library in the system partition, thus effectively sharing the same libraries
2097 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2098 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002099 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002100
Jooyung Han85d61762020-06-24 23:50:26 +09002101 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2102 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002103 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002104 a.linkToSystemLib = false
2105 }
2106
Jiyong Park4da07972021-01-05 21:01:11 +09002107 forced := ctx.Config().ForceApexSymlinkOptimization()
2108
Jiyong Park9d677202020-02-19 16:29:35 +09002109 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002110 // to the system health when the APEXes are still bundled (b/149805758).
2111 if !forced && a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002112 a.linkToSystemLib = false
2113 }
2114
Jiyong Park638d30e2020-02-26 18:27:19 +09002115 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2116 if ctx.Host() {
2117 a.linkToSystemLib = false
2118 }
2119
Colin Cross6340ea52021-11-04 12:01:18 -07002120 if a.properties.ApexType != zipApex {
2121 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2122 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002123
2124 ////////////////////////////////////////////////////////////////////////////////////////////
2125 // 4) generate the build rules to create the APEX. This is done in builder.go.
2126 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002127 if a.properties.ApexType == flattenedApex {
2128 a.buildFlattenedApex(ctx)
2129 } else {
2130 a.buildUnflattenedApex(ctx)
2131 }
Jiyong Park956305c2020-01-09 12:32:06 +09002132 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002133 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002134
2135 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2136 if a.installable() {
2137 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2138 // along with other ordinary files. (Note that this is done by apexer for
2139 // non-flattened APEXes)
2140 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2141
2142 // Place the public key as apex_pubkey. This is also done by apexer for
2143 // non-flattened APEXes case.
2144 // TODO(jiyong): Why do we need this CP rule?
2145 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2146 ctx.Build(pctx, android.BuildParams{
2147 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002148 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002149 Output: copiedPubkey,
2150 })
2151 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2152 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002153}
2154
Paul Duffincc33ec82021-04-25 23:14:55 +01002155// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2156// the bootclasspath_fragment contributes to the apex.
2157func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2158 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2159 var filesToAdd []apexFile
2160
2161 // Add the boot image files, e.g. .art, .oat and .vdex files.
2162 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2163 dirInApex := filepath.Join("javalib", arch.String())
2164 for _, f := range files {
2165 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2166 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2167 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2168 filesToAdd = append(filesToAdd, af)
2169 }
2170 }
2171
satayev3db35472021-05-06 23:59:58 +01002172 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002173 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2174 filesToAdd = append(filesToAdd, *af)
2175 }
satayev3db35472021-05-06 23:59:58 +01002176
Paul Duffincc33ec82021-04-25 23:14:55 +01002177 return filesToAdd
2178}
2179
satayevb98371c2021-06-15 16:49:50 +01002180// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2181// the module contributes to the apex; or nil if the proto config was not generated.
2182func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2183 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2184 if !info.ClasspathFragmentProtoGenerated {
2185 return nil
2186 }
2187 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2188 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2189 return &af
satayev14e49132021-05-17 21:03:07 +01002190}
2191
Paul Duffincc33ec82021-04-25 23:14:55 +01002192// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2193// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002194func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2195 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2196
2197 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2198 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002199 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2200 if err != nil {
2201 ctx.ModuleErrorf("%s", err)
2202 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002203
2204 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2205 // bootclasspath_fragment.
2206 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2207 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002208}
2209
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002210///////////////////////////////////////////////////////////////////////////////////////////////////
2211// Factory functions
2212//
2213
2214func newApexBundle() *apexBundle {
2215 module := &apexBundle{}
2216
2217 module.AddProperties(&module.properties)
2218 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002219 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002220 module.AddProperties(&module.overridableProperties)
2221
2222 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2223 android.InitDefaultableModule(module)
2224 android.InitSdkAwareModule(module)
2225 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002226 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002227 return module
2228}
2229
Paul Duffineb8051d2021-10-18 17:49:39 +01002230func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002231 bundle := newApexBundle()
2232 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002233 return bundle
2234}
2235
2236// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2237// certain compatibility checks such as apex_available are not done for apex_test.
2238func testApexBundleFactory() android.Module {
2239 bundle := newApexBundle()
2240 bundle.testApex = true
2241 return bundle
2242}
2243
2244// apex packages other modules into an APEX file which is a packaging format for system-level
2245// components like binaries, shared libraries, etc.
2246func BundleFactory() android.Module {
2247 return newApexBundle()
2248}
2249
2250type Defaults struct {
2251 android.ModuleBase
2252 android.DefaultsModuleBase
2253}
2254
2255// apex_defaults provides defaultable properties to other apex modules.
2256func defaultsFactory() android.Module {
2257 return DefaultsFactory()
2258}
2259
2260func DefaultsFactory(props ...interface{}) android.Module {
2261 module := &Defaults{}
2262
2263 module.AddProperties(props...)
2264 module.AddProperties(
2265 &apexBundleProperties{},
2266 &apexTargetBundleProperties{},
2267 &overridableProperties{},
2268 )
2269
2270 android.InitDefaultsModule(module)
2271 return module
2272}
2273
2274type OverrideApex struct {
2275 android.ModuleBase
2276 android.OverrideModuleBase
2277}
2278
2279func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2280 // All the overrides happen in the base module.
2281}
2282
2283// override_apex is used to create an apex module based on another apex module by overriding some of
2284// its properties.
2285func overrideApexFactory() android.Module {
2286 m := &OverrideApex{}
2287
2288 m.AddProperties(&overridableProperties{})
2289
2290 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2291 android.InitOverrideModule(m)
2292 return m
2293}
2294
2295///////////////////////////////////////////////////////////////////////////////////////////////////
2296// Vality check routines
2297//
2298// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2299// certain conditions are not met.
2300//
2301// TODO(jiyong): move these checks to a separate go file.
2302
2303// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2304// of this apexBundle.
2305func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
2306 if a.testApex || a.vndkApex {
2307 return
2308 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002309 // apexBundle::minSdkVersion reports its own errors.
2310 minSdkVersion := a.minSdkVersion(ctx)
2311 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
2312}
2313
2314func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
2315 ver := proptools.String(a.properties.Min_sdk_version)
2316 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002317 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002318 }
2319 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2320 if err != nil {
2321 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2322 return android.NoneApiLevel
2323 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002324 return apiLevel
2325}
2326
2327// Ensures that a lib providing stub isn't statically linked
2328func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2329 // Practically, we only care about regular APEXes on the device.
2330 if ctx.Host() || a.testApex || a.vndkApex {
2331 return
2332 }
2333
2334 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2335
2336 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2337 if ccm, ok := to.(*cc.Module); ok {
2338 apexName := ctx.ModuleName()
2339 fromName := ctx.OtherModuleName(from)
2340 toName := ctx.OtherModuleName(to)
2341
2342 // If `to` is not actually in the same APEX as `from` then it does not need
2343 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002344 //
2345 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002346 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2347 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2348 return false
2349 }
2350
2351 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2352 // exception to this rule. It can't make the static dependencies dynamic
2353 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002354 // Same rule should be applied to linkerconfig, because it should be executed
2355 // only with static linked libraries before linker is available with ld.config.txt
2356 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002357 return false
2358 }
2359
2360 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2361 if isStubLibraryFromOtherApex && !externalDep {
2362 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2363 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2364 }
2365
2366 }
2367 return true
2368 })
2369}
2370
satayevb98371c2021-06-15 16:49:50 +01002371// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002372func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2373 if a.Updatable() {
2374 if String(a.properties.Min_sdk_version) == "" {
2375 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2376 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002377 if a.UsePlatformApis() {
2378 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2379 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002380 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002381 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002382 }
2383}
2384
satayevb98371c2021-06-15 16:49:50 +01002385// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2386func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2387 ctx.VisitDirectDeps(func(module android.Module) {
2388 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2389 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2390 if !info.ClasspathFragmentProtoGenerated {
2391 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2392 }
2393 }
2394 })
2395}
2396
2397// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002398func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002399 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2400 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002401 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2402 tag := ctx.OtherModuleDependencyTag(module)
2403 switch tag {
2404 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002405 if m, ok := module.(interface {
2406 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2407 }); ok {
2408 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002409 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2410 }
2411 }
2412 }
2413 })
2414}
2415
satayevb98371c2021-06-15 16:49:50 +01002416// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002417func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2418 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2419 if ctx.Host() || a.testApex || a.vndkApex {
2420 return
2421 }
2422
2423 // Because APEXes targeting other than system/system_ext partitions can't set
2424 // apex_available, we skip checks for these APEXes
2425 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2426 return
2427 }
2428
2429 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2430 // Requiring them and their transitive depencies with apex_available is not right
2431 // because they just add noise.
2432 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2433 return
2434 }
2435
2436 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2437 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2438 if externalDep {
2439 return false
2440 }
2441
2442 apexName := ctx.ModuleName()
2443 fromName := ctx.OtherModuleName(from)
2444 toName := ctx.OtherModuleName(to)
2445
2446 // If `to` is not actually in the same APEX as `from` then it does not need
2447 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002448 //
2449 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002450 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2451 // As soon as the dependency graph crosses the APEX boundary, don't go
2452 // further.
2453 return false
2454 }
2455
2456 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2457 return true
2458 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002459 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2460 "\n\nDependency path:%s\n\n"+
2461 "Consider adding %q to 'apex_available' property of %q",
2462 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002463 // Visit this module's dependencies to check and report any issues with their availability.
2464 return true
2465 })
2466}
2467
Jiyong Park192600a2021-08-03 07:52:17 +00002468// checkStaticExecutable ensures that executables in an APEX are not static.
2469func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002470 // No need to run this for host APEXes
2471 if ctx.Host() {
2472 return
2473 }
2474
Jiyong Park192600a2021-08-03 07:52:17 +00002475 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2476 if ctx.OtherModuleDependencyTag(module) != executableTag {
2477 return
2478 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002479
2480 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002481 apex := a.ApexVariationName()
2482 exec := ctx.OtherModuleName(module)
2483 if isStaticExecutableAllowed(apex, exec) {
2484 return
2485 }
2486 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2487 }
2488 })
2489}
2490
2491// A small list of exceptions where static executables are allowed in APEXes.
2492func isStaticExecutableAllowed(apex string, exec string) bool {
2493 m := map[string][]string{
2494 "com.android.runtime": []string{
2495 "linker",
2496 "linkerconfig",
2497 },
2498 }
2499 execNames, ok := m[apex]
2500 return ok && android.InList(exec, execNames)
2501}
2502
braleeb0c1f0c2021-06-07 22:49:13 +08002503// Collect information for opening IDE project files in java/jdeps.go.
2504func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2505 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2506 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2507 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2508 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2509}
2510
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002511var (
2512 apexAvailBaseline = makeApexAvailableBaseline()
2513 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2514)
2515
Colin Cross440e0d02020-06-11 11:32:11 -07002516func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002517 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002518 moduleName = normalizeModuleName(moduleName)
2519
Colin Cross440e0d02020-06-11 11:32:11 -07002520 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002521 return true
2522 }
2523
2524 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002525 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002526 return true
2527 }
2528
2529 return false
2530}
2531
2532func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002533 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2534 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002535 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002536 if strings.HasPrefix(moduleName, "libclang_rt.") {
2537 // This module has many arch variants that depend on the product being built.
2538 // We don't want to list them all
2539 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002540 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002541 if strings.HasPrefix(moduleName, "androidx.") {
2542 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2543 moduleName = "androidx"
2544 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002545 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002546}
2547
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002548// Transform the map of apex -> modules to module -> apexes.
2549func invertApexBaseline(m map[string][]string) map[string][]string {
2550 r := make(map[string][]string)
2551 for apex, modules := range m {
2552 for _, module := range modules {
2553 r[module] = append(r[module], apex)
2554 }
2555 }
2556 return r
2557}
2558
2559// Retrieve the baseline of apexes to which the supplied module belongs.
2560func BaselineApexAvailable(moduleName string) []string {
2561 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2562}
2563
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002564// This is a map from apex to modules, which overrides the apex_available setting for that
2565// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002566// TODO(b/147364041): remove this
2567func makeApexAvailableBaseline() map[string][]string {
2568 // The "Module separator"s below are employed to minimize merge conflicts.
2569 m := make(map[string][]string)
2570 //
2571 // Module separator
2572 //
2573 m["com.android.appsearch"] = []string{
2574 "icing-java-proto-lite",
2575 "libprotobuf-java-lite",
2576 }
2577 //
2578 // Module separator
2579 //
2580 m["com.android.bluetooth.updatable"] = []string{
2581 "android.hardware.audio.common@5.0",
2582 "android.hardware.bluetooth.a2dp@1.0",
2583 "android.hardware.bluetooth.audio@2.0",
2584 "android.hardware.bluetooth@1.0",
2585 "android.hardware.bluetooth@1.1",
2586 "android.hardware.graphics.bufferqueue@1.0",
2587 "android.hardware.graphics.bufferqueue@2.0",
2588 "android.hardware.graphics.common@1.0",
2589 "android.hardware.graphics.common@1.1",
2590 "android.hardware.graphics.common@1.2",
2591 "android.hardware.media@1.0",
2592 "android.hidl.safe_union@1.0",
2593 "android.hidl.token@1.0",
2594 "android.hidl.token@1.0-utils",
2595 "avrcp-target-service",
2596 "avrcp_headers",
2597 "bluetooth-protos-lite",
2598 "bluetooth.mapsapi",
2599 "com.android.vcard",
2600 "dnsresolver_aidl_interface-V2-java",
2601 "ipmemorystore-aidl-interfaces-V5-java",
2602 "ipmemorystore-aidl-interfaces-java",
2603 "internal_include_headers",
2604 "lib-bt-packets",
2605 "lib-bt-packets-avrcp",
2606 "lib-bt-packets-base",
2607 "libFraunhoferAAC",
2608 "libaudio-a2dp-hw-utils",
2609 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002610 "libbluetooth",
2611 "libbluetooth-types",
2612 "libbluetooth-types-header",
2613 "libbluetooth_gd",
2614 "libbluetooth_headers",
2615 "libbluetooth_jni",
2616 "libbt-audio-hal-interface",
2617 "libbt-bta",
2618 "libbt-common",
2619 "libbt-hci",
2620 "libbt-platform-protos-lite",
2621 "libbt-protos-lite",
2622 "libbt-sbc-decoder",
2623 "libbt-sbc-encoder",
2624 "libbt-stack",
2625 "libbt-utils",
2626 "libbtcore",
2627 "libbtdevice",
2628 "libbte",
2629 "libbtif",
2630 "libchrome",
2631 "libevent",
2632 "libfmq",
2633 "libg722codec",
2634 "libgui_headers",
2635 "libmedia_headers",
2636 "libmodpb64",
2637 "libosi",
2638 "libstagefright_foundation_headers",
2639 "libstagefright_headers",
2640 "libstatslog",
2641 "libstatssocket",
2642 "libtinyxml2",
2643 "libudrv-uipc",
2644 "libz",
2645 "media_plugin_headers",
2646 "net-utils-services-common",
2647 "netd_aidl_interface-unstable-java",
2648 "netd_event_listener_interface-java",
2649 "netlink-client",
2650 "networkstack-client",
2651 "sap-api-java-static",
2652 "services.net",
2653 }
2654 //
2655 // Module separator
2656 //
2657 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2658 //
2659 // Module separator
2660 //
2661 m["com.android.extservices"] = []string{
2662 "error_prone_annotations",
2663 "ExtServices-core",
2664 "ExtServices",
2665 "libtextclassifier-java",
2666 "libz_current",
2667 "textclassifier-statsd",
2668 "TextClassifierNotificationLibNoManifest",
2669 "TextClassifierServiceLibNoManifest",
2670 }
2671 //
2672 // Module separator
2673 //
2674 m["com.android.neuralnetworks"] = []string{
2675 "android.hardware.neuralnetworks@1.0",
2676 "android.hardware.neuralnetworks@1.1",
2677 "android.hardware.neuralnetworks@1.2",
2678 "android.hardware.neuralnetworks@1.3",
2679 "android.hidl.allocator@1.0",
2680 "android.hidl.memory.token@1.0",
2681 "android.hidl.memory@1.0",
2682 "android.hidl.safe_union@1.0",
2683 "libarect",
2684 "libbuildversion",
2685 "libmath",
2686 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002687 }
2688 //
2689 // Module separator
2690 //
2691 m["com.android.media"] = []string{
2692 "android.frameworks.bufferhub@1.0",
2693 "android.hardware.cas.native@1.0",
2694 "android.hardware.cas@1.0",
2695 "android.hardware.configstore-utils",
2696 "android.hardware.configstore@1.0",
2697 "android.hardware.configstore@1.1",
2698 "android.hardware.graphics.allocator@2.0",
2699 "android.hardware.graphics.allocator@3.0",
2700 "android.hardware.graphics.bufferqueue@1.0",
2701 "android.hardware.graphics.bufferqueue@2.0",
2702 "android.hardware.graphics.common@1.0",
2703 "android.hardware.graphics.common@1.1",
2704 "android.hardware.graphics.common@1.2",
2705 "android.hardware.graphics.mapper@2.0",
2706 "android.hardware.graphics.mapper@2.1",
2707 "android.hardware.graphics.mapper@3.0",
2708 "android.hardware.media.omx@1.0",
2709 "android.hardware.media@1.0",
2710 "android.hidl.allocator@1.0",
2711 "android.hidl.memory.token@1.0",
2712 "android.hidl.memory@1.0",
2713 "android.hidl.token@1.0",
2714 "android.hidl.token@1.0-utils",
2715 "bionic_libc_platform_headers",
2716 "exoplayer2-extractor",
2717 "exoplayer2-extractor-annotation-stubs",
2718 "gl_headers",
2719 "jsr305",
2720 "libEGL",
2721 "libEGL_blobCache",
2722 "libEGL_getProcAddress",
2723 "libFLAC",
2724 "libFLAC-config",
2725 "libFLAC-headers",
2726 "libGLESv2",
2727 "libaacextractor",
2728 "libamrextractor",
2729 "libarect",
2730 "libaudio_system_headers",
2731 "libaudioclient",
2732 "libaudioclient_headers",
2733 "libaudiofoundation",
2734 "libaudiofoundation_headers",
2735 "libaudiomanager",
2736 "libaudiopolicy",
2737 "libaudioutils",
2738 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002739 "libbluetooth-types-header",
2740 "libbufferhub",
2741 "libbufferhub_headers",
2742 "libbufferhubqueue",
2743 "libc_malloc_debug_backtrace",
2744 "libcamera_client",
2745 "libcamera_metadata",
2746 "libdvr_headers",
2747 "libexpat",
2748 "libfifo",
2749 "libflacextractor",
2750 "libgrallocusage",
2751 "libgraphicsenv",
2752 "libgui",
2753 "libgui_headers",
2754 "libhardware_headers",
2755 "libinput",
2756 "liblzma",
2757 "libmath",
2758 "libmedia",
2759 "libmedia_codeclist",
2760 "libmedia_headers",
2761 "libmedia_helper",
2762 "libmedia_helper_headers",
2763 "libmedia_midiiowrapper",
2764 "libmedia_omx",
2765 "libmediautils",
2766 "libmidiextractor",
2767 "libmkvextractor",
2768 "libmp3extractor",
2769 "libmp4extractor",
2770 "libmpeg2extractor",
2771 "libnativebase_headers",
2772 "libnativewindow_headers",
2773 "libnblog",
2774 "liboggextractor",
2775 "libpackagelistparser",
2776 "libpdx",
2777 "libpdx_default_transport",
2778 "libpdx_headers",
2779 "libpdx_uds",
2780 "libprocinfo",
2781 "libspeexresampler",
2782 "libspeexresampler",
2783 "libstagefright_esds",
2784 "libstagefright_flacdec",
2785 "libstagefright_flacdec",
2786 "libstagefright_foundation",
2787 "libstagefright_foundation_headers",
2788 "libstagefright_foundation_without_imemory",
2789 "libstagefright_headers",
2790 "libstagefright_id3",
2791 "libstagefright_metadatautils",
2792 "libstagefright_mpeg2extractor",
2793 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002794 "libui",
2795 "libui_headers",
2796 "libunwindstack",
2797 "libvibrator",
2798 "libvorbisidec",
2799 "libwavextractor",
2800 "libwebm",
2801 "media_ndk_headers",
2802 "media_plugin_headers",
2803 "updatable-media",
2804 }
2805 //
2806 // Module separator
2807 //
2808 m["com.android.media.swcodec"] = []string{
2809 "android.frameworks.bufferhub@1.0",
2810 "android.hardware.common-ndk_platform",
2811 "android.hardware.configstore-utils",
2812 "android.hardware.configstore@1.0",
2813 "android.hardware.configstore@1.1",
2814 "android.hardware.graphics.allocator@2.0",
2815 "android.hardware.graphics.allocator@3.0",
2816 "android.hardware.graphics.allocator@4.0",
2817 "android.hardware.graphics.bufferqueue@1.0",
2818 "android.hardware.graphics.bufferqueue@2.0",
2819 "android.hardware.graphics.common-ndk_platform",
2820 "android.hardware.graphics.common@1.0",
2821 "android.hardware.graphics.common@1.1",
2822 "android.hardware.graphics.common@1.2",
2823 "android.hardware.graphics.mapper@2.0",
2824 "android.hardware.graphics.mapper@2.1",
2825 "android.hardware.graphics.mapper@3.0",
2826 "android.hardware.graphics.mapper@4.0",
2827 "android.hardware.media.bufferpool@2.0",
2828 "android.hardware.media.c2@1.0",
2829 "android.hardware.media.c2@1.1",
2830 "android.hardware.media.omx@1.0",
2831 "android.hardware.media@1.0",
2832 "android.hardware.media@1.0",
2833 "android.hidl.memory.token@1.0",
2834 "android.hidl.memory@1.0",
2835 "android.hidl.safe_union@1.0",
2836 "android.hidl.token@1.0",
2837 "android.hidl.token@1.0-utils",
2838 "libEGL",
2839 "libFLAC",
2840 "libFLAC-config",
2841 "libFLAC-headers",
2842 "libFraunhoferAAC",
2843 "libLibGuiProperties",
2844 "libarect",
2845 "libaudio_system_headers",
2846 "libaudioutils",
2847 "libaudioutils",
2848 "libaudioutils_fixedfft",
2849 "libavcdec",
2850 "libavcenc",
2851 "libavservices_minijail",
2852 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002853 "libbinderthreadstateutils",
2854 "libbluetooth-types-header",
2855 "libbufferhub_headers",
2856 "libcodec2",
2857 "libcodec2_headers",
2858 "libcodec2_hidl@1.0",
2859 "libcodec2_hidl@1.1",
2860 "libcodec2_internal",
2861 "libcodec2_soft_aacdec",
2862 "libcodec2_soft_aacenc",
2863 "libcodec2_soft_amrnbdec",
2864 "libcodec2_soft_amrnbenc",
2865 "libcodec2_soft_amrwbdec",
2866 "libcodec2_soft_amrwbenc",
2867 "libcodec2_soft_av1dec_gav1",
2868 "libcodec2_soft_avcdec",
2869 "libcodec2_soft_avcenc",
2870 "libcodec2_soft_common",
2871 "libcodec2_soft_flacdec",
2872 "libcodec2_soft_flacenc",
2873 "libcodec2_soft_g711alawdec",
2874 "libcodec2_soft_g711mlawdec",
2875 "libcodec2_soft_gsmdec",
2876 "libcodec2_soft_h263dec",
2877 "libcodec2_soft_h263enc",
2878 "libcodec2_soft_hevcdec",
2879 "libcodec2_soft_hevcenc",
2880 "libcodec2_soft_mp3dec",
2881 "libcodec2_soft_mpeg2dec",
2882 "libcodec2_soft_mpeg4dec",
2883 "libcodec2_soft_mpeg4enc",
2884 "libcodec2_soft_opusdec",
2885 "libcodec2_soft_opusenc",
2886 "libcodec2_soft_rawdec",
2887 "libcodec2_soft_vorbisdec",
2888 "libcodec2_soft_vp8dec",
2889 "libcodec2_soft_vp8enc",
2890 "libcodec2_soft_vp9dec",
2891 "libcodec2_soft_vp9enc",
2892 "libcodec2_vndk",
2893 "libdvr_headers",
2894 "libfmq",
2895 "libfmq",
2896 "libgav1",
2897 "libgralloctypes",
2898 "libgrallocusage",
2899 "libgraphicsenv",
2900 "libgsm",
2901 "libgui_bufferqueue_static",
2902 "libgui_headers",
2903 "libhardware",
2904 "libhardware_headers",
2905 "libhevcdec",
2906 "libhevcenc",
2907 "libion",
2908 "libjpeg",
2909 "liblzma",
2910 "libmath",
2911 "libmedia_codecserviceregistrant",
2912 "libmedia_headers",
2913 "libmpeg2dec",
2914 "libnativebase_headers",
2915 "libnativewindow_headers",
2916 "libpdx_headers",
2917 "libscudo_wrapper",
2918 "libsfplugin_ccodec_utils",
2919 "libspeexresampler",
2920 "libstagefright_amrnb_common",
2921 "libstagefright_amrnbdec",
2922 "libstagefright_amrnbenc",
2923 "libstagefright_amrwbdec",
2924 "libstagefright_amrwbenc",
2925 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002926 "libstagefright_enc_common",
2927 "libstagefright_flacdec",
2928 "libstagefright_foundation",
2929 "libstagefright_foundation_headers",
2930 "libstagefright_headers",
2931 "libstagefright_m4vh263dec",
2932 "libstagefright_m4vh263enc",
2933 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002934 "libui",
2935 "libui_headers",
2936 "libunwindstack",
2937 "libvorbisidec",
2938 "libvpx",
2939 "libyuv",
2940 "libyuv_static",
2941 "media_ndk_headers",
2942 "media_plugin_headers",
2943 "mediaswcodec",
2944 }
2945 //
2946 // Module separator
2947 //
2948 m["com.android.mediaprovider"] = []string{
2949 "MediaProvider",
2950 "MediaProviderGoogle",
2951 "fmtlib_ndk",
2952 "libbase_ndk",
2953 "libfuse",
2954 "libfuse_jni",
2955 }
2956 //
2957 // Module separator
2958 //
2959 m["com.android.permission"] = []string{
2960 "car-ui-lib",
2961 "iconloader",
2962 "kotlin-annotations",
2963 "kotlin-stdlib",
2964 "kotlin-stdlib-jdk7",
2965 "kotlin-stdlib-jdk8",
2966 "kotlinx-coroutines-android",
2967 "kotlinx-coroutines-android-nodeps",
2968 "kotlinx-coroutines-core",
2969 "kotlinx-coroutines-core-nodeps",
2970 "permissioncontroller-statsd",
2971 "GooglePermissionController",
2972 "PermissionController",
2973 "SettingsLibActionBarShadow",
2974 "SettingsLibAppPreference",
2975 "SettingsLibBarChartPreference",
2976 "SettingsLibLayoutPreference",
2977 "SettingsLibProgressBar",
2978 "SettingsLibSearchWidget",
2979 "SettingsLibSettingsTheme",
2980 "SettingsLibRestrictedLockUtils",
2981 "SettingsLibHelpUtils",
2982 }
2983 //
2984 // Module separator
2985 //
2986 m["com.android.runtime"] = []string{
2987 "bionic_libc_platform_headers",
2988 "libarm-optimized-routines-math",
2989 "libc_aeabi",
2990 "libc_bionic",
2991 "libc_bionic_ndk",
2992 "libc_bootstrap",
2993 "libc_common",
2994 "libc_common_shared",
2995 "libc_common_static",
2996 "libc_dns",
2997 "libc_dynamic_dispatch",
2998 "libc_fortify",
2999 "libc_freebsd",
3000 "libc_freebsd_large_stack",
3001 "libc_gdtoa",
3002 "libc_init_dynamic",
3003 "libc_init_static",
3004 "libc_jemalloc_wrapper",
3005 "libc_netbsd",
3006 "libc_nomalloc",
3007 "libc_nopthread",
3008 "libc_openbsd",
3009 "libc_openbsd_large_stack",
3010 "libc_openbsd_ndk",
3011 "libc_pthread",
3012 "libc_static_dispatch",
3013 "libc_syscalls",
3014 "libc_tzcode",
3015 "libc_unwind_static",
3016 "libdebuggerd",
3017 "libdebuggerd_common_headers",
3018 "libdebuggerd_handler_core",
3019 "libdebuggerd_handler_fallback",
3020 "libdl_static",
3021 "libjemalloc5",
3022 "liblinker_main",
3023 "liblinker_malloc",
3024 "liblz4",
3025 "liblzma",
3026 "libprocinfo",
3027 "libpropertyinfoparser",
3028 "libscudo",
3029 "libstdc++",
3030 "libsystemproperties",
3031 "libtombstoned_client_static",
3032 "libunwindstack",
3033 "libz",
3034 "libziparchive",
3035 }
3036 //
3037 // Module separator
3038 //
3039 m["com.android.tethering"] = []string{
3040 "android.hardware.tetheroffload.config-V1.0-java",
3041 "android.hardware.tetheroffload.control-V1.0-java",
3042 "android.hidl.base-V1.0-java",
3043 "libcgrouprc",
3044 "libcgrouprc_format",
3045 "libtetherutilsjni",
3046 "libvndksupport",
3047 "net-utils-framework-common",
3048 "netd_aidl_interface-V3-java",
3049 "netlink-client",
3050 "networkstack-aidl-interfaces-java",
3051 "tethering-aidl-interfaces-java",
3052 "TetheringApiCurrentLib",
3053 }
3054 //
3055 // Module separator
3056 //
3057 m["com.android.wifi"] = []string{
3058 "PlatformProperties",
3059 "android.hardware.wifi-V1.0-java",
3060 "android.hardware.wifi-V1.0-java-constants",
3061 "android.hardware.wifi-V1.1-java",
3062 "android.hardware.wifi-V1.2-java",
3063 "android.hardware.wifi-V1.3-java",
3064 "android.hardware.wifi-V1.4-java",
3065 "android.hardware.wifi.hostapd-V1.0-java",
3066 "android.hardware.wifi.hostapd-V1.1-java",
3067 "android.hardware.wifi.hostapd-V1.2-java",
3068 "android.hardware.wifi.supplicant-V1.0-java",
3069 "android.hardware.wifi.supplicant-V1.1-java",
3070 "android.hardware.wifi.supplicant-V1.2-java",
3071 "android.hardware.wifi.supplicant-V1.3-java",
3072 "android.hidl.base-V1.0-java",
3073 "android.hidl.manager-V1.0-java",
3074 "android.hidl.manager-V1.1-java",
3075 "android.hidl.manager-V1.2-java",
3076 "bouncycastle-unbundled",
3077 "dnsresolver_aidl_interface-V2-java",
3078 "error_prone_annotations",
3079 "framework-wifi-pre-jarjar",
3080 "framework-wifi-util-lib",
3081 "ipmemorystore-aidl-interfaces-V3-java",
3082 "ipmemorystore-aidl-interfaces-java",
3083 "ksoap2",
3084 "libnanohttpd",
3085 "libwifi-jni",
3086 "net-utils-services-common",
3087 "netd_aidl_interface-V2-java",
3088 "netd_aidl_interface-unstable-java",
3089 "netd_event_listener_interface-java",
3090 "netlink-client",
3091 "networkstack-client",
3092 "services.net",
3093 "wifi-lite-protos",
3094 "wifi-nano-protos",
3095 "wifi-service-pre-jarjar",
3096 "wifi-service-resources",
3097 }
3098 //
3099 // Module separator
3100 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003101 m["com.android.os.statsd"] = []string{
3102 "libstatssocket",
3103 }
3104 //
3105 // Module separator
3106 //
3107 m[android.AvailableToAnyApex] = []string{
3108 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3109 "androidx",
3110 "androidx-constraintlayout_constraintlayout",
3111 "androidx-constraintlayout_constraintlayout-nodeps",
3112 "androidx-constraintlayout_constraintlayout-solver",
3113 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3114 "com.google.android.material_material",
3115 "com.google.android.material_material-nodeps",
3116
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003117 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003118 "libprofile-clang-extras",
3119 "libprofile-clang-extras_ndk",
3120 "libprofile-extras",
3121 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003122 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003123 }
3124 return m
3125}
3126
3127func init() {
3128 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3129 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3130}
3131
3132func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3133 rules := make([]android.Rule, 0, len(modules_packages))
3134 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003135 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003136 BootclasspathJar().
3137 With("apex_available", module_name).
3138 WithMatcher("permitted_packages", android.NotInList(module_packages)).
3139 Because("jars that are part of the " + module_name +
3140 " module may only allow these packages: " + strings.Join(module_packages, ",") +
3141 ". Please jarjar or move code around.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003142 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003143 }
3144 return rules
3145}
3146
3147// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
3148// Adding code to the bootclasspath in new packages will cause issues on module update.
3149func qModulesPackages() map[string][]string {
3150 return map[string][]string{
3151 "com.android.conscrypt": []string{
3152 "android.net.ssl",
3153 "com.android.org.conscrypt",
3154 },
3155 "com.android.media": []string{
3156 "android.media",
3157 },
3158 }
3159}
3160
3161// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
3162// Adding code to the bootclasspath in new packages will cause issues on module update.
3163func rModulesPackages() map[string][]string {
3164 return map[string][]string{
3165 "com.android.mediaprovider": []string{
3166 "android.provider",
3167 },
3168 "com.android.permission": []string{
3169 "android.permission",
3170 "android.app.role",
3171 "com.android.permission",
3172 "com.android.role",
3173 },
3174 "com.android.sdkext": []string{
3175 "android.os.ext",
3176 },
3177 "com.android.os.statsd": []string{
3178 "android.app",
3179 "android.os",
3180 "android.util",
3181 "com.android.internal.statsd",
3182 "com.android.server.stats",
3183 },
3184 "com.android.wifi": []string{
3185 "com.android.server.wifi",
3186 "com.android.wifi.x",
3187 "android.hardware.wifi",
3188 "android.net.wifi",
3189 },
3190 "com.android.tethering": []string{
3191 "android.net",
3192 },
3193 }
3194}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003195
3196// For Bazel / bp2build
3197
3198type bazelApexBundleAttributes struct {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003199 Manifest bazel.LabelAttribute
3200 Android_manifest bazel.LabelAttribute
3201 File_contexts bazel.LabelAttribute
3202 Key bazel.LabelAttribute
3203 Certificate bazel.LabelAttribute
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003204 Min_sdk_version *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003205 Updatable bazel.BoolAttribute
3206 Installable bazel.BoolAttribute
3207 Native_shared_libs bazel.LabelListAttribute
3208 Binaries bazel.StringListAttribute
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003209 Prebuilts bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003210}
3211
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003212func ApexBundleBp2Build(ctx android.TopDownMutatorContext) {
3213 module, ok := ctx.Module().(*apexBundle)
3214 if !ok {
3215 // Not an APEX bundle
3216 return
3217 }
3218 if !module.ConvertWithBp2build(ctx) {
3219 return
3220 }
3221 if ctx.ModuleType() != "apex" {
3222 return
3223 }
3224
3225 apexBundleBp2BuildInternal(ctx, module)
3226}
3227
3228func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) {
3229 var manifestLabelAttribute bazel.LabelAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003230 if module.properties.Manifest != nil {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003231 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Manifest))
3232 }
3233
3234 var androidManifestLabelAttribute bazel.LabelAttribute
3235 if module.properties.AndroidManifest != nil {
3236 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.AndroidManifest))
3237 }
3238
3239 var fileContextsLabelAttribute bazel.LabelAttribute
3240 if module.properties.File_contexts != nil {
3241 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.File_contexts))
3242 }
3243
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003244 var minSdkVersion *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003245 if module.properties.Min_sdk_version != nil {
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003246 minSdkVersion = module.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003247 }
3248
3249 var keyLabelAttribute bazel.LabelAttribute
3250 if module.overridableProperties.Key != nil {
3251 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Key))
3252 }
3253
3254 var certificateLabelAttribute bazel.LabelAttribute
3255 if module.overridableProperties.Certificate != nil {
3256 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Certificate))
3257 }
3258
3259 nativeSharedLibs := module.properties.ApexNativeDependencies.Native_shared_libs
3260 nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
3261 nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
3262
Daniel Norman5a3ce132021-08-26 15:44:43 -07003263 prebuilts := module.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003264 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3265 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3266
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003267 binaries := module.properties.ApexNativeDependencies.Binaries
3268 binariesStringListAttribute := bazel.MakeStringListAttribute(binaries)
3269
3270 var updatableAttribute bazel.BoolAttribute
3271 if module.properties.Updatable != nil {
3272 updatableAttribute.Value = module.properties.Updatable
3273 }
3274
3275 var installableAttribute bazel.BoolAttribute
3276 if module.properties.Installable != nil {
3277 installableAttribute.Value = module.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003278 }
3279
3280 attrs := &bazelApexBundleAttributes{
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003281 Manifest: manifestLabelAttribute,
3282 Android_manifest: androidManifestLabelAttribute,
3283 File_contexts: fileContextsLabelAttribute,
3284 Min_sdk_version: minSdkVersion,
3285 Key: keyLabelAttribute,
3286 Certificate: certificateLabelAttribute,
3287 Updatable: updatableAttribute,
3288 Installable: installableAttribute,
3289 Native_shared_libs: nativeSharedLibsLabelListAttribute,
3290 Binaries: binariesStringListAttribute,
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003291 Prebuilts: prebuiltsLabelListAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003292 }
3293
3294 props := bazel.BazelTargetModuleProperties{
3295 Rule_class: "apex",
3296 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3297 }
3298
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +00003299 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003300}