blob: d898cbfdca73832f5028b3f46e0c5cf6b092abbd [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 Parkf4020582021-11-29 12:37:10 +0900133 // Marks that this APEX is designed to be updatable in the future, although it's not
134 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
135 // updatable APEXes. Currently, this disables the size optimization, so that the size of
136 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
137 // false.
138 Future_updatable *bool
139
Jiyong Park1bc84122021-06-22 20:23:05 +0900140 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
141 // false`. Default is false.
142 Platform_apis *bool
143
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900144 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
145 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900146 Installable *bool
147
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000148 // Whether this APEX can be compressed or not. Setting this property to false means this
149 // APEX will never be compressed. When set to true, APEX will be compressed if other
150 // conditions, e.g, target device needs to support APEX compression, are also fulfilled.
151 // Default: true.
152 Compressible *bool
153
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900154 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
155 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
156 Use_vndk_as_stable *bool
157
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000158 // Whether this is multi-installed APEX should skip installing symbol files.
159 // Multi-installed APEXes share the same apex_name and are installed at the same time.
160 // Default is false.
161 //
162 // Should be set to true for all multi-installed APEXes except the singular
163 // default version within the multi-installed group.
164 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
165 // or else conflicting build rules may be created.
166 Multi_install_skip_symbol_files *bool
167
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900168 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
169 // `name#version` or `name` which is an alias for `name#current`. If left empty,
170 // `platform#current` is implied. This value affects all modules included in this APEX. In
171 // other words, they are also built with the SDKs specified here.
172 Uses_sdks []string
173
174 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
175 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
176 // container. When set to zip, contents are stored in a zip container directly. This type is
177 // mostly for host-side debugging. When set to both, the two types are both built. Default
178 // is 'image'.
179 Payload_type *string
180
Huang Jianan13cac632021-08-02 15:02:17 +0800181 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
182 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900183 Payload_fs_type *string
184
185 // For telling the APEX to ignore special handling for system libraries such as bionic.
186 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900187 Ignore_system_library_special_case *bool
188
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100189 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100190 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100191 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900192
193 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
194 // used in tests.
195 Test_only_unsigned_payload *bool
196
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000197 // Whenever apex should be compressed, regardless of product flag used. Should be only
198 // used in tests.
199 Test_only_force_compression *bool
200
Jooyung Han09c11ad2021-10-27 03:45:31 +0900201 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
202 // with the tool to sign payload contents.
203 Custom_sign_tool *string
204
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100205 // Canonical name of this APEX bundle. Used to determine the path to the
206 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
207 // apex mutator variations. For override_apex modules, this is the name of the
208 // overridden base module.
209 ApexVariationName string `blueprint:"mutated"`
210
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900211 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900212
213 // List of sanitizer names that this APEX is enabled for
214 SanitizerNames []string `blueprint:"mutated"`
215
216 PreventInstall bool `blueprint:"mutated"`
217
218 HideFromMake bool `blueprint:"mutated"`
219
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900220 // Internal package method for this APEX. When payload_type is image, this can be either
221 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
222 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900223 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900224}
225
226type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900227 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900228 Native_shared_libs []string
229
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900230 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900231 Jni_libs []string
232
Jiyong Park99644e92020-11-17 22:21:02 +0900233 // List of rust dyn libraries
234 Rust_dyn_libs []string
235
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900236 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900237 Binaries []string
238
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900239 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900240 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900241
242 // List of filesystem images that are embedded inside this APEX bundle.
243 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900244}
245
246type apexMultilibProperties struct {
247 // Native dependencies whose compile_multilib is "first"
248 First ApexNativeDependencies
249
250 // Native dependencies whose compile_multilib is "both"
251 Both ApexNativeDependencies
252
253 // Native dependencies whose compile_multilib is "prefer32"
254 Prefer32 ApexNativeDependencies
255
256 // Native dependencies whose compile_multilib is "32"
257 Lib32 ApexNativeDependencies
258
259 // Native dependencies whose compile_multilib is "64"
260 Lib64 ApexNativeDependencies
261}
262
263type apexTargetBundleProperties struct {
264 Target struct {
265 // Multilib properties only for android.
266 Android struct {
267 Multilib apexMultilibProperties
268 }
269
270 // Multilib properties only for host.
271 Host struct {
272 Multilib apexMultilibProperties
273 }
274
275 // Multilib properties only for host linux_bionic.
276 Linux_bionic struct {
277 Multilib apexMultilibProperties
278 }
279
280 // Multilib properties only for host linux_glibc.
281 Linux_glibc struct {
282 Multilib apexMultilibProperties
283 }
284 }
285}
286
Jiyong Park59140302020-12-14 18:44:04 +0900287type apexArchBundleProperties struct {
288 Arch struct {
289 Arm struct {
290 ApexNativeDependencies
291 }
292 Arm64 struct {
293 ApexNativeDependencies
294 }
295 X86 struct {
296 ApexNativeDependencies
297 }
298 X86_64 struct {
299 ApexNativeDependencies
300 }
301 }
302}
303
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900304// These properties can be used in override_apex to override the corresponding properties in the
305// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900306type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900307 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900308 Apps []string
309
Daniel Norman5a3ce132021-08-26 15:44:43 -0700310 // List of prebuilt files that are embedded inside this APEX bundle.
311 Prebuilts []string
312
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900313 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900314 Rros []string
315
markchien7c803b82021-08-26 22:10:06 +0800316 // List of BPF programs inside this APEX bundle.
317 Bpfs []string
318
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900319 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
320 // Soong). This does not completely prevent installation of the overridden binaries, but if
321 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
322 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900323 Overrides []string
324
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900325 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900326 Logging_parent string
327
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900328 // Apex Container package name. Override value for attribute package:name in
329 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900330 Package_name string
331
332 // A txt file containing list of files that are allowed to be included in this APEX.
333 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700334
335 // Name of the apex_key module that provides the private key to sign this APEX bundle.
336 Key *string
337
338 // Specifies the certificate and the private key to sign the zip container of this APEX. If
339 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
340 // as the certificate and the private key, respectively. If this is ":module", then the
341 // certificate and the private key are provided from the android_app_certificate module
342 // named "module".
343 Certificate *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900344}
345
346type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900347 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900348 android.ModuleBase
349 android.DefaultableModuleBase
350 android.OverridableModuleBase
351 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400352 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900353
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900354 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900355 properties apexBundleProperties
356 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900357 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900358 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900359 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900360
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900361 ///////////////////////////////////////////////////////////////////////////////////////////
362 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900364 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800365 publicKeyFile android.Path
366 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900367
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900368 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800369 containerCertificateFile android.Path
370 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900372 // Flags for special variants of APEX
373 testApex bool
374 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900375
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
377 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900378 primaryApexType bool
379
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900380 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381 suffix string
382
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900383 // File system type of apex_payload.img
384 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900386 // Whether to create symlink to the system file instead of having a file inside the apex or
387 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900388 linkToSystemLib bool
389
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900390 // List of files to be included in this APEX. This is filled in the first part of
391 // GenerateAndroidBuildActions.
392 filesInfo []apexFile
393
394 // List of other module names that should be installed when this APEX gets installed.
395 requiredDeps []string
396
397 ///////////////////////////////////////////////////////////////////////////////////////////
398 // Outputs (final and intermediates)
399
400 // Processed apex manifest in JSONson format (for Q)
401 manifestJsonOut android.WritablePath
402
403 // Processed apex manifest in PB format (for R+)
404 manifestPbOut android.WritablePath
405
406 // Processed file_contexts files
407 fileContexts android.WritablePath
408
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900409 // Struct holding the merged notice file paths in different formats
410 mergedNotices android.NoticeOutputs
411
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900412 // The built APEX file. This is the main product.
413 outputFile android.WritablePath
414
415 // The built APEX file in app bundle format. This file is not directly installed to the
416 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
417 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
418 // system) to be merged into a single app bundle file that Play accepts. See
419 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
420 bundleModuleFile android.WritablePath
421
Colin Cross6340ea52021-11-04 12:01:18 -0700422 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900423 installDir android.InstallPath
424
Colin Cross6340ea52021-11-04 12:01:18 -0700425 // Path where this APEX was installed.
426 installedFile android.InstallPath
427
428 // Installed locations of symlinks for backward compatibility.
429 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900430
431 // Text file having the list of individual files that are included in this APEX. Used for
432 // debugging purpose.
433 installedFilesFile android.WritablePath
434
435 // List of module names that this APEX is including (to be shown via *-deps-info target).
436 // Used for debugging purpose.
437 android.ApexBundleDepsInfo
438
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900439 // Optional list of lint report zip files for apexes that contain java or app modules
440 lintReports android.Paths
441
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900442 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000443
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000444 isCompressed bool
445
sophiezc80a2b32020-11-12 16:39:19 +0000446 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700447 nativeApisUsedByModuleFile android.ModuleOutPath
448 nativeApisBackedByModuleFile android.ModuleOutPath
449 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800450
451 // Collect the module directory for IDE info in java/jdeps.go.
452 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900453}
454
Colin Cross6340ea52021-11-04 12:01:18 -0700455func (*apexBundle) InstallBypassMake() bool {
456 return true
457}
458
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900459// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900460type apexFileClass int
461
Jooyung Han72bd2f82019-10-23 16:46:38 +0900462const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900463 app apexFileClass = iota
464 appSet
465 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900466 goBinary
467 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900468 nativeExecutable
469 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900470 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900471 pyBinary
472 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900473)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900474
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900475// apexFile represents a file in an APEX bundle. This is created during the first half of
476// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
477// of the function, this is used to create commands that copies the files into a staging directory,
478// where they are packaged into the APEX file. This struct is also used for creating Make modules
479// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900480type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900481 // buildFile is put in the installDir inside the APEX.
482 builtFile android.Path
483 noticeFiles android.Paths
484 installDir string
485 customStem string
486 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900487
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900488 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
489 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
490 // suffix>]
491 androidMkModuleName string // becomes LOCAL_MODULE
492 class apexFileClass // becomes LOCAL_MODULE_CLASS
493 moduleDir string // becomes LOCAL_PATH
494 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
495 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
496 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
497 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900498
499 jacocoReportClassesFile android.Path // only for javalibs and apps
500 lintDepSets java.LintDepSets // only for javalibs and apps
501 certificate java.Certificate // only for apps
502 overriddenPackageName string // only for apps
503
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900504 transitiveDep bool
505 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900506
Jiyong Park57621b22021-01-20 20:33:11 +0900507 multilib string
508
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900509 // TODO(jiyong): remove this
510 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900511}
512
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900513// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900514func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
515 ret := apexFile{
516 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900517 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900518 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900519 class: class,
520 module: module,
521 }
522 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900523 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900524 ret.moduleDir = ctx.OtherModuleDir(module)
525 ret.requiredModuleNames = module.RequiredModuleNames()
526 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
527 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900528 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900529 }
530 return ret
531}
532
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900533func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900534 return af.builtFile != nil && af.builtFile.String() != ""
535}
536
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900537// apexRelativePath returns the relative path of the given path from the install directory of this
538// apexFile.
539// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900540func (af *apexFile) apexRelativePath(path string) string {
541 return filepath.Join(af.installDir, path)
542}
543
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900544// path returns path of this apex file relative to the APEX root
545func (af *apexFile) path() string {
546 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900547}
548
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900549// stem returns the base filename of this apex file
550func (af *apexFile) stem() string {
551 if af.customStem != "" {
552 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900553 }
554 return af.builtFile.Base()
555}
556
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900557// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
558func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900559 var ret []string
560 for _, symlink := range af.symlinks {
561 ret = append(ret, af.apexRelativePath(symlink))
562 }
563 return ret
564}
565
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900566// availableToPlatform tests whether this apexFile is from a module that can be installed to the
567// platform.
568func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900569 if af.module == nil {
570 return false
571 }
572 if am, ok := af.module.(android.ApexModule); ok {
573 return am.AvailableFor(android.AvailableToPlatform)
574 }
575 return false
576}
577
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900578////////////////////////////////////////////////////////////////////////////////////////////////////
579// Mutators
580//
581// Brief description about mutators for APEX. The following three mutators are the most important
582// ones.
583//
584// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
585// to the (direct) dependencies of this APEX bundle.
586//
Paul Duffin949abc02020-12-08 10:34:30 +0000587// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900588// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
589// modules are marked as being included in the APEX via BuildForApex().
590//
Paul Duffin949abc02020-12-08 10:34:30 +0000591// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
592// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900593
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900594type dependencyTag struct {
595 blueprint.BaseDependencyTag
596 name string
597
598 // Determines if the dependent will be part of the APEX payload. Can be false for the
599 // dependencies to the signing key module, etc.
600 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000601
602 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
603 // replacement. This is needed because some prebuilt modules do not provide all the information
604 // needed by the apex.
605 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900606}
607
Paul Duffin8c535da2021-03-17 14:51:03 +0000608func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
609 return !d.sourceOnly
610}
611
612var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
613
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900614var (
Paul Duffin0b817782021-03-17 15:02:19 +0000615 androidAppTag = dependencyTag{name: "androidApp", payload: true}
616 bpfTag = dependencyTag{name: "bpf", payload: true}
617 certificateTag = dependencyTag{name: "certificate"}
618 executableTag = dependencyTag{name: "executable", payload: true}
619 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100620 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100621 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000622 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000623 javaLibTag = dependencyTag{name: "javaLib", payload: true}
624 jniLibTag = dependencyTag{name: "jniLib", payload: true}
625 keyTag = dependencyTag{name: "key"}
626 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
627 rroTag = dependencyTag{name: "rro", payload: true}
628 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
629 testForTag = dependencyTag{name: "test for"}
630 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000631 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900632)
633
634// TODO(jiyong): shorten this function signature
635func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900636 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900637 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900638 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900639
640 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900641 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900642 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
643 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900644 }
645
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900646 // Use *FarVariation* to be able to depend on modules having conflicting variations with
647 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
648 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900649 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900650 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900651 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
652 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900653 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900654 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900655}
656
657func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900658 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900659 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
660 } else {
661 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
662 if ctx.Os().Bionic() {
663 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
664 } else {
665 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
666 }
667 }
668}
669
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900670// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
671// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
672func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
673 deviceConfig := ctx.DeviceConfig()
674 if a.vndkApex {
675 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900676 }
677
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900678 var prefix string
679 var vndkVersion string
680 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000681 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900682 prefix = cc.VendorVariationPrefix
683 vndkVersion = deviceConfig.VndkVersion()
684 } else if a.ProductSpecific() {
685 prefix = cc.ProductVariationPrefix
686 vndkVersion = deviceConfig.ProductVndkVersion()
687 }
688 }
689 if vndkVersion == "current" {
690 vndkVersion = deviceConfig.PlatformVndkVersion()
691 }
692 if vndkVersion != "" {
693 return prefix + vndkVersion
694 }
695
696 return android.CoreVariation // The usual case
697}
698
699func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900700 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
701 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
702 // each target os/architectures, appropriate dependencies are selected by their
703 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900704 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900705 imageVariation := a.getImageVariation(ctx)
706
707 a.combineProperties(ctx)
708
709 has32BitTarget := false
710 for _, target := range targets {
711 if target.Arch.ArchType.Multilib == "lib32" {
712 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000713 }
714 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900715 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900716 // Don't include artifacts for the host cross targets because there is no way for us
717 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900718 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900719 continue
720 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000721
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900722 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000723
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900724 // Add native modules targeting both ABIs. When multilib.* is omitted for
725 // native_shared_libs/jni_libs/tests, it implies multilib.both
726 depsList = append(depsList, a.properties.Multilib.Both)
727 depsList = append(depsList, ApexNativeDependencies{
728 Native_shared_libs: a.properties.Native_shared_libs,
729 Tests: a.properties.Tests,
730 Jni_libs: a.properties.Jni_libs,
731 Binaries: nil,
732 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900733
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900734 // Add native modules targeting the first ABI When multilib.* is omitted for
735 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900736 isPrimaryAbi := i == 0
737 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900738 depsList = append(depsList, a.properties.Multilib.First)
739 depsList = append(depsList, ApexNativeDependencies{
740 Native_shared_libs: nil,
741 Tests: nil,
742 Jni_libs: nil,
743 Binaries: a.properties.Binaries,
744 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900745 }
746
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900747 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900748 switch target.Arch.ArchType.Multilib {
749 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900750 depsList = append(depsList, a.properties.Multilib.Lib32)
751 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900752 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900753 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900754 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900755 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900756 }
757 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900758
Jiyong Park59140302020-12-14 18:44:04 +0900759 // Add native modules targeting a specific arch variant
760 switch target.Arch.ArchType {
761 case android.Arm:
762 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
763 case android.Arm64:
764 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
765 case android.X86:
766 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
767 case android.X86_64:
768 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
769 default:
770 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
771 }
772
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900773 for _, d := range depsList {
774 addDependenciesForNativeModules(ctx, d, target, imageVariation)
775 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000776 ctx.AddFarVariationDependencies([]blueprint.Variation{
777 {Mutator: "os", Variation: target.OsVariation()},
778 {Mutator: "arch", Variation: target.ArchVariation()},
779 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900780 }
781
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900782 // Common-arch dependencies come next
783 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100784 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100785 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900786 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900787 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000788 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900790 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
791 // This field currently isn't used.
792 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900793 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
794 if len(a.properties.Uses_sdks) > 0 {
795 sdkRefs := []android.SdkRef{}
796 for _, str := range a.properties.Uses_sdks {
797 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
798 sdkRefs = append(sdkRefs, parsed)
799 }
800 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100801 }
802}
803
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900804// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900805func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
806 if a.overridableProperties.Allowed_files != nil {
807 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100808 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900809
810 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
811 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800812 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900813 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700814 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
815 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
816 // regardless of the TARGET_PREFER_* setting. See b/144532908
817 arches := ctx.DeviceConfig().Arches()
818 if len(arches) != 0 {
819 archForPrebuiltEtc := arches[0]
820 for _, arch := range arches {
821 // Prefer 64-bit arch if there is any
822 if arch.ArchType.Multilib == "lib64" {
823 archForPrebuiltEtc = arch
824 break
825 }
826 }
827 ctx.AddFarVariationDependencies([]blueprint.Variation{
828 {Mutator: "os", Variation: ctx.Os().String()},
829 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
830 }, prebuiltTag, prebuilts...)
831 }
832 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700833
834 // Dependencies for signing
835 if String(a.overridableProperties.Key) == "" {
836 ctx.PropertyErrorf("key", "missing")
837 return
838 }
839 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
840
841 cert := android.SrcIsModule(a.getCertString(ctx))
842 if cert != "" {
843 ctx.AddDependency(ctx.Module(), certificateTag, cert)
844 // empty cert is not an error. Cert and private keys will be directly found under
845 // PRODUCT_DEFAULT_DEV_CERTIFICATE
846 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100847}
848
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900849type ApexBundleInfo struct {
850 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100851}
852
Paul Duffin949abc02020-12-08 10:34:30 +0000853var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900854
Paul Duffina7d6a892020-12-07 17:39:59 +0000855var _ ApexInfoMutator = (*apexBundle)(nil)
856
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100857func (a *apexBundle) ApexVariationName() string {
858 return a.properties.ApexVariationName
859}
860
Paul Duffina7d6a892020-12-07 17:39:59 +0000861// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900862// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
863// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
864// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
865// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000866//
867// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
868// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
869// The apexMutator uses that list to create module variants for the apexes to which it belongs.
870// The relationship between module variants and apexes is not one-to-one as variants will be
871// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000872func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900873
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900874 // The VNDK APEX is special. For the APEX, the membership is described in a very different
875 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
876 // libraries are self-identified by their vndk.enabled properties. There is no need to run
877 // this mutator for the APEX as nothing will be collected. So, let's return fast.
878 if a.vndkApex {
879 return
880 }
881
882 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
883 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
884 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
885 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
886 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900887 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
888 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
889 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
890 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
891 return
892 }
893
Colin Cross56a83212020-09-15 18:30:11 -0700894 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900895 am, ok := child.(android.ApexModule)
896 if !ok || !am.CanHaveApexVariants() {
897 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900898 }
Paul Duffin573989d2021-03-17 13:25:29 +0000899 depTag := mctx.OtherModuleDependencyTag(child)
900
901 // Check to see if the tag always requires that the child module has an apex variant for every
902 // apex variant of the parent module. If it does not then it is still possible for something
903 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
904 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
905 return true
906 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000907 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900908 return false
909 }
Jooyung Handf78e212020-07-22 15:54:47 +0900910 if excludeVndkLibs {
911 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
912 return false
913 }
914 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900915 // By default, all the transitive dependencies are collected, unless filtered out
916 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700917 return true
918 }
919
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900920 // Records whether a certain module is included in this apexBundle via direct dependency or
921 // inndirect dependency.
922 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700923 mctx.WalkDeps(func(child, parent android.Module) bool {
924 if !continueApexDepsWalk(child, parent) {
925 return false
926 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900927 // If the parent is apexBundle, this child is directly depended.
928 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900929 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700930 contents[depName] = contents[depName].Add(directDep)
931 return true
932 })
933
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900934 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900935 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700936 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
937 Contents: apexContents,
938 })
939
Jooyung Haned124c32021-01-26 11:43:46 +0900940 minSdkVersion := a.minSdkVersion(mctx)
941 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
942 if minSdkVersion.IsNone() {
943 minSdkVersion = android.FutureApiLevel
944 }
945
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900946 // This is the main part of this mutator. Mark the collected dependencies that they need to
947 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900948
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100949 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
950 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700951 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100952 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900953 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700954 RequiredSdks: a.RequiredSdks(),
955 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900956 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100957 InApexVariants: []string{apexVariationName},
958 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700959 ApexContents: []*android.ApexContents{apexContents},
960 }
Colin Cross56a83212020-09-15 18:30:11 -0700961 mctx.WalkDeps(func(child, parent android.Module) bool {
962 if !continueApexDepsWalk(child, parent) {
963 return false
964 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900965 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900966 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900967 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900968}
969
Paul Duffina7d6a892020-12-07 17:39:59 +0000970type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100971 // ApexVariationName returns the name of the APEX variation to use in the apex
972 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
973 ApexVariationName() string
974
Paul Duffina7d6a892020-12-07 17:39:59 +0000975 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
976 // depended upon by an apex and which require an apex specific variant.
977 ApexInfoMutator(android.TopDownMutatorContext)
978}
979
980// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
981// specific variant to modules that support the ApexInfoMutator.
982func apexInfoMutator(mctx android.TopDownMutatorContext) {
983 if !mctx.Module().Enabled() {
984 return
985 }
986
987 if a, ok := mctx.Module().(ApexInfoMutator); ok {
988 a.ApexInfoMutator(mctx)
989 return
990 }
991}
992
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900993// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
994// unique apex variations for this module. See android/apex.go for more about unique apex variant.
995// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700996func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
997 if !mctx.Module().Enabled() {
998 return
999 }
1000 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001001 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1002 }
1003}
1004
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001005// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1006// the apex in order to retrieve its contents later.
1007// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001008func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1009 if !mctx.Module().Enabled() {
1010 return
1011 }
Colin Cross56a83212020-09-15 18:30:11 -07001012 if am, ok := mctx.Module().(android.ApexModule); ok {
1013 if testFor := am.TestFor(); len(testFor) > 0 {
1014 mctx.AddFarVariationDependencies([]blueprint.Variation{
1015 {Mutator: "os", Variation: am.Target().OsVariation()},
1016 {"arch", "common"},
1017 }, testForTag, testFor...)
1018 }
1019 }
1020}
1021
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001022// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001023func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1024 if !mctx.Module().Enabled() {
1025 return
1026 }
Colin Cross56a83212020-09-15 18:30:11 -07001027 if _, ok := mctx.Module().(android.ApexModule); ok {
1028 var contents []*android.ApexContents
1029 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1030 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1031 contents = append(contents, abInfo.Contents)
1032 }
1033 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1034 ApexContents: contents,
1035 })
Colin Crossaede88c2020-08-11 12:17:01 -07001036 }
1037}
1038
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001039// markPlatformAvailability marks whether or not a module can be available to platform. A module
1040// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1041// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1042// be) available to platform
1043// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001044func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1045 // Host and recovery are not considered as platform
1046 if mctx.Host() || mctx.Module().InstallInRecovery() {
1047 return
1048 }
1049
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001050 am, ok := mctx.Module().(android.ApexModule)
1051 if !ok {
1052 return
1053 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001054
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001055 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001056
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001057 // If any of the dep is not available to platform, this module is also considered as being
1058 // not available to platform even if it has "//apex_available:platform"
1059 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001060 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001061 // if the dependency crosses apex boundary, don't consider it
1062 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001063 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001064 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1065 availableToPlatform = false
1066 // TODO(b/154889534) trigger an error when 'am' has
1067 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001068 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001069 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001070
Paul Duffinb5769c12021-05-12 16:16:51 +01001071 // Exception 1: check to see if the module always requires it.
1072 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001073 availableToPlatform = true
1074 }
1075
1076 // Exception 2: bootstrap bionic libraries are also always available to platform
1077 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1078 availableToPlatform = true
1079 }
1080
1081 if !availableToPlatform {
1082 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001083 }
1084}
1085
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001086// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001087// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001088func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001089 if !mctx.Module().Enabled() {
1090 return
1091 }
Colin Cross56a83212020-09-15 18:30:11 -07001092
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001093 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001094 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001095 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001096 return
1097 }
1098
1099 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001100 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1101 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001102 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001103 if strings.HasPrefix(apexBundleName, "com.android.art") {
1104 // Create an alias from the platform variant. This is done to make
1105 // test_for dependencies work for modules that are split by the APEX
1106 // mutator, since test_for dependencies always go to the platform variant.
1107 // This doesn't happen for normal APEXes that are disjunct, so only do
1108 // this for the overlapping ART APEXes.
1109 // TODO(b/183882457): Remove this if the test_for functionality is
1110 // refactored to depend on the proper APEX variants instead of platform.
1111 mctx.CreateAliasVariation("", apexBundleName)
1112 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001113 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1114 apexBundleName := o.GetOverriddenModuleName()
1115 if apexBundleName == "" {
1116 mctx.ModuleErrorf("base property is not set")
1117 return
1118 }
1119 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001120 if strings.HasPrefix(apexBundleName, "com.android.art") {
1121 // TODO(b/183882457): See note for CreateAliasVariation above.
1122 mctx.CreateAliasVariation("", apexBundleName)
1123 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001124 }
1125}
Sundong Ahne9b55722019-09-06 17:37:42 +09001126
Paul Duffin6717d882021-06-15 19:09:41 +01001127// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1128// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001129func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001130 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001131 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001132 return !a.vndkApex
1133 }
1134
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001135 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001136}
1137
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001138// See android.UpdateDirectlyInAnyApex
1139// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001140func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1141 if !mctx.Module().Enabled() {
1142 return
1143 }
1144 if am, ok := mctx.Module().(android.ApexModule); ok {
1145 android.UpdateDirectlyInAnyApex(mctx, am)
1146 }
1147}
1148
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001149// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001150type apexPackaging int
1151
1152const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001153 // imageApex is a packaging method where contents are included in a filesystem image which
1154 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001155 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001156
1157 // zipApex is a packaging method where contents are directly included in the zip container.
1158 // This is used for host-side testing - because the contents are easily accessible by
1159 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001160 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001161
1162 // flattendApex is a packaging method where contents are not included in the APEX file, but
1163 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1164 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001165 flattenedApex
1166)
1167
1168const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001169 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001170 imageApexSuffix = ".apex"
1171 imageCapexSuffix = ".capex"
1172 zipApexSuffix = ".zipapex"
1173 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001174
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001175 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001176 imageApexType = "image"
1177 zipApexType = "zip"
1178 flattenedApexType = "flattened"
1179
Dan Willemsen47e1a752021-10-16 18:36:13 -07001180 ext4FsType = "ext4"
1181 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001182 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001183)
1184
1185// The suffix for the output "file", not the module
1186func (a apexPackaging) suffix() string {
1187 switch a {
1188 case imageApex:
1189 return imageApexSuffix
1190 case zipApex:
1191 return zipApexSuffix
1192 default:
1193 panic(fmt.Errorf("unknown APEX type %d", a))
1194 }
1195}
1196
1197func (a apexPackaging) name() string {
1198 switch a {
1199 case imageApex:
1200 return imageApexType
1201 case zipApex:
1202 return zipApexType
1203 default:
1204 panic(fmt.Errorf("unknown APEX type %d", a))
1205 }
1206}
1207
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001208// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1209// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001210func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001211 if !mctx.Module().Enabled() {
1212 return
1213 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001214 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001215 var variants []string
1216 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1217 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001218 // This is the normal case. Note that both image and flattend APEXes are
1219 // created. The image type is installed to the system partition, while the
1220 // flattened APEX is (optionally) installed to the system_ext partition.
1221 // This is mostly for GSI which has to support wide range of devices. If GSI
1222 // is installed on a newer (APEX-capable) device, the image APEX in the
1223 // system will be used. However, if the same GSI is installed on an old
1224 // device which can't support image APEX, the flattened APEX in the
1225 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001226 variants = append(variants, imageApexType, flattenedApexType)
1227 case "zip":
1228 variants = append(variants, zipApexType)
1229 case "both":
1230 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1231 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001232 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001233 return
1234 }
1235
1236 modules := mctx.CreateLocalVariations(variants...)
1237
1238 for i, v := range variants {
1239 switch v {
1240 case imageApexType:
1241 modules[i].(*apexBundle).properties.ApexType = imageApex
1242 case zipApexType:
1243 modules[i].(*apexBundle).properties.ApexType = zipApex
1244 case flattenedApexType:
1245 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001247 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001248 modules[i].(*apexBundle).MakeAsSystemExt()
1249 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001250 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001251 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001252 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001253 // payload_type is forcibly overridden to "image"
1254 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001255 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001256 }
1257}
1258
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001259var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001260
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001261// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001262func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1263 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001264 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001265 return true
1266}
1267
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001268var _ android.OutputFileProducer = (*apexBundle)(nil)
1269
1270// Implements android.OutputFileProducer
1271func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1272 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001273 case "", android.DefaultDistTag:
1274 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001275 return android.Paths{a.outputFile}, nil
1276 default:
1277 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1278 }
1279}
1280
1281var _ cc.Coverage = (*apexBundle)(nil)
1282
1283// Implements cc.Coverage
1284func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1285 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1286}
1287
1288// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001289func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001290 a.properties.PreventInstall = true
1291}
1292
1293// Implements cc.Coverage
1294func (a *apexBundle) HideFromMake() {
1295 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001296 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1297 // TODO(ccross): untangle these
1298 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001299}
1300
1301// Implements cc.Coverage
1302func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1303 a.properties.IsCoverageVariant = coverage
1304}
1305
1306// Implements cc.Coverage
1307func (a *apexBundle) EnableCoverageIfNeeded() {}
1308
1309var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1310
1311// Implements android.ApexBudleDepsInfoIntf
1312func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001313 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001314}
1315
Jiyong Parkf4020582021-11-29 12:37:10 +09001316func (a *apexBundle) FutureUpdatable() bool {
1317 return proptools.BoolDefault(a.properties.Future_updatable, false)
1318}
1319
Jiyong Park1bc84122021-06-22 20:23:05 +09001320func (a *apexBundle) UsePlatformApis() bool {
1321 return proptools.BoolDefault(a.properties.Platform_apis, false)
1322}
1323
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001324// getCertString returns the name of the cert that should be used to sign this APEX. This is
1325// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001326func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001327 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001328 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1329 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1330 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001331 if a.vndkApex {
1332 moduleName = vndkApexName
1333 }
1334 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001335 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001336 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001337 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001338 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001339}
1340
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001341// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001342func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001343 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001344}
1345
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001346// See the generate_hashtree property
1347func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001348 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001349}
1350
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001351// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001352func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1353 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1354}
1355
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001356// See the test_only_force_compression property
1357func (a *apexBundle) testOnlyShouldForceCompression() bool {
1358 return proptools.Bool(a.properties.Test_only_force_compression)
1359}
1360
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001361// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1362// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1363// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001364
Jiyong Parkf97782b2019-02-13 20:28:58 +09001365func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1366 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1367 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1368 }
1369}
1370
Jiyong Park388ef3f2019-01-28 19:47:32 +09001371func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001372 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1373 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001374 }
1375
1376 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001377 globalSanitizerNames := []string{}
1378 if a.Host() {
1379 globalSanitizerNames = ctx.Config().SanitizeHost()
1380 } else {
1381 arches := ctx.Config().SanitizeDeviceArch()
1382 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1383 globalSanitizerNames = ctx.Config().SanitizeDevice()
1384 }
1385 }
1386 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001387}
1388
Jooyung Han8ce8db92020-05-15 19:05:05 +09001389func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001390 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1391 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001392 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001393 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001394 for _, target := range ctx.MultiTargets() {
1395 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001396 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1397 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1398 Tests: nil,
1399 Jni_libs: nil,
1400 Binaries: nil,
1401 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001402 break
1403 }
1404 }
1405 }
1406}
1407
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001408// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1409// returned apexFile saves information about the Soong module that will be used for creating the
1410// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001411func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001412 // Decide the APEX-local directory by the multilib of the library In the future, we may
1413 // query this to the module.
1414 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001415 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001416 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001417 case "lib32":
1418 dirInApex = "lib"
1419 case "lib64":
1420 dirInApex = "lib64"
1421 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001422 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001423 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001424 }
Jooyung Han35155c42020-02-06 17:33:20 +09001425 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001426 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001427 // Special case for Bionic libs and other libs installed with them. This is to
1428 // prevent those libs from being included in the search path
1429 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1430 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1431 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1432 // will be loaded into the default linker namespace (aka "platform" namespace). If
1433 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1434 // be loaded again into the runtime linker namespace, which will result in double
1435 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001436 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001437 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001438
Jiyong Parkf653b052019-11-18 15:39:01 +09001439 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001440 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1441 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001442}
1443
Jiyong Park1833cef2019-12-13 13:28:36 +09001444func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001445 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001446 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001447 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001448 }
Jooyung Han35155c42020-02-06 17:33:20 +09001449 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001450 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001451 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1452 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001453 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001454 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001455 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001456}
1457
Jiyong Park99644e92020-11-17 22:21:02 +09001458func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1459 dirInApex := "bin"
1460 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1461 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1462 }
1463 fileToCopy := rustm.OutputFile().Path()
1464 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1465 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1466 return af
1467}
1468
1469func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1470 // Decide the APEX-local directory by the multilib of the library
1471 // In the future, we may query this to the module.
1472 var dirInApex string
1473 switch rustm.Arch().ArchType.Multilib {
1474 case "lib32":
1475 dirInApex = "lib"
1476 case "lib64":
1477 dirInApex = "lib64"
1478 }
1479 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1480 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1481 }
1482 fileToCopy := rustm.OutputFile().Path()
1483 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1484 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1485}
1486
Jiyong Park1833cef2019-12-13 13:28:36 +09001487func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001488 dirInApex := "bin"
1489 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001490 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001491}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001492
Jiyong Park1833cef2019-12-13 13:28:36 +09001493func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001494 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001495 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001496 // NB: Since go binaries are static we don't need the module for anything here, which is
1497 // good since the go tool is a blueprint.Module not an android.Module like we would
1498 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001499 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001500}
1501
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001502func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001503 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001504 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1505 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1506 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001507 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001508 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001509 af.symlinks = sh.Symlinks()
1510 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001511}
1512
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001513func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001514 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001515 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001516 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001517}
1518
atrost6e126252020-01-27 17:01:16 +00001519func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1520 dirInApex := filepath.Join("etc", config.SubDir())
1521 fileToCopy := config.CompatConfig()
1522 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1523}
1524
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001525// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1526// way.
1527type javaModule interface {
1528 android.Module
1529 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001530 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001531 JacocoReportClassesFile() android.Path
1532 LintDepSets() java.LintDepSets
1533 Stem() string
1534}
1535
1536var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001537var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001538var _ javaModule = (*java.SdkLibrary)(nil)
1539var _ javaModule = (*java.DexImport)(nil)
1540var _ javaModule = (*java.SdkLibraryImport)(nil)
1541
Paul Duffin190fdef2021-04-26 10:33:59 +01001542// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001543func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001544 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001545}
1546
1547// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1548func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001549 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001550 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001551 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1552 af.lintDepSets = module.LintDepSets()
1553 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001554 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1555 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1556 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1557 }
1558 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001559 return af
1560}
1561
1562// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1563// the same way.
1564type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001565 android.Module
1566 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001567 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001568 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001569 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001570 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001571 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001572 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001573}
1574
1575var _ androidApp = (*java.AndroidApp)(nil)
1576var _ androidApp = (*java.AndroidAppImport)(nil)
1577
1578func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001579 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001580 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001581 appDir = "priv-app"
1582 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001583 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001584 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001585 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001586 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001587 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001588 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001589
1590 if app, ok := aapp.(interface {
1591 OverriddenManifestPackageName() string
1592 }); ok {
1593 af.overriddenPackageName = app.OverriddenManifestPackageName()
1594 }
Jiyong Park618922e2020-01-08 13:35:43 +09001595 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001596}
1597
Jiyong Park69aeba92020-04-24 21:16:36 +09001598func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1599 rroDir := "overlay"
1600 dirInApex := filepath.Join(rroDir, rro.Theme())
1601 fileToCopy := rro.OutputFile()
1602 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1603 af.certificate = rro.Certificate()
1604
1605 if a, ok := rro.(interface {
1606 OverriddenManifestPackageName() string
1607 }); ok {
1608 af.overriddenPackageName = a.OverriddenManifestPackageName()
1609 }
1610 return af
1611}
1612
markchien2f59ec92020-09-02 16:23:38 +08001613func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1614 dirInApex := filepath.Join("etc", "bpf")
1615 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1616}
1617
Jiyong Park12a719c2021-01-07 15:31:24 +09001618func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1619 dirInApex := filepath.Join("etc", "fs")
1620 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1621}
1622
Paul Duffin064b70c2020-11-02 17:32:38 +00001623// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001624// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1625// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1626// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001627func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001628 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001629 am, ok := child.(android.ApexModule)
1630 if !ok || !am.CanHaveApexVariants() {
1631 return false
1632 }
1633
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001634 // Filter-out unwanted depedendencies
1635 depTag := ctx.OtherModuleDependencyTag(child)
1636 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1637 return false
1638 }
1639 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001640 return false
1641 }
1642
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001643 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001644 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001645
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001646 // Visit actually
1647 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001648 })
1649}
1650
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001651// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1652type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001653
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001654const (
1655 ext4 fsType = iota
1656 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001657 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001658)
Artur Satayev849f8442020-04-28 14:57:42 +01001659
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001660func (f fsType) string() string {
1661 switch f {
1662 case ext4:
1663 return ext4FsType
1664 case f2fs:
1665 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001666 case erofs:
1667 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001668 default:
1669 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001670 }
1671}
1672
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001673// Creates build rules for an APEX. It consists of the following major steps:
1674//
1675// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1676// 2) traverse the dependency tree to collect apexFile structs from them.
1677// 3) some fields in apexBundle struct are configured
1678// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001679func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001680 ////////////////////////////////////////////////////////////////////////////////////////////
1681 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001682 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001683 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001684 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001685 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001686 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001687 if len(a.properties.Tests) > 0 && !a.testApex {
1688 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1689 return
1690 }
Jiyong Park678c8812020-02-07 17:25:49 +09001691
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001692 ////////////////////////////////////////////////////////////////////////////////////////////
1693 // 2) traverse the dependency tree to collect apexFile structs from them.
1694
1695 // all the files that will be included in this APEX
1696 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001697
Jooyung Hane1633032019-08-01 17:41:43 +09001698 // native lib dependencies
1699 var provideNativeLibs []string
1700 var requireNativeLibs []string
1701
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001702 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1703
braleeb0c1f0c2021-06-07 22:49:13 +08001704 // Collect the module directory for IDE info in java/jdeps.go.
1705 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1706
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001707 // TODO(jiyong): do this using WalkPayloadDeps
1708 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001709 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001710 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001711 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1712 return false
1713 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001714 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1715 return false
1716 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001717 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001718 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001719 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001720 case sharedLibTag, jniLibTag:
1721 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001722 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001723 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1724 fi.isJniLib = isJniLib
1725 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001726 // Collect the list of stub-providing libs except:
1727 // - VNDK libs are only for vendors
1728 // - bootstrap bionic libs are treated as provided by system
1729 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001730 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001731 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001732 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001733 } else if r, ok := child.(*rust.Module); ok {
1734 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001735 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001736 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001737 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001738 propertyName := "native_shared_libs"
1739 if isJniLib {
1740 propertyName = "jni_libs"
1741 }
1742 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001743 }
1744 case executableTag:
1745 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001746 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001747 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001748 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001749 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001750 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001751 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001752 } else if rust, ok := child.(*rust.Module); ok {
1753 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1754 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001755 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001756 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1757 }
1758 case shBinaryTag:
1759 if sh, ok := child.(*sh.ShBinary); ok {
1760 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1761 } else {
1762 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001763 }
Paul Duffin94f19632021-04-20 12:40:07 +01001764 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001765 {
Paul Duffin7771eba2021-04-23 14:25:28 +01001766 if _, ok := child.(*java.BootclasspathFragmentModule); !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001767 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001768 return false
1769 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001770
Paul Duffincc33ec82021-04-25 23:14:55 +01001771 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1772 filesInfo = append(filesInfo, filesToAdd...)
Paul Duffin4d101b62021-03-24 15:42:20 +00001773 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001774 }
satayev333a1732021-05-17 21:35:26 +01001775 case sscpfTag:
1776 {
1777 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1778 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1779 return false
1780 }
satayevb98371c2021-06-15 16:49:50 +01001781 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1782 filesInfo = append(filesInfo, *af)
1783 }
satayev333a1732021-05-17 21:35:26 +01001784 return true
1785 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001786 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001787 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001788 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001789 af := apexFileForJavaModule(ctx, child.(javaModule))
1790 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001791 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1792 return false
1793 }
1794 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001795 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001796 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001797 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001798 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001799 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001800 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001801 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001802 return true // track transitive dependencies
1803 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001804 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001805 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001806 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001807 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1808 appDir := "app"
1809 if ap.Privileged() {
1810 appDir = "priv-app"
1811 }
Yo Chiange8128052020-07-23 20:09:18 +08001812 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001813 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1814 af.certificate = java.PresignedCertificate
1815 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001816 } else {
1817 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1818 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001819 case rroTag:
1820 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1821 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1822 } else {
1823 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1824 }
markchien2f59ec92020-09-02 16:23:38 +08001825 case bpfTag:
1826 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1827 filesToCopy, _ := bpfProgram.OutputFiles("")
1828 for _, bpfFile := range filesToCopy {
1829 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1830 }
1831 } else {
1832 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1833 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001834 case fsTag:
1835 if fs, ok := child.(filesystem.Filesystem); ok {
1836 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1837 } else {
1838 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1839 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001840 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001841 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001842 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001843 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001844 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001845 }
Paul Duffin0b817782021-03-17 15:02:19 +00001846 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001847 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1848 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1849 } else {
1850 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1851 }
Roland Levillain630846d2019-06-26 12:48:34 +01001852 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001853 if ccTest, ok := child.(*cc.Module); ok {
1854 if ccTest.IsTestPerSrcAllTestsVariation() {
1855 // Multiple-output test module (where `test_per_src: true`).
1856 //
1857 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1858 // We do not add this variation to `filesInfo`, as it has no output;
1859 // however, we do add the other variations of this module as indirect
1860 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001861 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001862 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001863 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001864 af.class = nativeTest
1865 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001866 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001867 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001868 } else {
1869 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1870 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001871 case keyTag:
1872 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001873 a.privateKeyFile = key.privateKeyFile
1874 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001875 } else {
1876 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001877 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001878 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001879 case certificateTag:
1880 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001881 a.containerCertificateFile = dep.Certificate.Pem
1882 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001883 } else {
1884 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1885 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001886 case android.PrebuiltDepTag:
1887 // If the prebuilt is force disabled, remember to delete the prebuilt file
1888 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001889 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001890 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1891 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001892 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001893 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001894 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001895 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001896 // We cannot use a switch statement on `depTag` here as the checked
1897 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001898 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001899 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001900 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001901 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001902 return false
1903 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001904 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1905 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001906
1907 // Always track transitive dependencies for host.
1908 if a.Host() {
1909 filesInfo = append(filesInfo, af)
1910 return true
1911 }
1912
Colin Cross56a83212020-09-15 18:30:11 -07001913 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001914 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001915 // If the dependency is a stubs lib, don't include it in this APEX,
1916 // but make sure that the lib is installed on the device.
1917 // In case no APEX is having the lib, the lib is installed to the system
1918 // partition.
1919 //
1920 // Always include if we are a host-apex however since those won't have any
1921 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001922 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001923 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001924 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001925 if !android.InList(name, a.requiredDeps) {
1926 a.requiredDeps = append(a.requiredDeps, name)
1927 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001928 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001929 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001930 // Don't track further
1931 return false
1932 }
Jiyong Parke3867542020-12-03 17:28:25 +09001933
1934 // If the dep is not considered to be in the same
1935 // apex, don't add it to filesInfo so that it is not
1936 // included in this APEX.
1937 // TODO(jiyong): move this to at the top of the
1938 // else-if clause for the indirect dependencies.
1939 // Currently, that's impossible because we would
1940 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001941 // DepIsInSameAPex is false. We also shouldn't do
1942 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001943 //
1944 // TODO(jiyong): explain why the same module is passed in twice.
1945 // Switching the first am to parent breaks lots of tests.
1946 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001947 return false
1948 }
1949
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 filesInfo = append(filesInfo, af)
1951 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001952 } else if rm, ok := child.(*rust.Module); ok {
1953 af := apexFileForRustLibrary(ctx, rm)
1954 af.transitiveDep = true
1955 filesInfo = append(filesInfo, af)
1956 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001957 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001958 } else if cc.IsTestPerSrcDepTag(depTag) {
1959 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001960 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001961 // Handle modules created as `test_per_src` variations of a single test module:
1962 // use the name of the generated test binary (`fileToCopy`) instead of the name
1963 // of the original test module (`depName`, shared by all `test_per_src`
1964 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001965 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001966 // these are not considered transitive dep
1967 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001968 filesInfo = append(filesInfo, af)
1969 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001970 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001971 } else if cc.IsHeaderDepTag(depTag) {
1972 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001973 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001974 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1975 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001976 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001977 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001978 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1979 }
Jiyong Park99644e92020-11-17 22:21:02 +09001980 } else if rust.IsDylibDepTag(depTag) {
1981 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1982 af := apexFileForRustLibrary(ctx, rustm)
1983 af.transitiveDep = true
1984 filesInfo = append(filesInfo, af)
1985 return true // track transitive dependencies
1986 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09001987 } else if rust.IsRlibDepTag(depTag) {
1988 // Rlib is statically linked, but it might have shared lib
1989 // dependencies. Track them.
1990 return true
Paul Duffin65898052021-04-20 22:47:03 +01001991 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01001992 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00001993 switch child.(type) {
1994 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01001995 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01001996 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00001997 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01001998 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00001999 return false
2000 }
2001 filesInfo = append(filesInfo, af)
2002 return true // track transitive dependencies
2003 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002004 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 +00002005 }
satayev333a1732021-05-17 21:35:26 +01002006 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2007 // Add the contents of the systemserverclasspath fragment to the apex.
2008 switch child.(type) {
2009 case *java.Library, *java.SdkLibrary:
2010 af := apexFileForJavaModule(ctx, child.(javaModule))
2011 filesInfo = append(filesInfo, af)
2012 return true // track transitive dependencies
2013 default:
2014 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2015 }
Colin Cross56a83212020-09-15 18:30:11 -07002016 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2017 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002018 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002019 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002020 }
2021 }
2022 }
2023 return false
2024 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002025 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002026 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002027 return
2028 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002029
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002030 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002031 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002032 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002033 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002034 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002035 if e, ok := encountered[dest]; !ok {
2036 encountered[dest] = f
2037 } else {
2038 // If a module is directly included and also transitively depended on
2039 // consider it as directly included.
2040 e.transitiveDep = e.transitiveDep && f.transitiveDep
2041 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002042 }
2043 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002044 var result []apexFile
2045 for _, v := range encountered {
2046 result = append(result, v)
2047 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002048 return result
2049 }
2050 filesInfo = removeDup(filesInfo)
2051
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002052 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002053 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002054 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2055 // changes.
2056 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002057 })
2058
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002059 ////////////////////////////////////////////////////////////////////////////////////////////
2060 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002061 a.installDir = android.PathForModuleInstall(ctx, "apex")
2062 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002063
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002064 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002065 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002066 switch a.properties.ApexType {
2067 case imageApex:
2068 if buildFlattenedAsDefault {
2069 a.suffix = imageApexSuffix
2070 } else {
2071 a.suffix = ""
2072 a.primaryApexType = true
2073
2074 if ctx.Config().InstallExtraFlattenedApexes() {
2075 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2076 }
2077 }
2078 case zipApex:
2079 if proptools.String(a.properties.Payload_type) == "zip" {
2080 a.suffix = ""
2081 a.primaryApexType = true
2082 } else {
2083 a.suffix = zipApexSuffix
2084 }
2085 case flattenedApex:
2086 if buildFlattenedAsDefault {
2087 a.suffix = ""
2088 a.primaryApexType = true
2089 } else {
2090 a.suffix = flattenedSuffix
2091 }
2092 }
2093
Theotime Combes4ba38c12020-06-12 12:46:59 +00002094 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2095 case ext4FsType:
2096 a.payloadFsType = ext4
2097 case f2fsFsType:
2098 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002099 case erofsFsType:
2100 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002101 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002102 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type)
Theotime Combes4ba38c12020-06-12 12:46:59 +00002103 }
2104
Jiyong Park7cd10e32020-01-14 09:22:18 +09002105 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2106 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2107 // the same library in the system partition, thus effectively sharing the same libraries
2108 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2109 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002110 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002111
Jooyung Han85d61762020-06-24 23:50:26 +09002112 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2113 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002114 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002115 a.linkToSystemLib = false
2116 }
2117
Jiyong Park4da07972021-01-05 21:01:11 +09002118 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002119 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002120
Jiyong Park9d677202020-02-19 16:29:35 +09002121 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002122 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002123 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002124 a.linkToSystemLib = false
2125 }
2126
Jiyong Park638d30e2020-02-26 18:27:19 +09002127 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2128 if ctx.Host() {
2129 a.linkToSystemLib = false
2130 }
2131
Colin Cross6340ea52021-11-04 12:01:18 -07002132 if a.properties.ApexType != zipApex {
2133 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2134 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002135
2136 ////////////////////////////////////////////////////////////////////////////////////////////
2137 // 4) generate the build rules to create the APEX. This is done in builder.go.
2138 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002139 if a.properties.ApexType == flattenedApex {
2140 a.buildFlattenedApex(ctx)
2141 } else {
2142 a.buildUnflattenedApex(ctx)
2143 }
Jiyong Park956305c2020-01-09 12:32:06 +09002144 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002145 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002146
2147 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2148 if a.installable() {
2149 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2150 // along with other ordinary files. (Note that this is done by apexer for
2151 // non-flattened APEXes)
2152 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2153
2154 // Place the public key as apex_pubkey. This is also done by apexer for
2155 // non-flattened APEXes case.
2156 // TODO(jiyong): Why do we need this CP rule?
2157 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2158 ctx.Build(pctx, android.BuildParams{
2159 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002160 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002161 Output: copiedPubkey,
2162 })
2163 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2164 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002165}
2166
Paul Duffincc33ec82021-04-25 23:14:55 +01002167// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2168// the bootclasspath_fragment contributes to the apex.
2169func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2170 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2171 var filesToAdd []apexFile
2172
2173 // Add the boot image files, e.g. .art, .oat and .vdex files.
2174 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2175 dirInApex := filepath.Join("javalib", arch.String())
2176 for _, f := range files {
2177 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2178 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2179 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2180 filesToAdd = append(filesToAdd, af)
2181 }
2182 }
2183
satayev3db35472021-05-06 23:59:58 +01002184 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002185 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2186 filesToAdd = append(filesToAdd, *af)
2187 }
satayev3db35472021-05-06 23:59:58 +01002188
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002189 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2190 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2191 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2192
2193 if pathOnHost != nil {
2194 // We need to copy the profile to a temporary path with the right filename because the apexer
2195 // will take the filename as is.
2196 ctx.Build(pctx, android.BuildParams{
2197 Rule: android.Cp,
2198 Input: pathOnHost,
2199 Output: tempPath,
2200 })
2201 } else {
2202 // At this point, the boot image profile cannot be generated. It is probably because the boot
2203 // image profile source file does not exist on the branch, or it is not available for the
2204 // current build target.
2205 // However, we cannot enforce the boot image profile to be generated because some build
2206 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2207 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2208 // only if the APEX is being built.
2209 ctx.Build(pctx, android.BuildParams{
2210 Rule: android.ErrorRule,
2211 Output: tempPath,
2212 Args: map[string]string{
2213 "error": "Boot image profile cannot be generated",
2214 },
2215 })
2216 }
2217
2218 androidMkModuleName := filepath.Base(pathInApex)
2219 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2220 filesToAdd = append(filesToAdd, af)
2221 }
2222
Paul Duffincc33ec82021-04-25 23:14:55 +01002223 return filesToAdd
2224}
2225
satayevb98371c2021-06-15 16:49:50 +01002226// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2227// the module contributes to the apex; or nil if the proto config was not generated.
2228func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2229 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2230 if !info.ClasspathFragmentProtoGenerated {
2231 return nil
2232 }
2233 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2234 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2235 return &af
satayev14e49132021-05-17 21:03:07 +01002236}
2237
Paul Duffincc33ec82021-04-25 23:14:55 +01002238// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2239// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002240func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2241 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2242
2243 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2244 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002245 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2246 if err != nil {
2247 ctx.ModuleErrorf("%s", err)
2248 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002249
2250 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2251 // bootclasspath_fragment.
2252 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2253 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002254}
2255
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002256///////////////////////////////////////////////////////////////////////////////////////////////////
2257// Factory functions
2258//
2259
2260func newApexBundle() *apexBundle {
2261 module := &apexBundle{}
2262
2263 module.AddProperties(&module.properties)
2264 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002265 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002266 module.AddProperties(&module.overridableProperties)
2267
2268 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2269 android.InitDefaultableModule(module)
2270 android.InitSdkAwareModule(module)
2271 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002272 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002273 return module
2274}
2275
Paul Duffineb8051d2021-10-18 17:49:39 +01002276func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002277 bundle := newApexBundle()
2278 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002279 return bundle
2280}
2281
2282// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2283// certain compatibility checks such as apex_available are not done for apex_test.
2284func testApexBundleFactory() android.Module {
2285 bundle := newApexBundle()
2286 bundle.testApex = true
2287 return bundle
2288}
2289
2290// apex packages other modules into an APEX file which is a packaging format for system-level
2291// components like binaries, shared libraries, etc.
2292func BundleFactory() android.Module {
2293 return newApexBundle()
2294}
2295
2296type Defaults struct {
2297 android.ModuleBase
2298 android.DefaultsModuleBase
2299}
2300
2301// apex_defaults provides defaultable properties to other apex modules.
2302func defaultsFactory() android.Module {
2303 return DefaultsFactory()
2304}
2305
2306func DefaultsFactory(props ...interface{}) android.Module {
2307 module := &Defaults{}
2308
2309 module.AddProperties(props...)
2310 module.AddProperties(
2311 &apexBundleProperties{},
2312 &apexTargetBundleProperties{},
2313 &overridableProperties{},
2314 )
2315
2316 android.InitDefaultsModule(module)
2317 return module
2318}
2319
2320type OverrideApex struct {
2321 android.ModuleBase
2322 android.OverrideModuleBase
2323}
2324
2325func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2326 // All the overrides happen in the base module.
2327}
2328
2329// override_apex is used to create an apex module based on another apex module by overriding some of
2330// its properties.
2331func overrideApexFactory() android.Module {
2332 m := &OverrideApex{}
2333
2334 m.AddProperties(&overridableProperties{})
2335
2336 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2337 android.InitOverrideModule(m)
2338 return m
2339}
2340
2341///////////////////////////////////////////////////////////////////////////////////////////////////
2342// Vality check routines
2343//
2344// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2345// certain conditions are not met.
2346//
2347// TODO(jiyong): move these checks to a separate go file.
2348
2349// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2350// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002351func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002352 if a.testApex || a.vndkApex {
2353 return
2354 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002355 // apexBundle::minSdkVersion reports its own errors.
2356 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002357 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002358}
2359
2360func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
2361 ver := proptools.String(a.properties.Min_sdk_version)
2362 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002363 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002364 }
2365 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2366 if err != nil {
2367 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2368 return android.NoneApiLevel
2369 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002370 return apiLevel
2371}
2372
2373// Ensures that a lib providing stub isn't statically linked
2374func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2375 // Practically, we only care about regular APEXes on the device.
2376 if ctx.Host() || a.testApex || a.vndkApex {
2377 return
2378 }
2379
2380 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2381
2382 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2383 if ccm, ok := to.(*cc.Module); ok {
2384 apexName := ctx.ModuleName()
2385 fromName := ctx.OtherModuleName(from)
2386 toName := ctx.OtherModuleName(to)
2387
2388 // If `to` is not actually in the same APEX as `from` then it does not need
2389 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002390 //
2391 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002392 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2393 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2394 return false
2395 }
2396
2397 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2398 // exception to this rule. It can't make the static dependencies dynamic
2399 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002400 // Same rule should be applied to linkerconfig, because it should be executed
2401 // only with static linked libraries before linker is available with ld.config.txt
2402 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002403 return false
2404 }
2405
2406 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2407 if isStubLibraryFromOtherApex && !externalDep {
2408 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2409 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2410 }
2411
2412 }
2413 return true
2414 })
2415}
2416
satayevb98371c2021-06-15 16:49:50 +01002417// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002418func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2419 if a.Updatable() {
2420 if String(a.properties.Min_sdk_version) == "" {
2421 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2422 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002423 if a.UsePlatformApis() {
2424 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2425 }
Daniel Norman69109112021-12-02 12:52:42 -08002426 if a.SocSpecific() || a.DeviceSpecific() {
2427 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2428 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002429 if a.FutureUpdatable() {
2430 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2431 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002432 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002433 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002434 }
2435}
2436
satayevb98371c2021-06-15 16:49:50 +01002437// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2438func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2439 ctx.VisitDirectDeps(func(module android.Module) {
2440 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2441 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2442 if !info.ClasspathFragmentProtoGenerated {
2443 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2444 }
2445 }
2446 })
2447}
2448
2449// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002450func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002451 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2452 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002453 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2454 tag := ctx.OtherModuleDependencyTag(module)
2455 switch tag {
2456 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002457 if m, ok := module.(interface {
2458 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2459 }); ok {
2460 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002461 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2462 }
2463 }
2464 }
2465 })
2466}
2467
satayevb98371c2021-06-15 16:49:50 +01002468// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002469func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2470 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2471 if ctx.Host() || a.testApex || a.vndkApex {
2472 return
2473 }
2474
2475 // Because APEXes targeting other than system/system_ext partitions can't set
2476 // apex_available, we skip checks for these APEXes
2477 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2478 return
2479 }
2480
2481 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2482 // Requiring them and their transitive depencies with apex_available is not right
2483 // because they just add noise.
2484 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2485 return
2486 }
2487
2488 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2489 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2490 if externalDep {
2491 return false
2492 }
2493
2494 apexName := ctx.ModuleName()
2495 fromName := ctx.OtherModuleName(from)
2496 toName := ctx.OtherModuleName(to)
2497
2498 // If `to` is not actually in the same APEX as `from` then it does not need
2499 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002500 //
2501 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002502 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2503 // As soon as the dependency graph crosses the APEX boundary, don't go
2504 // further.
2505 return false
2506 }
2507
2508 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2509 return true
2510 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002511 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2512 "\n\nDependency path:%s\n\n"+
2513 "Consider adding %q to 'apex_available' property of %q",
2514 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002515 // Visit this module's dependencies to check and report any issues with their availability.
2516 return true
2517 })
2518}
2519
Jiyong Park192600a2021-08-03 07:52:17 +00002520// checkStaticExecutable ensures that executables in an APEX are not static.
2521func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002522 // No need to run this for host APEXes
2523 if ctx.Host() {
2524 return
2525 }
2526
Jiyong Park192600a2021-08-03 07:52:17 +00002527 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2528 if ctx.OtherModuleDependencyTag(module) != executableTag {
2529 return
2530 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002531
2532 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002533 apex := a.ApexVariationName()
2534 exec := ctx.OtherModuleName(module)
2535 if isStaticExecutableAllowed(apex, exec) {
2536 return
2537 }
2538 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2539 }
2540 })
2541}
2542
2543// A small list of exceptions where static executables are allowed in APEXes.
2544func isStaticExecutableAllowed(apex string, exec string) bool {
2545 m := map[string][]string{
2546 "com.android.runtime": []string{
2547 "linker",
2548 "linkerconfig",
2549 },
2550 }
2551 execNames, ok := m[apex]
2552 return ok && android.InList(exec, execNames)
2553}
2554
braleeb0c1f0c2021-06-07 22:49:13 +08002555// Collect information for opening IDE project files in java/jdeps.go.
2556func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2557 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2558 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2559 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2560 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2561}
2562
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002563var (
2564 apexAvailBaseline = makeApexAvailableBaseline()
2565 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2566)
2567
Colin Cross440e0d02020-06-11 11:32:11 -07002568func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002569 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002570 moduleName = normalizeModuleName(moduleName)
2571
Colin Cross440e0d02020-06-11 11:32:11 -07002572 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002573 return true
2574 }
2575
2576 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002577 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002578 return true
2579 }
2580
2581 return false
2582}
2583
2584func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002585 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2586 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002587 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002588 if strings.HasPrefix(moduleName, "libclang_rt.") {
2589 // This module has many arch variants that depend on the product being built.
2590 // We don't want to list them all
2591 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002592 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002593 if strings.HasPrefix(moduleName, "androidx.") {
2594 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2595 moduleName = "androidx"
2596 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002597 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002598}
2599
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002600// Transform the map of apex -> modules to module -> apexes.
2601func invertApexBaseline(m map[string][]string) map[string][]string {
2602 r := make(map[string][]string)
2603 for apex, modules := range m {
2604 for _, module := range modules {
2605 r[module] = append(r[module], apex)
2606 }
2607 }
2608 return r
2609}
2610
2611// Retrieve the baseline of apexes to which the supplied module belongs.
2612func BaselineApexAvailable(moduleName string) []string {
2613 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2614}
2615
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002616// This is a map from apex to modules, which overrides the apex_available setting for that
2617// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002618// TODO(b/147364041): remove this
2619func makeApexAvailableBaseline() map[string][]string {
2620 // The "Module separator"s below are employed to minimize merge conflicts.
2621 m := make(map[string][]string)
2622 //
2623 // Module separator
2624 //
2625 m["com.android.appsearch"] = []string{
2626 "icing-java-proto-lite",
2627 "libprotobuf-java-lite",
2628 }
2629 //
2630 // Module separator
2631 //
2632 m["com.android.bluetooth.updatable"] = []string{
2633 "android.hardware.audio.common@5.0",
2634 "android.hardware.bluetooth.a2dp@1.0",
2635 "android.hardware.bluetooth.audio@2.0",
2636 "android.hardware.bluetooth@1.0",
2637 "android.hardware.bluetooth@1.1",
2638 "android.hardware.graphics.bufferqueue@1.0",
2639 "android.hardware.graphics.bufferqueue@2.0",
2640 "android.hardware.graphics.common@1.0",
2641 "android.hardware.graphics.common@1.1",
2642 "android.hardware.graphics.common@1.2",
2643 "android.hardware.media@1.0",
2644 "android.hidl.safe_union@1.0",
2645 "android.hidl.token@1.0",
2646 "android.hidl.token@1.0-utils",
2647 "avrcp-target-service",
2648 "avrcp_headers",
2649 "bluetooth-protos-lite",
2650 "bluetooth.mapsapi",
2651 "com.android.vcard",
2652 "dnsresolver_aidl_interface-V2-java",
2653 "ipmemorystore-aidl-interfaces-V5-java",
2654 "ipmemorystore-aidl-interfaces-java",
2655 "internal_include_headers",
2656 "lib-bt-packets",
2657 "lib-bt-packets-avrcp",
2658 "lib-bt-packets-base",
2659 "libFraunhoferAAC",
2660 "libaudio-a2dp-hw-utils",
2661 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002662 "libbluetooth",
2663 "libbluetooth-types",
2664 "libbluetooth-types-header",
2665 "libbluetooth_gd",
2666 "libbluetooth_headers",
2667 "libbluetooth_jni",
2668 "libbt-audio-hal-interface",
2669 "libbt-bta",
2670 "libbt-common",
2671 "libbt-hci",
2672 "libbt-platform-protos-lite",
2673 "libbt-protos-lite",
2674 "libbt-sbc-decoder",
2675 "libbt-sbc-encoder",
2676 "libbt-stack",
2677 "libbt-utils",
2678 "libbtcore",
2679 "libbtdevice",
2680 "libbte",
2681 "libbtif",
2682 "libchrome",
2683 "libevent",
2684 "libfmq",
2685 "libg722codec",
2686 "libgui_headers",
2687 "libmedia_headers",
2688 "libmodpb64",
2689 "libosi",
2690 "libstagefright_foundation_headers",
2691 "libstagefright_headers",
2692 "libstatslog",
2693 "libstatssocket",
2694 "libtinyxml2",
2695 "libudrv-uipc",
2696 "libz",
2697 "media_plugin_headers",
2698 "net-utils-services-common",
2699 "netd_aidl_interface-unstable-java",
2700 "netd_event_listener_interface-java",
2701 "netlink-client",
2702 "networkstack-client",
2703 "sap-api-java-static",
2704 "services.net",
2705 }
2706 //
2707 // Module separator
2708 //
2709 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2710 //
2711 // Module separator
2712 //
2713 m["com.android.extservices"] = []string{
2714 "error_prone_annotations",
2715 "ExtServices-core",
2716 "ExtServices",
2717 "libtextclassifier-java",
2718 "libz_current",
2719 "textclassifier-statsd",
2720 "TextClassifierNotificationLibNoManifest",
2721 "TextClassifierServiceLibNoManifest",
2722 }
2723 //
2724 // Module separator
2725 //
2726 m["com.android.neuralnetworks"] = []string{
2727 "android.hardware.neuralnetworks@1.0",
2728 "android.hardware.neuralnetworks@1.1",
2729 "android.hardware.neuralnetworks@1.2",
2730 "android.hardware.neuralnetworks@1.3",
2731 "android.hidl.allocator@1.0",
2732 "android.hidl.memory.token@1.0",
2733 "android.hidl.memory@1.0",
2734 "android.hidl.safe_union@1.0",
2735 "libarect",
2736 "libbuildversion",
2737 "libmath",
2738 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002739 }
2740 //
2741 // Module separator
2742 //
2743 m["com.android.media"] = []string{
2744 "android.frameworks.bufferhub@1.0",
2745 "android.hardware.cas.native@1.0",
2746 "android.hardware.cas@1.0",
2747 "android.hardware.configstore-utils",
2748 "android.hardware.configstore@1.0",
2749 "android.hardware.configstore@1.1",
2750 "android.hardware.graphics.allocator@2.0",
2751 "android.hardware.graphics.allocator@3.0",
2752 "android.hardware.graphics.bufferqueue@1.0",
2753 "android.hardware.graphics.bufferqueue@2.0",
2754 "android.hardware.graphics.common@1.0",
2755 "android.hardware.graphics.common@1.1",
2756 "android.hardware.graphics.common@1.2",
2757 "android.hardware.graphics.mapper@2.0",
2758 "android.hardware.graphics.mapper@2.1",
2759 "android.hardware.graphics.mapper@3.0",
2760 "android.hardware.media.omx@1.0",
2761 "android.hardware.media@1.0",
2762 "android.hidl.allocator@1.0",
2763 "android.hidl.memory.token@1.0",
2764 "android.hidl.memory@1.0",
2765 "android.hidl.token@1.0",
2766 "android.hidl.token@1.0-utils",
2767 "bionic_libc_platform_headers",
2768 "exoplayer2-extractor",
2769 "exoplayer2-extractor-annotation-stubs",
2770 "gl_headers",
2771 "jsr305",
2772 "libEGL",
2773 "libEGL_blobCache",
2774 "libEGL_getProcAddress",
2775 "libFLAC",
2776 "libFLAC-config",
2777 "libFLAC-headers",
2778 "libGLESv2",
2779 "libaacextractor",
2780 "libamrextractor",
2781 "libarect",
2782 "libaudio_system_headers",
2783 "libaudioclient",
2784 "libaudioclient_headers",
2785 "libaudiofoundation",
2786 "libaudiofoundation_headers",
2787 "libaudiomanager",
2788 "libaudiopolicy",
2789 "libaudioutils",
2790 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002791 "libbluetooth-types-header",
2792 "libbufferhub",
2793 "libbufferhub_headers",
2794 "libbufferhubqueue",
2795 "libc_malloc_debug_backtrace",
2796 "libcamera_client",
2797 "libcamera_metadata",
2798 "libdvr_headers",
2799 "libexpat",
2800 "libfifo",
2801 "libflacextractor",
2802 "libgrallocusage",
2803 "libgraphicsenv",
2804 "libgui",
2805 "libgui_headers",
2806 "libhardware_headers",
2807 "libinput",
2808 "liblzma",
2809 "libmath",
2810 "libmedia",
2811 "libmedia_codeclist",
2812 "libmedia_headers",
2813 "libmedia_helper",
2814 "libmedia_helper_headers",
2815 "libmedia_midiiowrapper",
2816 "libmedia_omx",
2817 "libmediautils",
2818 "libmidiextractor",
2819 "libmkvextractor",
2820 "libmp3extractor",
2821 "libmp4extractor",
2822 "libmpeg2extractor",
2823 "libnativebase_headers",
2824 "libnativewindow_headers",
2825 "libnblog",
2826 "liboggextractor",
2827 "libpackagelistparser",
2828 "libpdx",
2829 "libpdx_default_transport",
2830 "libpdx_headers",
2831 "libpdx_uds",
2832 "libprocinfo",
2833 "libspeexresampler",
2834 "libspeexresampler",
2835 "libstagefright_esds",
2836 "libstagefright_flacdec",
2837 "libstagefright_flacdec",
2838 "libstagefright_foundation",
2839 "libstagefright_foundation_headers",
2840 "libstagefright_foundation_without_imemory",
2841 "libstagefright_headers",
2842 "libstagefright_id3",
2843 "libstagefright_metadatautils",
2844 "libstagefright_mpeg2extractor",
2845 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002846 "libui",
2847 "libui_headers",
2848 "libunwindstack",
2849 "libvibrator",
2850 "libvorbisidec",
2851 "libwavextractor",
2852 "libwebm",
2853 "media_ndk_headers",
2854 "media_plugin_headers",
2855 "updatable-media",
2856 }
2857 //
2858 // Module separator
2859 //
2860 m["com.android.media.swcodec"] = []string{
2861 "android.frameworks.bufferhub@1.0",
2862 "android.hardware.common-ndk_platform",
2863 "android.hardware.configstore-utils",
2864 "android.hardware.configstore@1.0",
2865 "android.hardware.configstore@1.1",
2866 "android.hardware.graphics.allocator@2.0",
2867 "android.hardware.graphics.allocator@3.0",
2868 "android.hardware.graphics.allocator@4.0",
2869 "android.hardware.graphics.bufferqueue@1.0",
2870 "android.hardware.graphics.bufferqueue@2.0",
2871 "android.hardware.graphics.common-ndk_platform",
2872 "android.hardware.graphics.common@1.0",
2873 "android.hardware.graphics.common@1.1",
2874 "android.hardware.graphics.common@1.2",
2875 "android.hardware.graphics.mapper@2.0",
2876 "android.hardware.graphics.mapper@2.1",
2877 "android.hardware.graphics.mapper@3.0",
2878 "android.hardware.graphics.mapper@4.0",
2879 "android.hardware.media.bufferpool@2.0",
2880 "android.hardware.media.c2@1.0",
2881 "android.hardware.media.c2@1.1",
2882 "android.hardware.media.omx@1.0",
2883 "android.hardware.media@1.0",
2884 "android.hardware.media@1.0",
2885 "android.hidl.memory.token@1.0",
2886 "android.hidl.memory@1.0",
2887 "android.hidl.safe_union@1.0",
2888 "android.hidl.token@1.0",
2889 "android.hidl.token@1.0-utils",
2890 "libEGL",
2891 "libFLAC",
2892 "libFLAC-config",
2893 "libFLAC-headers",
2894 "libFraunhoferAAC",
2895 "libLibGuiProperties",
2896 "libarect",
2897 "libaudio_system_headers",
2898 "libaudioutils",
2899 "libaudioutils",
2900 "libaudioutils_fixedfft",
2901 "libavcdec",
2902 "libavcenc",
2903 "libavservices_minijail",
2904 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002905 "libbinderthreadstateutils",
2906 "libbluetooth-types-header",
2907 "libbufferhub_headers",
2908 "libcodec2",
2909 "libcodec2_headers",
2910 "libcodec2_hidl@1.0",
2911 "libcodec2_hidl@1.1",
2912 "libcodec2_internal",
2913 "libcodec2_soft_aacdec",
2914 "libcodec2_soft_aacenc",
2915 "libcodec2_soft_amrnbdec",
2916 "libcodec2_soft_amrnbenc",
2917 "libcodec2_soft_amrwbdec",
2918 "libcodec2_soft_amrwbenc",
2919 "libcodec2_soft_av1dec_gav1",
2920 "libcodec2_soft_avcdec",
2921 "libcodec2_soft_avcenc",
2922 "libcodec2_soft_common",
2923 "libcodec2_soft_flacdec",
2924 "libcodec2_soft_flacenc",
2925 "libcodec2_soft_g711alawdec",
2926 "libcodec2_soft_g711mlawdec",
2927 "libcodec2_soft_gsmdec",
2928 "libcodec2_soft_h263dec",
2929 "libcodec2_soft_h263enc",
2930 "libcodec2_soft_hevcdec",
2931 "libcodec2_soft_hevcenc",
2932 "libcodec2_soft_mp3dec",
2933 "libcodec2_soft_mpeg2dec",
2934 "libcodec2_soft_mpeg4dec",
2935 "libcodec2_soft_mpeg4enc",
2936 "libcodec2_soft_opusdec",
2937 "libcodec2_soft_opusenc",
2938 "libcodec2_soft_rawdec",
2939 "libcodec2_soft_vorbisdec",
2940 "libcodec2_soft_vp8dec",
2941 "libcodec2_soft_vp8enc",
2942 "libcodec2_soft_vp9dec",
2943 "libcodec2_soft_vp9enc",
2944 "libcodec2_vndk",
2945 "libdvr_headers",
2946 "libfmq",
2947 "libfmq",
2948 "libgav1",
2949 "libgralloctypes",
2950 "libgrallocusage",
2951 "libgraphicsenv",
2952 "libgsm",
2953 "libgui_bufferqueue_static",
2954 "libgui_headers",
2955 "libhardware",
2956 "libhardware_headers",
2957 "libhevcdec",
2958 "libhevcenc",
2959 "libion",
2960 "libjpeg",
2961 "liblzma",
2962 "libmath",
2963 "libmedia_codecserviceregistrant",
2964 "libmedia_headers",
2965 "libmpeg2dec",
2966 "libnativebase_headers",
2967 "libnativewindow_headers",
2968 "libpdx_headers",
2969 "libscudo_wrapper",
2970 "libsfplugin_ccodec_utils",
2971 "libspeexresampler",
2972 "libstagefright_amrnb_common",
2973 "libstagefright_amrnbdec",
2974 "libstagefright_amrnbenc",
2975 "libstagefright_amrwbdec",
2976 "libstagefright_amrwbenc",
2977 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002978 "libstagefright_enc_common",
2979 "libstagefright_flacdec",
2980 "libstagefright_foundation",
2981 "libstagefright_foundation_headers",
2982 "libstagefright_headers",
2983 "libstagefright_m4vh263dec",
2984 "libstagefright_m4vh263enc",
2985 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002986 "libui",
2987 "libui_headers",
2988 "libunwindstack",
2989 "libvorbisidec",
2990 "libvpx",
2991 "libyuv",
2992 "libyuv_static",
2993 "media_ndk_headers",
2994 "media_plugin_headers",
2995 "mediaswcodec",
2996 }
2997 //
2998 // Module separator
2999 //
3000 m["com.android.mediaprovider"] = []string{
3001 "MediaProvider",
3002 "MediaProviderGoogle",
3003 "fmtlib_ndk",
3004 "libbase_ndk",
3005 "libfuse",
3006 "libfuse_jni",
3007 }
3008 //
3009 // Module separator
3010 //
3011 m["com.android.permission"] = []string{
3012 "car-ui-lib",
3013 "iconloader",
3014 "kotlin-annotations",
3015 "kotlin-stdlib",
3016 "kotlin-stdlib-jdk7",
3017 "kotlin-stdlib-jdk8",
3018 "kotlinx-coroutines-android",
3019 "kotlinx-coroutines-android-nodeps",
3020 "kotlinx-coroutines-core",
3021 "kotlinx-coroutines-core-nodeps",
3022 "permissioncontroller-statsd",
3023 "GooglePermissionController",
3024 "PermissionController",
3025 "SettingsLibActionBarShadow",
3026 "SettingsLibAppPreference",
3027 "SettingsLibBarChartPreference",
3028 "SettingsLibLayoutPreference",
3029 "SettingsLibProgressBar",
3030 "SettingsLibSearchWidget",
3031 "SettingsLibSettingsTheme",
3032 "SettingsLibRestrictedLockUtils",
3033 "SettingsLibHelpUtils",
3034 }
3035 //
3036 // Module separator
3037 //
3038 m["com.android.runtime"] = []string{
3039 "bionic_libc_platform_headers",
3040 "libarm-optimized-routines-math",
3041 "libc_aeabi",
3042 "libc_bionic",
3043 "libc_bionic_ndk",
3044 "libc_bootstrap",
3045 "libc_common",
3046 "libc_common_shared",
3047 "libc_common_static",
3048 "libc_dns",
3049 "libc_dynamic_dispatch",
3050 "libc_fortify",
3051 "libc_freebsd",
3052 "libc_freebsd_large_stack",
3053 "libc_gdtoa",
3054 "libc_init_dynamic",
3055 "libc_init_static",
3056 "libc_jemalloc_wrapper",
3057 "libc_netbsd",
3058 "libc_nomalloc",
3059 "libc_nopthread",
3060 "libc_openbsd",
3061 "libc_openbsd_large_stack",
3062 "libc_openbsd_ndk",
3063 "libc_pthread",
3064 "libc_static_dispatch",
3065 "libc_syscalls",
3066 "libc_tzcode",
3067 "libc_unwind_static",
3068 "libdebuggerd",
3069 "libdebuggerd_common_headers",
3070 "libdebuggerd_handler_core",
3071 "libdebuggerd_handler_fallback",
3072 "libdl_static",
3073 "libjemalloc5",
3074 "liblinker_main",
3075 "liblinker_malloc",
3076 "liblz4",
3077 "liblzma",
3078 "libprocinfo",
3079 "libpropertyinfoparser",
3080 "libscudo",
3081 "libstdc++",
3082 "libsystemproperties",
3083 "libtombstoned_client_static",
3084 "libunwindstack",
3085 "libz",
3086 "libziparchive",
3087 }
3088 //
3089 // Module separator
3090 //
3091 m["com.android.tethering"] = []string{
3092 "android.hardware.tetheroffload.config-V1.0-java",
3093 "android.hardware.tetheroffload.control-V1.0-java",
3094 "android.hidl.base-V1.0-java",
3095 "libcgrouprc",
3096 "libcgrouprc_format",
3097 "libtetherutilsjni",
3098 "libvndksupport",
3099 "net-utils-framework-common",
3100 "netd_aidl_interface-V3-java",
3101 "netlink-client",
3102 "networkstack-aidl-interfaces-java",
3103 "tethering-aidl-interfaces-java",
3104 "TetheringApiCurrentLib",
3105 }
3106 //
3107 // Module separator
3108 //
3109 m["com.android.wifi"] = []string{
3110 "PlatformProperties",
3111 "android.hardware.wifi-V1.0-java",
3112 "android.hardware.wifi-V1.0-java-constants",
3113 "android.hardware.wifi-V1.1-java",
3114 "android.hardware.wifi-V1.2-java",
3115 "android.hardware.wifi-V1.3-java",
3116 "android.hardware.wifi-V1.4-java",
3117 "android.hardware.wifi.hostapd-V1.0-java",
3118 "android.hardware.wifi.hostapd-V1.1-java",
3119 "android.hardware.wifi.hostapd-V1.2-java",
3120 "android.hardware.wifi.supplicant-V1.0-java",
3121 "android.hardware.wifi.supplicant-V1.1-java",
3122 "android.hardware.wifi.supplicant-V1.2-java",
3123 "android.hardware.wifi.supplicant-V1.3-java",
3124 "android.hidl.base-V1.0-java",
3125 "android.hidl.manager-V1.0-java",
3126 "android.hidl.manager-V1.1-java",
3127 "android.hidl.manager-V1.2-java",
3128 "bouncycastle-unbundled",
3129 "dnsresolver_aidl_interface-V2-java",
3130 "error_prone_annotations",
3131 "framework-wifi-pre-jarjar",
3132 "framework-wifi-util-lib",
3133 "ipmemorystore-aidl-interfaces-V3-java",
3134 "ipmemorystore-aidl-interfaces-java",
3135 "ksoap2",
3136 "libnanohttpd",
3137 "libwifi-jni",
3138 "net-utils-services-common",
3139 "netd_aidl_interface-V2-java",
3140 "netd_aidl_interface-unstable-java",
3141 "netd_event_listener_interface-java",
3142 "netlink-client",
3143 "networkstack-client",
3144 "services.net",
3145 "wifi-lite-protos",
3146 "wifi-nano-protos",
3147 "wifi-service-pre-jarjar",
3148 "wifi-service-resources",
3149 }
3150 //
3151 // Module separator
3152 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003153 m["com.android.os.statsd"] = []string{
3154 "libstatssocket",
3155 }
3156 //
3157 // Module separator
3158 //
3159 m[android.AvailableToAnyApex] = []string{
3160 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3161 "androidx",
3162 "androidx-constraintlayout_constraintlayout",
3163 "androidx-constraintlayout_constraintlayout-nodeps",
3164 "androidx-constraintlayout_constraintlayout-solver",
3165 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3166 "com.google.android.material_material",
3167 "com.google.android.material_material-nodeps",
3168
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003169 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003170 "libprofile-clang-extras",
3171 "libprofile-clang-extras_ndk",
3172 "libprofile-extras",
3173 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003174 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003175 }
3176 return m
3177}
3178
3179func init() {
3180 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3181 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3182}
3183
3184func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3185 rules := make([]android.Rule, 0, len(modules_packages))
3186 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003187 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003188 BootclasspathJar().
3189 With("apex_available", module_name).
3190 WithMatcher("permitted_packages", android.NotInList(module_packages)).
3191 Because("jars that are part of the " + module_name +
3192 " module may only allow these packages: " + strings.Join(module_packages, ",") +
3193 ". Please jarjar or move code around.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003194 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003195 }
3196 return rules
3197}
3198
3199// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
3200// Adding code to the bootclasspath in new packages will cause issues on module update.
3201func qModulesPackages() map[string][]string {
3202 return map[string][]string{
3203 "com.android.conscrypt": []string{
3204 "android.net.ssl",
3205 "com.android.org.conscrypt",
3206 },
3207 "com.android.media": []string{
3208 "android.media",
3209 },
3210 }
3211}
3212
3213// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
3214// Adding code to the bootclasspath in new packages will cause issues on module update.
3215func rModulesPackages() map[string][]string {
3216 return map[string][]string{
3217 "com.android.mediaprovider": []string{
3218 "android.provider",
3219 },
3220 "com.android.permission": []string{
3221 "android.permission",
3222 "android.app.role",
3223 "com.android.permission",
3224 "com.android.role",
3225 },
3226 "com.android.sdkext": []string{
3227 "android.os.ext",
3228 },
3229 "com.android.os.statsd": []string{
3230 "android.app",
3231 "android.os",
3232 "android.util",
3233 "com.android.internal.statsd",
3234 "com.android.server.stats",
3235 },
3236 "com.android.wifi": []string{
3237 "com.android.server.wifi",
3238 "com.android.wifi.x",
3239 "android.hardware.wifi",
3240 "android.net.wifi",
3241 },
3242 "com.android.tethering": []string{
3243 "android.net",
3244 },
3245 }
3246}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003247
3248// For Bazel / bp2build
3249
3250type bazelApexBundleAttributes struct {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003251 Manifest bazel.LabelAttribute
3252 Android_manifest bazel.LabelAttribute
3253 File_contexts bazel.LabelAttribute
3254 Key bazel.LabelAttribute
3255 Certificate bazel.LabelAttribute
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003256 Min_sdk_version *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003257 Updatable bazel.BoolAttribute
3258 Installable bazel.BoolAttribute
3259 Native_shared_libs bazel.LabelListAttribute
Jingwen Chenb07c9012021-12-08 10:05:45 +00003260 Binaries bazel.LabelListAttribute
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003261 Prebuilts bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003262}
3263
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003264func ApexBundleBp2Build(ctx android.TopDownMutatorContext) {
3265 module, ok := ctx.Module().(*apexBundle)
3266 if !ok {
3267 // Not an APEX bundle
3268 return
3269 }
3270 if !module.ConvertWithBp2build(ctx) {
3271 return
3272 }
3273 if ctx.ModuleType() != "apex" {
3274 return
3275 }
3276
3277 apexBundleBp2BuildInternal(ctx, module)
3278}
3279
3280func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) {
3281 var manifestLabelAttribute bazel.LabelAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003282 if module.properties.Manifest != nil {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003283 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Manifest))
3284 }
3285
3286 var androidManifestLabelAttribute bazel.LabelAttribute
3287 if module.properties.AndroidManifest != nil {
3288 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.AndroidManifest))
3289 }
3290
3291 var fileContextsLabelAttribute bazel.LabelAttribute
3292 if module.properties.File_contexts != nil {
3293 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.File_contexts))
3294 }
3295
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003296 var minSdkVersion *string
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003297 if module.properties.Min_sdk_version != nil {
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003298 minSdkVersion = module.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003299 }
3300
3301 var keyLabelAttribute bazel.LabelAttribute
3302 if module.overridableProperties.Key != nil {
3303 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Key))
3304 }
3305
3306 var certificateLabelAttribute bazel.LabelAttribute
3307 if module.overridableProperties.Certificate != nil {
3308 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Certificate))
3309 }
3310
3311 nativeSharedLibs := module.properties.ApexNativeDependencies.Native_shared_libs
3312 nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
3313 nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
3314
Daniel Norman5a3ce132021-08-26 15:44:43 -07003315 prebuilts := module.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003316 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3317 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3318
Jingwen Chenb07c9012021-12-08 10:05:45 +00003319 binaries := android.BazelLabelForModuleDeps(ctx, module.properties.ApexNativeDependencies.Binaries)
3320 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003321
3322 var updatableAttribute bazel.BoolAttribute
3323 if module.properties.Updatable != nil {
3324 updatableAttribute.Value = module.properties.Updatable
3325 }
3326
3327 var installableAttribute bazel.BoolAttribute
3328 if module.properties.Installable != nil {
3329 installableAttribute.Value = module.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003330 }
3331
3332 attrs := &bazelApexBundleAttributes{
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003333 Manifest: manifestLabelAttribute,
3334 Android_manifest: androidManifestLabelAttribute,
3335 File_contexts: fileContextsLabelAttribute,
3336 Min_sdk_version: minSdkVersion,
3337 Key: keyLabelAttribute,
3338 Certificate: certificateLabelAttribute,
3339 Updatable: updatableAttribute,
3340 Installable: installableAttribute,
3341 Native_shared_libs: nativeSharedLibsLabelListAttribute,
Jingwen Chenb07c9012021-12-08 10:05:45 +00003342 Binaries: binariesLabelListAttribute,
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003343 Prebuilts: prebuiltsLabelListAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003344 }
3345
3346 props := bazel.BazelTargetModuleProperties{
3347 Rule_class: "apex",
3348 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3349 }
3350
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +00003351 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003352}