blob: a36a022f67e22a2279a00889ba2cd5b098b91c2f [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
Paul Duffin3abc1742021-03-15 19:32:23 +0000114 // List of platform_compat_config files that are embedded inside this APEX bundle.
115 Compat_configs []string
116
Jiyong Park12a719c2021-01-07 15:31:24 +0900117 // List of filesystem images that are embedded inside this APEX bundle.
118 Filesystems []string
119
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900120 // The minimum SDK version that this APEX must support at minimum. This is usually set to
121 // the SDK version that the APEX was first introduced.
122 Min_sdk_version *string
123
124 // Whether this APEX is considered updatable or not. When set to true, this will enforce
125 // additional rules for making sure that the APEX is truly updatable. To be updatable,
126 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000127 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900128 Updatable *bool
129
Jiyong Park1bc84122021-06-22 20:23:05 +0900130 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
131 // false`. Default is false.
132 Platform_apis *bool
133
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900134 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
135 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900136 Installable *bool
137
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000138 // Whether this APEX can be compressed or not. Setting this property to false means this
139 // APEX will never be compressed. When set to true, APEX will be compressed if other
140 // conditions, e.g, target device needs to support APEX compression, are also fulfilled.
141 // Default: true.
142 Compressible *bool
143
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900144 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
145 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
146 Use_vndk_as_stable *bool
147
148 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
149 // `name#version` or `name` which is an alias for `name#current`. If left empty,
150 // `platform#current` is implied. This value affects all modules included in this APEX. In
151 // other words, they are also built with the SDKs specified here.
152 Uses_sdks []string
153
154 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
155 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
156 // container. When set to zip, contents are stored in a zip container directly. This type is
157 // mostly for host-side debugging. When set to both, the two types are both built. Default
158 // is 'image'.
159 Payload_type *string
160
Huang Jianan13cac632021-08-02 15:02:17 +0800161 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
162 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900163 Payload_fs_type *string
164
165 // For telling the APEX to ignore special handling for system libraries such as bionic.
166 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900167 Ignore_system_library_special_case *bool
168
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100169 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100170 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100171 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900172
173 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
174 // used in tests.
175 Test_only_unsigned_payload *bool
176
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000177 // Whenever apex should be compressed, regardless of product flag used. Should be only
178 // used in tests.
179 Test_only_force_compression *bool
180
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100181 // Canonical name of this APEX bundle. Used to determine the path to the
182 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
183 // apex mutator variations. For override_apex modules, this is the name of the
184 // overridden base module.
185 ApexVariationName string `blueprint:"mutated"`
186
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900187 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900188
189 // List of sanitizer names that this APEX is enabled for
190 SanitizerNames []string `blueprint:"mutated"`
191
192 PreventInstall bool `blueprint:"mutated"`
193
194 HideFromMake bool `blueprint:"mutated"`
195
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900196 // Internal package method for this APEX. When payload_type is image, this can be either
197 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
198 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900199 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900200}
201
202type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900203 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900204 Native_shared_libs []string
205
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900206 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900207 Jni_libs []string
208
Jiyong Park99644e92020-11-17 22:21:02 +0900209 // List of rust dyn libraries
210 Rust_dyn_libs []string
211
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900212 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900213 Binaries []string
214
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900215 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900216 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900217
218 // List of filesystem images that are embedded inside this APEX bundle.
219 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900220}
221
222type apexMultilibProperties struct {
223 // Native dependencies whose compile_multilib is "first"
224 First ApexNativeDependencies
225
226 // Native dependencies whose compile_multilib is "both"
227 Both ApexNativeDependencies
228
229 // Native dependencies whose compile_multilib is "prefer32"
230 Prefer32 ApexNativeDependencies
231
232 // Native dependencies whose compile_multilib is "32"
233 Lib32 ApexNativeDependencies
234
235 // Native dependencies whose compile_multilib is "64"
236 Lib64 ApexNativeDependencies
237}
238
239type apexTargetBundleProperties struct {
240 Target struct {
241 // Multilib properties only for android.
242 Android struct {
243 Multilib apexMultilibProperties
244 }
245
246 // Multilib properties only for host.
247 Host struct {
248 Multilib apexMultilibProperties
249 }
250
251 // Multilib properties only for host linux_bionic.
252 Linux_bionic struct {
253 Multilib apexMultilibProperties
254 }
255
256 // Multilib properties only for host linux_glibc.
257 Linux_glibc struct {
258 Multilib apexMultilibProperties
259 }
260 }
261}
262
Jiyong Park59140302020-12-14 18:44:04 +0900263type apexArchBundleProperties struct {
264 Arch struct {
265 Arm struct {
266 ApexNativeDependencies
267 }
268 Arm64 struct {
269 ApexNativeDependencies
270 }
271 X86 struct {
272 ApexNativeDependencies
273 }
274 X86_64 struct {
275 ApexNativeDependencies
276 }
277 }
278}
279
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900280// These properties can be used in override_apex to override the corresponding properties in the
281// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900282type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900283 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900284 Apps []string
285
Daniel Norman5a3ce132021-08-26 15:44:43 -0700286 // List of prebuilt files that are embedded inside this APEX bundle.
287 Prebuilts []string
288
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900289 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900290 Rros []string
291
markchien7c803b82021-08-26 22:10:06 +0800292 // List of BPF programs inside this APEX bundle.
293 Bpfs []string
294
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900295 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
296 // Soong). This does not completely prevent installation of the overridden binaries, but if
297 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
298 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900299 Overrides []string
300
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900301 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900302 Logging_parent string
303
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900304 // Apex Container package name. Override value for attribute package:name in
305 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900306 Package_name string
307
308 // A txt file containing list of files that are allowed to be included in this APEX.
309 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700310
311 // Name of the apex_key module that provides the private key to sign this APEX bundle.
312 Key *string
313
314 // Specifies the certificate and the private key to sign the zip container of this APEX. If
315 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
316 // as the certificate and the private key, respectively. If this is ":module", then the
317 // certificate and the private key are provided from the android_app_certificate module
318 // named "module".
319 Certificate *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900320}
321
322type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900323 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900324 android.ModuleBase
325 android.DefaultableModuleBase
326 android.OverridableModuleBase
327 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400328 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900329
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900330 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900331 properties apexBundleProperties
332 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900333 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900334 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900335 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900336
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900337 ///////////////////////////////////////////////////////////////////////////////////////////
338 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900339
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900340 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800341 publicKeyFile android.Path
342 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900343
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900344 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800345 containerCertificateFile android.Path
346 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900347
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900348 // Flags for special variants of APEX
349 testApex bool
350 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900351
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900352 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
353 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900354 primaryApexType bool
355
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900356 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900357 suffix string
358
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900359 // File system type of apex_payload.img
360 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362 // Whether to create symlink to the system file instead of having a file inside the apex or
363 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900364 linkToSystemLib bool
365
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900366 // List of files to be included in this APEX. This is filled in the first part of
367 // GenerateAndroidBuildActions.
368 filesInfo []apexFile
369
370 // List of other module names that should be installed when this APEX gets installed.
371 requiredDeps []string
372
373 ///////////////////////////////////////////////////////////////////////////////////////////
374 // Outputs (final and intermediates)
375
376 // Processed apex manifest in JSONson format (for Q)
377 manifestJsonOut android.WritablePath
378
379 // Processed apex manifest in PB format (for R+)
380 manifestPbOut android.WritablePath
381
382 // Processed file_contexts files
383 fileContexts android.WritablePath
384
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900385 // Struct holding the merged notice file paths in different formats
386 mergedNotices android.NoticeOutputs
387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900388 // The built APEX file. This is the main product.
389 outputFile android.WritablePath
390
391 // The built APEX file in app bundle format. This file is not directly installed to the
392 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
393 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
394 // system) to be merged into a single app bundle file that Play accepts. See
395 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
396 bundleModuleFile android.WritablePath
397
398 // Target path to install this APEX. Usually out/target/product/<device>/<partition>/apex.
399 installDir android.InstallPath
400
401 // List of commands to create symlinks for backward compatibility. These commands will be
402 // attached as LOCAL_POST_INSTALL_CMD to apex package itself (for unflattened build) or
403 // apex_manifest (for flattened build) so that compat symlinks are always installed
404 // regardless of TARGET_FLATTEN_APEX setting.
405 compatSymlinks []string
406
407 // Text file having the list of individual files that are included in this APEX. Used for
408 // debugging purpose.
409 installedFilesFile android.WritablePath
410
411 // List of module names that this APEX is including (to be shown via *-deps-info target).
412 // Used for debugging purpose.
413 android.ApexBundleDepsInfo
414
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900415 // Optional list of lint report zip files for apexes that contain java or app modules
416 lintReports android.Paths
417
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900418 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000419
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000420 isCompressed bool
421
sophiezc80a2b32020-11-12 16:39:19 +0000422 // Path of API coverage generate file
sophiez6bde0b52021-01-09 01:03:42 +0000423 apisUsedByModuleFile android.ModuleOutPath
424 apisBackedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800425
426 // Collect the module directory for IDE info in java/jdeps.go.
427 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900428}
429
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900430// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900431type apexFileClass int
432
Jooyung Han72bd2f82019-10-23 16:46:38 +0900433const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900434 app apexFileClass = iota
435 appSet
436 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900437 goBinary
438 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900439 nativeExecutable
440 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900441 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900442 pyBinary
443 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900444)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900445
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900446// apexFile represents a file in an APEX bundle. This is created during the first half of
447// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
448// of the function, this is used to create commands that copies the files into a staging directory,
449// where they are packaged into the APEX file. This struct is also used for creating Make modules
450// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900451type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900452 // buildFile is put in the installDir inside the APEX.
453 builtFile android.Path
454 noticeFiles android.Paths
455 installDir string
456 customStem string
457 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900458
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900459 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
460 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
461 // suffix>]
462 androidMkModuleName string // becomes LOCAL_MODULE
463 class apexFileClass // becomes LOCAL_MODULE_CLASS
464 moduleDir string // becomes LOCAL_PATH
465 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
466 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
467 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
468 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900469
470 jacocoReportClassesFile android.Path // only for javalibs and apps
471 lintDepSets java.LintDepSets // only for javalibs and apps
472 certificate java.Certificate // only for apps
473 overriddenPackageName string // only for apps
474
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900475 transitiveDep bool
476 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900477
Jiyong Park57621b22021-01-20 20:33:11 +0900478 multilib string
479
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900480 // TODO(jiyong): remove this
481 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900482}
483
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900484// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900485func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
486 ret := apexFile{
487 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900488 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900489 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900490 class: class,
491 module: module,
492 }
493 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900494 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900495 ret.moduleDir = ctx.OtherModuleDir(module)
496 ret.requiredModuleNames = module.RequiredModuleNames()
497 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
498 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900499 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900500 }
501 return ret
502}
503
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900504func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900505 return af.builtFile != nil && af.builtFile.String() != ""
506}
507
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900508// apexRelativePath returns the relative path of the given path from the install directory of this
509// apexFile.
510// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900511func (af *apexFile) apexRelativePath(path string) string {
512 return filepath.Join(af.installDir, path)
513}
514
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900515// path returns path of this apex file relative to the APEX root
516func (af *apexFile) path() string {
517 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900518}
519
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900520// stem returns the base filename of this apex file
521func (af *apexFile) stem() string {
522 if af.customStem != "" {
523 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900524 }
525 return af.builtFile.Base()
526}
527
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900528// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
529func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900530 var ret []string
531 for _, symlink := range af.symlinks {
532 ret = append(ret, af.apexRelativePath(symlink))
533 }
534 return ret
535}
536
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900537// availableToPlatform tests whether this apexFile is from a module that can be installed to the
538// platform.
539func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900540 if af.module == nil {
541 return false
542 }
543 if am, ok := af.module.(android.ApexModule); ok {
544 return am.AvailableFor(android.AvailableToPlatform)
545 }
546 return false
547}
548
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900549////////////////////////////////////////////////////////////////////////////////////////////////////
550// Mutators
551//
552// Brief description about mutators for APEX. The following three mutators are the most important
553// ones.
554//
555// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
556// to the (direct) dependencies of this APEX bundle.
557//
Paul Duffin949abc02020-12-08 10:34:30 +0000558// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900559// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
560// modules are marked as being included in the APEX via BuildForApex().
561//
Paul Duffin949abc02020-12-08 10:34:30 +0000562// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
563// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900564
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900565type dependencyTag struct {
566 blueprint.BaseDependencyTag
567 name string
568
569 // Determines if the dependent will be part of the APEX payload. Can be false for the
570 // dependencies to the signing key module, etc.
571 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000572
573 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
574 // replacement. This is needed because some prebuilt modules do not provide all the information
575 // needed by the apex.
576 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900577}
578
Paul Duffin8c535da2021-03-17 14:51:03 +0000579func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
580 return !d.sourceOnly
581}
582
583var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
584
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900585var (
Paul Duffin0b817782021-03-17 15:02:19 +0000586 androidAppTag = dependencyTag{name: "androidApp", payload: true}
587 bpfTag = dependencyTag{name: "bpf", payload: true}
588 certificateTag = dependencyTag{name: "certificate"}
589 executableTag = dependencyTag{name: "executable", payload: true}
590 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100591 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100592 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000593 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000594 javaLibTag = dependencyTag{name: "javaLib", payload: true}
595 jniLibTag = dependencyTag{name: "jniLib", payload: true}
596 keyTag = dependencyTag{name: "key"}
597 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
598 rroTag = dependencyTag{name: "rro", payload: true}
599 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
600 testForTag = dependencyTag{name: "test for"}
601 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900602)
603
604// TODO(jiyong): shorten this function signature
605func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900606 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900607 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900608 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900609
610 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900611 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900612 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
613 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900614 }
615
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900616 // Use *FarVariation* to be able to depend on modules having conflicting variations with
617 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
618 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900619 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900620 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900621 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
622 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900623 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900624 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900625}
626
627func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900628 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900629 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
630 } else {
631 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
632 if ctx.Os().Bionic() {
633 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
634 } else {
635 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
636 }
637 }
638}
639
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
641// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
642func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
643 deviceConfig := ctx.DeviceConfig()
644 if a.vndkApex {
645 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900646 }
647
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900648 var prefix string
649 var vndkVersion string
650 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000651 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900652 prefix = cc.VendorVariationPrefix
653 vndkVersion = deviceConfig.VndkVersion()
654 } else if a.ProductSpecific() {
655 prefix = cc.ProductVariationPrefix
656 vndkVersion = deviceConfig.ProductVndkVersion()
657 }
658 }
659 if vndkVersion == "current" {
660 vndkVersion = deviceConfig.PlatformVndkVersion()
661 }
662 if vndkVersion != "" {
663 return prefix + vndkVersion
664 }
665
666 return android.CoreVariation // The usual case
667}
668
669func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900670 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
671 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
672 // each target os/architectures, appropriate dependencies are selected by their
673 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900674 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900675 imageVariation := a.getImageVariation(ctx)
676
677 a.combineProperties(ctx)
678
679 has32BitTarget := false
680 for _, target := range targets {
681 if target.Arch.ArchType.Multilib == "lib32" {
682 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000683 }
684 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900685 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900686 // Don't include artifacts for the host cross targets because there is no way for us
687 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900688 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900689 continue
690 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000691
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900692 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000693
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900694 // Add native modules targeting both ABIs. When multilib.* is omitted for
695 // native_shared_libs/jni_libs/tests, it implies multilib.both
696 depsList = append(depsList, a.properties.Multilib.Both)
697 depsList = append(depsList, ApexNativeDependencies{
698 Native_shared_libs: a.properties.Native_shared_libs,
699 Tests: a.properties.Tests,
700 Jni_libs: a.properties.Jni_libs,
701 Binaries: nil,
702 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900703
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900704 // Add native modules targeting the first ABI When multilib.* is omitted for
705 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900706 isPrimaryAbi := i == 0
707 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900708 depsList = append(depsList, a.properties.Multilib.First)
709 depsList = append(depsList, ApexNativeDependencies{
710 Native_shared_libs: nil,
711 Tests: nil,
712 Jni_libs: nil,
713 Binaries: a.properties.Binaries,
714 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900715 }
716
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900717 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900718 switch target.Arch.ArchType.Multilib {
719 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900720 depsList = append(depsList, a.properties.Multilib.Lib32)
721 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900722 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900723 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900724 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900725 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900726 }
727 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900728
Jiyong Park59140302020-12-14 18:44:04 +0900729 // Add native modules targeting a specific arch variant
730 switch target.Arch.ArchType {
731 case android.Arm:
732 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
733 case android.Arm64:
734 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
735 case android.X86:
736 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
737 case android.X86_64:
738 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
739 default:
740 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
741 }
742
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900743 for _, d := range depsList {
744 addDependenciesForNativeModules(ctx, d, target, imageVariation)
745 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900746 }
747
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900748 // Common-arch dependencies come next
749 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100750 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100751 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900752 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900753 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000754 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900755
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900756 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
757 // This field currently isn't used.
758 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900759 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
760 if len(a.properties.Uses_sdks) > 0 {
761 sdkRefs := []android.SdkRef{}
762 for _, str := range a.properties.Uses_sdks {
763 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
764 sdkRefs = append(sdkRefs, parsed)
765 }
766 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100767 }
768}
769
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900770// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900771func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
772 if a.overridableProperties.Allowed_files != nil {
773 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100774 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900775
776 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
777 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800778 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900779 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700780 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
781 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
782 // regardless of the TARGET_PREFER_* setting. See b/144532908
783 arches := ctx.DeviceConfig().Arches()
784 if len(arches) != 0 {
785 archForPrebuiltEtc := arches[0]
786 for _, arch := range arches {
787 // Prefer 64-bit arch if there is any
788 if arch.ArchType.Multilib == "lib64" {
789 archForPrebuiltEtc = arch
790 break
791 }
792 }
793 ctx.AddFarVariationDependencies([]blueprint.Variation{
794 {Mutator: "os", Variation: ctx.Os().String()},
795 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
796 }, prebuiltTag, prebuilts...)
797 }
798 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700799
800 // Dependencies for signing
801 if String(a.overridableProperties.Key) == "" {
802 ctx.PropertyErrorf("key", "missing")
803 return
804 }
805 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
806
807 cert := android.SrcIsModule(a.getCertString(ctx))
808 if cert != "" {
809 ctx.AddDependency(ctx.Module(), certificateTag, cert)
810 // empty cert is not an error. Cert and private keys will be directly found under
811 // PRODUCT_DEFAULT_DEV_CERTIFICATE
812 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100813}
814
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900815type ApexBundleInfo struct {
816 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100817}
818
Paul Duffin949abc02020-12-08 10:34:30 +0000819var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900820
Paul Duffina7d6a892020-12-07 17:39:59 +0000821var _ ApexInfoMutator = (*apexBundle)(nil)
822
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100823func (a *apexBundle) ApexVariationName() string {
824 return a.properties.ApexVariationName
825}
826
Paul Duffina7d6a892020-12-07 17:39:59 +0000827// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900828// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
829// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
830// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
831// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000832//
833// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
834// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
835// The apexMutator uses that list to create module variants for the apexes to which it belongs.
836// The relationship between module variants and apexes is not one-to-one as variants will be
837// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000838func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900839
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900840 // The VNDK APEX is special. For the APEX, the membership is described in a very different
841 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
842 // libraries are self-identified by their vndk.enabled properties. There is no need to run
843 // this mutator for the APEX as nothing will be collected. So, let's return fast.
844 if a.vndkApex {
845 return
846 }
847
848 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
849 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
850 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
851 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
852 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900853 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
854 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
855 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
856 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
857 return
858 }
859
Colin Cross56a83212020-09-15 18:30:11 -0700860 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900861 am, ok := child.(android.ApexModule)
862 if !ok || !am.CanHaveApexVariants() {
863 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900864 }
Paul Duffin573989d2021-03-17 13:25:29 +0000865 depTag := mctx.OtherModuleDependencyTag(child)
866
867 // Check to see if the tag always requires that the child module has an apex variant for every
868 // apex variant of the parent module. If it does not then it is still possible for something
869 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
870 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
871 return true
872 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000873 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900874 return false
875 }
Jooyung Handf78e212020-07-22 15:54:47 +0900876 if excludeVndkLibs {
877 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
878 return false
879 }
880 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900881 // By default, all the transitive dependencies are collected, unless filtered out
882 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700883 return true
884 }
885
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900886 // Records whether a certain module is included in this apexBundle via direct dependency or
887 // inndirect dependency.
888 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700889 mctx.WalkDeps(func(child, parent android.Module) bool {
890 if !continueApexDepsWalk(child, parent) {
891 return false
892 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900893 // If the parent is apexBundle, this child is directly depended.
894 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900895 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700896 contents[depName] = contents[depName].Add(directDep)
897 return true
898 })
899
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900900 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900901 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700902 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
903 Contents: apexContents,
904 })
905
Jooyung Haned124c32021-01-26 11:43:46 +0900906 minSdkVersion := a.minSdkVersion(mctx)
907 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
908 if minSdkVersion.IsNone() {
909 minSdkVersion = android.FutureApiLevel
910 }
911
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900912 // This is the main part of this mutator. Mark the collected dependencies that they need to
913 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900914
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100915 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
916 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700917 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100918 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900919 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700920 RequiredSdks: a.RequiredSdks(),
921 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900922 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100923 InApexVariants: []string{apexVariationName},
924 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700925 ApexContents: []*android.ApexContents{apexContents},
926 }
Colin Cross56a83212020-09-15 18:30:11 -0700927 mctx.WalkDeps(func(child, parent android.Module) bool {
928 if !continueApexDepsWalk(child, parent) {
929 return false
930 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900931 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900932 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900933 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900934}
935
Paul Duffina7d6a892020-12-07 17:39:59 +0000936type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100937 // ApexVariationName returns the name of the APEX variation to use in the apex
938 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
939 ApexVariationName() string
940
Paul Duffina7d6a892020-12-07 17:39:59 +0000941 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
942 // depended upon by an apex and which require an apex specific variant.
943 ApexInfoMutator(android.TopDownMutatorContext)
944}
945
946// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
947// specific variant to modules that support the ApexInfoMutator.
948func apexInfoMutator(mctx android.TopDownMutatorContext) {
949 if !mctx.Module().Enabled() {
950 return
951 }
952
953 if a, ok := mctx.Module().(ApexInfoMutator); ok {
954 a.ApexInfoMutator(mctx)
955 return
956 }
957}
958
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900959// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
960// unique apex variations for this module. See android/apex.go for more about unique apex variant.
961// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700962func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
963 if !mctx.Module().Enabled() {
964 return
965 }
966 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700967 android.UpdateUniqueApexVariationsForDeps(mctx, am)
968 }
969}
970
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900971// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
972// the apex in order to retrieve its contents later.
973// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700974func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
975 if !mctx.Module().Enabled() {
976 return
977 }
Colin Cross56a83212020-09-15 18:30:11 -0700978 if am, ok := mctx.Module().(android.ApexModule); ok {
979 if testFor := am.TestFor(); len(testFor) > 0 {
980 mctx.AddFarVariationDependencies([]blueprint.Variation{
981 {Mutator: "os", Variation: am.Target().OsVariation()},
982 {"arch", "common"},
983 }, testForTag, testFor...)
984 }
985 }
986}
987
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900988// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700989func apexTestForMutator(mctx android.BottomUpMutatorContext) {
990 if !mctx.Module().Enabled() {
991 return
992 }
Colin Cross56a83212020-09-15 18:30:11 -0700993 if _, ok := mctx.Module().(android.ApexModule); ok {
994 var contents []*android.ApexContents
995 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
996 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
997 contents = append(contents, abInfo.Contents)
998 }
999 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1000 ApexContents: contents,
1001 })
Colin Crossaede88c2020-08-11 12:17:01 -07001002 }
1003}
1004
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001005// markPlatformAvailability marks whether or not a module can be available to platform. A module
1006// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1007// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1008// be) available to platform
1009// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001010func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1011 // Host and recovery are not considered as platform
1012 if mctx.Host() || mctx.Module().InstallInRecovery() {
1013 return
1014 }
1015
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001016 am, ok := mctx.Module().(android.ApexModule)
1017 if !ok {
1018 return
1019 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001020
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001021 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001022
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001023 // If any of the dep is not available to platform, this module is also considered as being
1024 // not available to platform even if it has "//apex_available:platform"
1025 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001026 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001027 // if the dependency crosses apex boundary, don't consider it
1028 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001029 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001030 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1031 availableToPlatform = false
1032 // TODO(b/154889534) trigger an error when 'am' has
1033 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001034 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001035 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001036
Paul Duffinb5769c12021-05-12 16:16:51 +01001037 // Exception 1: check to see if the module always requires it.
1038 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001039 availableToPlatform = true
1040 }
1041
1042 // Exception 2: bootstrap bionic libraries are also always available to platform
1043 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1044 availableToPlatform = true
1045 }
1046
1047 if !availableToPlatform {
1048 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001049 }
1050}
1051
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001052// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001053// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001055 if !mctx.Module().Enabled() {
1056 return
1057 }
Colin Cross56a83212020-09-15 18:30:11 -07001058
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001059 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001060 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001061 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001062 return
1063 }
1064
1065 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001066 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1067 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001069 if strings.HasPrefix(apexBundleName, "com.android.art") {
1070 // Create an alias from the platform variant. This is done to make
1071 // test_for dependencies work for modules that are split by the APEX
1072 // mutator, since test_for dependencies always go to the platform variant.
1073 // This doesn't happen for normal APEXes that are disjunct, so only do
1074 // this for the overlapping ART APEXes.
1075 // TODO(b/183882457): Remove this if the test_for functionality is
1076 // refactored to depend on the proper APEX variants instead of platform.
1077 mctx.CreateAliasVariation("", apexBundleName)
1078 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001079 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1080 apexBundleName := o.GetOverriddenModuleName()
1081 if apexBundleName == "" {
1082 mctx.ModuleErrorf("base property is not set")
1083 return
1084 }
1085 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001086 if strings.HasPrefix(apexBundleName, "com.android.art") {
1087 // TODO(b/183882457): See note for CreateAliasVariation above.
1088 mctx.CreateAliasVariation("", apexBundleName)
1089 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001090 }
1091}
Sundong Ahne9b55722019-09-06 17:37:42 +09001092
Paul Duffin6717d882021-06-15 19:09:41 +01001093// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1094// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001095func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001096 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001097 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001098 return !a.vndkApex
1099 }
1100
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001101 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001102}
1103
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001104// See android.UpdateDirectlyInAnyApex
1105// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001106func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1107 if !mctx.Module().Enabled() {
1108 return
1109 }
1110 if am, ok := mctx.Module().(android.ApexModule); ok {
1111 android.UpdateDirectlyInAnyApex(mctx, am)
1112 }
1113}
1114
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001115// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001116type apexPackaging int
1117
1118const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001119 // imageApex is a packaging method where contents are included in a filesystem image which
1120 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001121 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001122
1123 // zipApex is a packaging method where contents are directly included in the zip container.
1124 // This is used for host-side testing - because the contents are easily accessible by
1125 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001126 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001127
1128 // flattendApex is a packaging method where contents are not included in the APEX file, but
1129 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1130 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001131 flattenedApex
1132)
1133
1134const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001135 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001136 imageApexSuffix = ".apex"
1137 imageCapexSuffix = ".capex"
1138 zipApexSuffix = ".zipapex"
1139 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001140
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001141 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001142 imageApexType = "image"
1143 zipApexType = "zip"
1144 flattenedApexType = "flattened"
1145
Dan Willemsen47e1a752021-10-16 18:36:13 -07001146 ext4FsType = "ext4"
1147 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001148 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001149)
1150
1151// The suffix for the output "file", not the module
1152func (a apexPackaging) suffix() string {
1153 switch a {
1154 case imageApex:
1155 return imageApexSuffix
1156 case zipApex:
1157 return zipApexSuffix
1158 default:
1159 panic(fmt.Errorf("unknown APEX type %d", a))
1160 }
1161}
1162
1163func (a apexPackaging) name() string {
1164 switch a {
1165 case imageApex:
1166 return imageApexType
1167 case zipApex:
1168 return zipApexType
1169 default:
1170 panic(fmt.Errorf("unknown APEX type %d", a))
1171 }
1172}
1173
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001174// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1175// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001176func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001177 if !mctx.Module().Enabled() {
1178 return
1179 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001180 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001181 var variants []string
1182 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1183 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001184 // This is the normal case. Note that both image and flattend APEXes are
1185 // created. The image type is installed to the system partition, while the
1186 // flattened APEX is (optionally) installed to the system_ext partition.
1187 // This is mostly for GSI which has to support wide range of devices. If GSI
1188 // is installed on a newer (APEX-capable) device, the image APEX in the
1189 // system will be used. However, if the same GSI is installed on an old
1190 // device which can't support image APEX, the flattened APEX in the
1191 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001192 variants = append(variants, imageApexType, flattenedApexType)
1193 case "zip":
1194 variants = append(variants, zipApexType)
1195 case "both":
1196 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1197 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001198 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001199 return
1200 }
1201
1202 modules := mctx.CreateLocalVariations(variants...)
1203
1204 for i, v := range variants {
1205 switch v {
1206 case imageApexType:
1207 modules[i].(*apexBundle).properties.ApexType = imageApex
1208 case zipApexType:
1209 modules[i].(*apexBundle).properties.ApexType = zipApex
1210 case flattenedApexType:
1211 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001212 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001213 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001214 modules[i].(*apexBundle).MakeAsSystemExt()
1215 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001216 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001217 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001218 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001219 // payload_type is forcibly overridden to "image"
1220 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001221 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001222 }
1223}
1224
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001225var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001226
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001227// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001228func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1229 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001230 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001231 return true
1232}
1233
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001234var _ android.OutputFileProducer = (*apexBundle)(nil)
1235
1236// Implements android.OutputFileProducer
1237func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1238 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001239 case "", android.DefaultDistTag:
1240 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001241 return android.Paths{a.outputFile}, nil
1242 default:
1243 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1244 }
1245}
1246
1247var _ cc.Coverage = (*apexBundle)(nil)
1248
1249// Implements cc.Coverage
1250func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1251 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1252}
1253
1254// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001255func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001256 a.properties.PreventInstall = true
1257}
1258
1259// Implements cc.Coverage
1260func (a *apexBundle) HideFromMake() {
1261 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001262 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1263 // TODO(ccross): untangle these
1264 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001265}
1266
1267// Implements cc.Coverage
1268func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1269 a.properties.IsCoverageVariant = coverage
1270}
1271
1272// Implements cc.Coverage
1273func (a *apexBundle) EnableCoverageIfNeeded() {}
1274
1275var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1276
1277// Implements android.ApexBudleDepsInfoIntf
1278func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001279 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001280}
1281
Jiyong Park1bc84122021-06-22 20:23:05 +09001282func (a *apexBundle) UsePlatformApis() bool {
1283 return proptools.BoolDefault(a.properties.Platform_apis, false)
1284}
1285
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001286// getCertString returns the name of the cert that should be used to sign this APEX. This is
1287// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001288func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001289 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001290 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1291 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1292 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001293 if a.vndkApex {
1294 moduleName = vndkApexName
1295 }
1296 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001297 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001298 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001299 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001300 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001301}
1302
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001303// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001304func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001305 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001306}
1307
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001308// See the generate_hashtree property
1309func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001310 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001311}
1312
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001313// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001314func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1315 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1316}
1317
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001318// See the test_only_force_compression property
1319func (a *apexBundle) testOnlyShouldForceCompression() bool {
1320 return proptools.Bool(a.properties.Test_only_force_compression)
1321}
1322
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001323// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1324// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1325// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001326
Jiyong Parkf97782b2019-02-13 20:28:58 +09001327func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1328 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1329 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1330 }
1331}
1332
Jiyong Park388ef3f2019-01-28 19:47:32 +09001333func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001334 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1335 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001336 }
1337
1338 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001339 globalSanitizerNames := []string{}
1340 if a.Host() {
1341 globalSanitizerNames = ctx.Config().SanitizeHost()
1342 } else {
1343 arches := ctx.Config().SanitizeDeviceArch()
1344 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1345 globalSanitizerNames = ctx.Config().SanitizeDevice()
1346 }
1347 }
1348 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001349}
1350
Jooyung Han8ce8db92020-05-15 19:05:05 +09001351func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001352 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1353 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001354 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001355 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001356 for _, target := range ctx.MultiTargets() {
1357 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001358 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1359 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1360 Tests: nil,
1361 Jni_libs: nil,
1362 Binaries: nil,
1363 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001364 break
1365 }
1366 }
1367 }
1368}
1369
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001370// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1371// returned apexFile saves information about the Soong module that will be used for creating the
1372// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001373func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001374 // Decide the APEX-local directory by the multilib of the library In the future, we may
1375 // query this to the module.
1376 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001377 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001378 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001379 case "lib32":
1380 dirInApex = "lib"
1381 case "lib64":
1382 dirInApex = "lib64"
1383 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001384 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001385 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001386 }
Jooyung Han35155c42020-02-06 17:33:20 +09001387 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001388 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001389 // Special case for Bionic libs and other libs installed with them. This is to
1390 // prevent those libs from being included in the search path
1391 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1392 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1393 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1394 // will be loaded into the default linker namespace (aka "platform" namespace). If
1395 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1396 // be loaded again into the runtime linker namespace, which will result in double
1397 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001398 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001399 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001400
Jiyong Parkf653b052019-11-18 15:39:01 +09001401 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001402 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1403 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001404}
1405
Jiyong Park1833cef2019-12-13 13:28:36 +09001406func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001407 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001408 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001409 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001410 }
Jooyung Han35155c42020-02-06 17:33:20 +09001411 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001412 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001413 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1414 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001415 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001416 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001417 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001418}
1419
Jiyong Park99644e92020-11-17 22:21:02 +09001420func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1421 dirInApex := "bin"
1422 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1423 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1424 }
1425 fileToCopy := rustm.OutputFile().Path()
1426 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1427 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1428 return af
1429}
1430
1431func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1432 // Decide the APEX-local directory by the multilib of the library
1433 // In the future, we may query this to the module.
1434 var dirInApex string
1435 switch rustm.Arch().ArchType.Multilib {
1436 case "lib32":
1437 dirInApex = "lib"
1438 case "lib64":
1439 dirInApex = "lib64"
1440 }
1441 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1442 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1443 }
1444 fileToCopy := rustm.OutputFile().Path()
1445 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1446 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1447}
1448
Jiyong Park1833cef2019-12-13 13:28:36 +09001449func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001450 dirInApex := "bin"
1451 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001452 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001453}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001454
Jiyong Park1833cef2019-12-13 13:28:36 +09001455func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001456 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001457 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001458 // NB: Since go binaries are static we don't need the module for anything here, which is
1459 // good since the go tool is a blueprint.Module not an android.Module like we would
1460 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001461 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001462}
1463
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001464func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001465 dirInApex := filepath.Join("bin", sh.SubDir())
1466 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001467 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001468 af.symlinks = sh.Symlinks()
1469 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001470}
1471
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001472func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001473 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001474 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001475 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001476}
1477
atrost6e126252020-01-27 17:01:16 +00001478func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1479 dirInApex := filepath.Join("etc", config.SubDir())
1480 fileToCopy := config.CompatConfig()
1481 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1482}
1483
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001484// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1485// way.
1486type javaModule interface {
1487 android.Module
1488 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001489 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001490 JacocoReportClassesFile() android.Path
1491 LintDepSets() java.LintDepSets
1492 Stem() string
1493}
1494
1495var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001496var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001497var _ javaModule = (*java.SdkLibrary)(nil)
1498var _ javaModule = (*java.DexImport)(nil)
1499var _ javaModule = (*java.SdkLibraryImport)(nil)
1500
Paul Duffin190fdef2021-04-26 10:33:59 +01001501// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001502func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001503 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001504}
1505
1506// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1507func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001508 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001509 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001510 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1511 af.lintDepSets = module.LintDepSets()
1512 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001513 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1514 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1515 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1516 }
1517 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001518 return af
1519}
1520
1521// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1522// the same way.
1523type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001524 android.Module
1525 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001526 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001527 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001528 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001529 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001530 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001531 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001532}
1533
1534var _ androidApp = (*java.AndroidApp)(nil)
1535var _ androidApp = (*java.AndroidAppImport)(nil)
1536
1537func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001538 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001539 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001540 appDir = "priv-app"
1541 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001542 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001543 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001544 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001545 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001546 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001547 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001548
1549 if app, ok := aapp.(interface {
1550 OverriddenManifestPackageName() string
1551 }); ok {
1552 af.overriddenPackageName = app.OverriddenManifestPackageName()
1553 }
Jiyong Park618922e2020-01-08 13:35:43 +09001554 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001555}
1556
Jiyong Park69aeba92020-04-24 21:16:36 +09001557func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1558 rroDir := "overlay"
1559 dirInApex := filepath.Join(rroDir, rro.Theme())
1560 fileToCopy := rro.OutputFile()
1561 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1562 af.certificate = rro.Certificate()
1563
1564 if a, ok := rro.(interface {
1565 OverriddenManifestPackageName() string
1566 }); ok {
1567 af.overriddenPackageName = a.OverriddenManifestPackageName()
1568 }
1569 return af
1570}
1571
markchien2f59ec92020-09-02 16:23:38 +08001572func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1573 dirInApex := filepath.Join("etc", "bpf")
1574 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1575}
1576
Jiyong Park12a719c2021-01-07 15:31:24 +09001577func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1578 dirInApex := filepath.Join("etc", "fs")
1579 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1580}
1581
Paul Duffin064b70c2020-11-02 17:32:38 +00001582// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001583// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1584// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1585// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001586func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001587 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001588 am, ok := child.(android.ApexModule)
1589 if !ok || !am.CanHaveApexVariants() {
1590 return false
1591 }
1592
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001593 // Filter-out unwanted depedendencies
1594 depTag := ctx.OtherModuleDependencyTag(child)
1595 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1596 return false
1597 }
1598 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001599 return false
1600 }
1601
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001602 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001603 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001604
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001605 // Visit actually
1606 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001607 })
1608}
1609
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001610// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1611type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001612
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001613const (
1614 ext4 fsType = iota
1615 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001616 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001617)
Artur Satayev849f8442020-04-28 14:57:42 +01001618
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001619func (f fsType) string() string {
1620 switch f {
1621 case ext4:
1622 return ext4FsType
1623 case f2fs:
1624 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001625 case erofs:
1626 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001627 default:
1628 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001629 }
1630}
1631
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632// Creates build rules for an APEX. It consists of the following major steps:
1633//
1634// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1635// 2) traverse the dependency tree to collect apexFile structs from them.
1636// 3) some fields in apexBundle struct are configured
1637// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001638func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001639 ////////////////////////////////////////////////////////////////////////////////////////////
1640 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001641 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001642 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001643 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001644 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001645 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001646 if len(a.properties.Tests) > 0 && !a.testApex {
1647 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1648 return
1649 }
Jiyong Park678c8812020-02-07 17:25:49 +09001650
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001651 ////////////////////////////////////////////////////////////////////////////////////////////
1652 // 2) traverse the dependency tree to collect apexFile structs from them.
1653
1654 // all the files that will be included in this APEX
1655 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001656
Jooyung Hane1633032019-08-01 17:41:43 +09001657 // native lib dependencies
1658 var provideNativeLibs []string
1659 var requireNativeLibs []string
1660
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001661 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1662
braleeb0c1f0c2021-06-07 22:49:13 +08001663 // Collect the module directory for IDE info in java/jdeps.go.
1664 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1665
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001666 // TODO(jiyong): do this using WalkPayloadDeps
1667 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001668 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001669 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001670 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1671 return false
1672 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001673 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1674 return false
1675 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001676 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001678 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001679 case sharedLibTag, jniLibTag:
1680 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001681 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001682 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1683 fi.isJniLib = isJniLib
1684 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001685 // Collect the list of stub-providing libs except:
1686 // - VNDK libs are only for vendors
1687 // - bootstrap bionic libs are treated as provided by system
1688 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001689 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001690 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001692 } else if r, ok := child.(*rust.Module); ok {
1693 fi := apexFileForRustLibrary(ctx, r)
1694 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001695 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001696 propertyName := "native_shared_libs"
1697 if isJniLib {
1698 propertyName = "jni_libs"
1699 }
1700 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001701 }
1702 case executableTag:
1703 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001704 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001706 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001707 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001708 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001709 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001710 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001712 } else if rust, ok := child.(*rust.Module); ok {
1713 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1714 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001715 } else {
Jiyong Park99644e92020-11-17 22:21:02 +09001716 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001717 }
Paul Duffin94f19632021-04-20 12:40:07 +01001718 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001719 {
Paul Duffin7771eba2021-04-23 14:25:28 +01001720 if _, ok := child.(*java.BootclasspathFragmentModule); !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001721 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001722 return false
1723 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001724
Paul Duffincc33ec82021-04-25 23:14:55 +01001725 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1726 filesInfo = append(filesInfo, filesToAdd...)
Paul Duffin4d101b62021-03-24 15:42:20 +00001727 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001728 }
satayev333a1732021-05-17 21:35:26 +01001729 case sscpfTag:
1730 {
1731 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1732 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1733 return false
1734 }
satayevb98371c2021-06-15 16:49:50 +01001735 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1736 filesInfo = append(filesInfo, *af)
1737 }
satayev333a1732021-05-17 21:35:26 +01001738 return true
1739 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001740 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001741 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001742 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001743 af := apexFileForJavaModule(ctx, child.(javaModule))
1744 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001745 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1746 return false
1747 }
1748 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001749 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001750 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001751 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001752 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001753 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001754 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001755 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001756 return true // track transitive dependencies
1757 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001758 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001759 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001760 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001761 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1762 appDir := "app"
1763 if ap.Privileged() {
1764 appDir = "priv-app"
1765 }
Yo Chiange8128052020-07-23 20:09:18 +08001766 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001767 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1768 af.certificate = java.PresignedCertificate
1769 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001770 } else {
1771 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1772 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001773 case rroTag:
1774 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1775 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1776 } else {
1777 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1778 }
markchien2f59ec92020-09-02 16:23:38 +08001779 case bpfTag:
1780 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1781 filesToCopy, _ := bpfProgram.OutputFiles("")
1782 for _, bpfFile := range filesToCopy {
1783 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1784 }
1785 } else {
1786 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1787 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001788 case fsTag:
1789 if fs, ok := child.(filesystem.Filesystem); ok {
1790 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1791 } else {
1792 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1793 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001794 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001795 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001796 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001797 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001798 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001799 }
Paul Duffin0b817782021-03-17 15:02:19 +00001800 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001801 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1802 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1803 } else {
1804 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1805 }
Roland Levillain630846d2019-06-26 12:48:34 +01001806 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001807 if ccTest, ok := child.(*cc.Module); ok {
1808 if ccTest.IsTestPerSrcAllTestsVariation() {
1809 // Multiple-output test module (where `test_per_src: true`).
1810 //
1811 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1812 // We do not add this variation to `filesInfo`, as it has no output;
1813 // however, we do add the other variations of this module as indirect
1814 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001815 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001816 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001817 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001818 af.class = nativeTest
1819 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001820 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001821 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001822 } else {
1823 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1824 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001825 case keyTag:
1826 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001827 a.privateKeyFile = key.privateKeyFile
1828 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001829 } else {
1830 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001831 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001832 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001833 case certificateTag:
1834 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001835 a.containerCertificateFile = dep.Certificate.Pem
1836 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001837 } else {
1838 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1839 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001840 case android.PrebuiltDepTag:
1841 // If the prebuilt is force disabled, remember to delete the prebuilt file
1842 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001843 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001844 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1845 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001846 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001847 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001848 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001849 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001850 // We cannot use a switch statement on `depTag` here as the checked
1851 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001852 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001853 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001854 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001855 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001856 return false
1857 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001858 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1859 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001860
1861 // Always track transitive dependencies for host.
1862 if a.Host() {
1863 filesInfo = append(filesInfo, af)
1864 return true
1865 }
1866
Colin Cross56a83212020-09-15 18:30:11 -07001867 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001868 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001869 // If the dependency is a stubs lib, don't include it in this APEX,
1870 // but make sure that the lib is installed on the device.
1871 // In case no APEX is having the lib, the lib is installed to the system
1872 // partition.
1873 //
1874 // Always include if we are a host-apex however since those won't have any
1875 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001876 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001877 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001878 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001879 if !android.InList(name, a.requiredDeps) {
1880 a.requiredDeps = append(a.requiredDeps, name)
1881 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001882 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001883 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001884 // Don't track further
1885 return false
1886 }
Jiyong Parke3867542020-12-03 17:28:25 +09001887
1888 // If the dep is not considered to be in the same
1889 // apex, don't add it to filesInfo so that it is not
1890 // included in this APEX.
1891 // TODO(jiyong): move this to at the top of the
1892 // else-if clause for the indirect dependencies.
1893 // Currently, that's impossible because we would
1894 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001895 // DepIsInSameAPex is false. We also shouldn't do
1896 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001897 //
1898 // TODO(jiyong): explain why the same module is passed in twice.
1899 // Switching the first am to parent breaks lots of tests.
1900 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001901 return false
1902 }
1903
Jiyong Parkf653b052019-11-18 15:39:01 +09001904 filesInfo = append(filesInfo, af)
1905 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001906 } else if rm, ok := child.(*rust.Module); ok {
1907 af := apexFileForRustLibrary(ctx, rm)
1908 af.transitiveDep = true
1909 filesInfo = append(filesInfo, af)
1910 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001911 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001912 } else if cc.IsTestPerSrcDepTag(depTag) {
1913 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001914 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001915 // Handle modules created as `test_per_src` variations of a single test module:
1916 // use the name of the generated test binary (`fileToCopy`) instead of the name
1917 // of the original test module (`depName`, shared by all `test_per_src`
1918 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001919 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001920 // these are not considered transitive dep
1921 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001922 filesInfo = append(filesInfo, af)
1923 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001924 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001925 } else if cc.IsHeaderDepTag(depTag) {
1926 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001927 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001928 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1929 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001930 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001931 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001932 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1933 }
Jiyong Park99644e92020-11-17 22:21:02 +09001934 } else if rust.IsDylibDepTag(depTag) {
1935 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1936 af := apexFileForRustLibrary(ctx, rustm)
1937 af.transitiveDep = true
1938 filesInfo = append(filesInfo, af)
1939 return true // track transitive dependencies
1940 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09001941 } else if rust.IsRlibDepTag(depTag) {
1942 // Rlib is statically linked, but it might have shared lib
1943 // dependencies. Track them.
1944 return true
Paul Duffin65898052021-04-20 22:47:03 +01001945 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01001946 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00001947 switch child.(type) {
1948 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01001949 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01001950 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00001951 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01001952 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00001953 return false
1954 }
1955 filesInfo = append(filesInfo, af)
1956 return true // track transitive dependencies
1957 default:
Paul Duffin94f19632021-04-20 12:40:07 +01001958 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 +00001959 }
satayev333a1732021-05-17 21:35:26 +01001960 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
1961 // Add the contents of the systemserverclasspath fragment to the apex.
1962 switch child.(type) {
1963 case *java.Library, *java.SdkLibrary:
1964 af := apexFileForJavaModule(ctx, child.(javaModule))
1965 filesInfo = append(filesInfo, af)
1966 return true // track transitive dependencies
1967 default:
1968 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
1969 }
Colin Cross56a83212020-09-15 18:30:11 -07001970 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
1971 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09001972 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09001973 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001974 }
1975 }
1976 }
1977 return false
1978 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001979 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001980 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001981 return
1982 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001983
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001984 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09001985 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001986 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001987 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001988 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001989 if e, ok := encountered[dest]; !ok {
1990 encountered[dest] = f
1991 } else {
1992 // If a module is directly included and also transitively depended on
1993 // consider it as directly included.
1994 e.transitiveDep = e.transitiveDep && f.transitiveDep
1995 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001996 }
1997 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001998 var result []apexFile
1999 for _, v := range encountered {
2000 result = append(result, v)
2001 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002002 return result
2003 }
2004 filesInfo = removeDup(filesInfo)
2005
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002006 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002007 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002008 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2009 // changes.
2010 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002011 })
2012
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002013 ////////////////////////////////////////////////////////////////////////////////////////////
2014 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002015 a.installDir = android.PathForModuleInstall(ctx, "apex")
2016 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002017
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002018 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002019 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002020 switch a.properties.ApexType {
2021 case imageApex:
2022 if buildFlattenedAsDefault {
2023 a.suffix = imageApexSuffix
2024 } else {
2025 a.suffix = ""
2026 a.primaryApexType = true
2027
2028 if ctx.Config().InstallExtraFlattenedApexes() {
2029 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2030 }
2031 }
2032 case zipApex:
2033 if proptools.String(a.properties.Payload_type) == "zip" {
2034 a.suffix = ""
2035 a.primaryApexType = true
2036 } else {
2037 a.suffix = zipApexSuffix
2038 }
2039 case flattenedApex:
2040 if buildFlattenedAsDefault {
2041 a.suffix = ""
2042 a.primaryApexType = true
2043 } else {
2044 a.suffix = flattenedSuffix
2045 }
2046 }
2047
Theotime Combes4ba38c12020-06-12 12:46:59 +00002048 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2049 case ext4FsType:
2050 a.payloadFsType = ext4
2051 case f2fsFsType:
2052 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002053 case erofsFsType:
2054 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002055 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002056 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 +00002057 }
2058
Jiyong Park7cd10e32020-01-14 09:22:18 +09002059 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2060 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2061 // the same library in the system partition, thus effectively sharing the same libraries
2062 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2063 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002064 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002065
Jooyung Han85d61762020-06-24 23:50:26 +09002066 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2067 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002068 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002069 a.linkToSystemLib = false
2070 }
2071
Jiyong Park4da07972021-01-05 21:01:11 +09002072 forced := ctx.Config().ForceApexSymlinkOptimization()
2073
Jiyong Park9d677202020-02-19 16:29:35 +09002074 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002075 // to the system health when the APEXes are still bundled (b/149805758).
2076 if !forced && a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002077 a.linkToSystemLib = false
2078 }
2079
Jiyong Park638d30e2020-02-26 18:27:19 +09002080 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2081 if ctx.Host() {
2082 a.linkToSystemLib = false
2083 }
2084
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002085 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
2086
2087 ////////////////////////////////////////////////////////////////////////////////////////////
2088 // 4) generate the build rules to create the APEX. This is done in builder.go.
2089 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002090 if a.properties.ApexType == flattenedApex {
2091 a.buildFlattenedApex(ctx)
2092 } else {
2093 a.buildUnflattenedApex(ctx)
2094 }
Jiyong Park956305c2020-01-09 12:32:06 +09002095 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002096 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002097
2098 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2099 if a.installable() {
2100 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2101 // along with other ordinary files. (Note that this is done by apexer for
2102 // non-flattened APEXes)
2103 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2104
2105 // Place the public key as apex_pubkey. This is also done by apexer for
2106 // non-flattened APEXes case.
2107 // TODO(jiyong): Why do we need this CP rule?
2108 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2109 ctx.Build(pctx, android.BuildParams{
2110 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002111 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002112 Output: copiedPubkey,
2113 })
2114 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2115 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002116}
2117
Paul Duffincc33ec82021-04-25 23:14:55 +01002118// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2119// the bootclasspath_fragment contributes to the apex.
2120func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2121 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2122 var filesToAdd []apexFile
2123
2124 // Add the boot image files, e.g. .art, .oat and .vdex files.
2125 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2126 dirInApex := filepath.Join("javalib", arch.String())
2127 for _, f := range files {
2128 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2129 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2130 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2131 filesToAdd = append(filesToAdd, af)
2132 }
2133 }
2134
satayev3db35472021-05-06 23:59:58 +01002135 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002136 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2137 filesToAdd = append(filesToAdd, *af)
2138 }
satayev3db35472021-05-06 23:59:58 +01002139
Paul Duffincc33ec82021-04-25 23:14:55 +01002140 return filesToAdd
2141}
2142
satayevb98371c2021-06-15 16:49:50 +01002143// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2144// the module contributes to the apex; or nil if the proto config was not generated.
2145func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2146 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2147 if !info.ClasspathFragmentProtoGenerated {
2148 return nil
2149 }
2150 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2151 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2152 return &af
satayev14e49132021-05-17 21:03:07 +01002153}
2154
Paul Duffincc33ec82021-04-25 23:14:55 +01002155// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2156// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002157func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2158 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2159
2160 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2161 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002162 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2163 if err != nil {
2164 ctx.ModuleErrorf("%s", err)
2165 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002166
2167 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2168 // bootclasspath_fragment.
2169 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2170 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002171}
2172
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002173///////////////////////////////////////////////////////////////////////////////////////////////////
2174// Factory functions
2175//
2176
2177func newApexBundle() *apexBundle {
2178 module := &apexBundle{}
2179
2180 module.AddProperties(&module.properties)
2181 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002182 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002183 module.AddProperties(&module.overridableProperties)
2184
2185 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2186 android.InitDefaultableModule(module)
2187 android.InitSdkAwareModule(module)
2188 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002189 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002190 return module
2191}
2192
Paul Duffineb8051d2021-10-18 17:49:39 +01002193func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002194 bundle := newApexBundle()
2195 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002196 return bundle
2197}
2198
2199// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2200// certain compatibility checks such as apex_available are not done for apex_test.
2201func testApexBundleFactory() android.Module {
2202 bundle := newApexBundle()
2203 bundle.testApex = true
2204 return bundle
2205}
2206
2207// apex packages other modules into an APEX file which is a packaging format for system-level
2208// components like binaries, shared libraries, etc.
2209func BundleFactory() android.Module {
2210 return newApexBundle()
2211}
2212
2213type Defaults struct {
2214 android.ModuleBase
2215 android.DefaultsModuleBase
2216}
2217
2218// apex_defaults provides defaultable properties to other apex modules.
2219func defaultsFactory() android.Module {
2220 return DefaultsFactory()
2221}
2222
2223func DefaultsFactory(props ...interface{}) android.Module {
2224 module := &Defaults{}
2225
2226 module.AddProperties(props...)
2227 module.AddProperties(
2228 &apexBundleProperties{},
2229 &apexTargetBundleProperties{},
2230 &overridableProperties{},
2231 )
2232
2233 android.InitDefaultsModule(module)
2234 return module
2235}
2236
2237type OverrideApex struct {
2238 android.ModuleBase
2239 android.OverrideModuleBase
2240}
2241
2242func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2243 // All the overrides happen in the base module.
2244}
2245
2246// override_apex is used to create an apex module based on another apex module by overriding some of
2247// its properties.
2248func overrideApexFactory() android.Module {
2249 m := &OverrideApex{}
2250
2251 m.AddProperties(&overridableProperties{})
2252
2253 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2254 android.InitOverrideModule(m)
2255 return m
2256}
2257
2258///////////////////////////////////////////////////////////////////////////////////////////////////
2259// Vality check routines
2260//
2261// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2262// certain conditions are not met.
2263//
2264// TODO(jiyong): move these checks to a separate go file.
2265
2266// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2267// of this apexBundle.
2268func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
2269 if a.testApex || a.vndkApex {
2270 return
2271 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002272 // apexBundle::minSdkVersion reports its own errors.
2273 minSdkVersion := a.minSdkVersion(ctx)
2274 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
2275}
2276
2277func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
2278 ver := proptools.String(a.properties.Min_sdk_version)
2279 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002280 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002281 }
2282 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2283 if err != nil {
2284 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2285 return android.NoneApiLevel
2286 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002287 return apiLevel
2288}
2289
2290// Ensures that a lib providing stub isn't statically linked
2291func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2292 // Practically, we only care about regular APEXes on the device.
2293 if ctx.Host() || a.testApex || a.vndkApex {
2294 return
2295 }
2296
2297 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2298
2299 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2300 if ccm, ok := to.(*cc.Module); ok {
2301 apexName := ctx.ModuleName()
2302 fromName := ctx.OtherModuleName(from)
2303 toName := ctx.OtherModuleName(to)
2304
2305 // If `to` is not actually in the same APEX as `from` then it does not need
2306 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002307 //
2308 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002309 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2310 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2311 return false
2312 }
2313
2314 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2315 // exception to this rule. It can't make the static dependencies dynamic
2316 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002317 // Same rule should be applied to linkerconfig, because it should be executed
2318 // only with static linked libraries before linker is available with ld.config.txt
2319 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002320 return false
2321 }
2322
2323 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2324 if isStubLibraryFromOtherApex && !externalDep {
2325 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2326 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2327 }
2328
2329 }
2330 return true
2331 })
2332}
2333
satayevb98371c2021-06-15 16:49:50 +01002334// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002335func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2336 if a.Updatable() {
2337 if String(a.properties.Min_sdk_version) == "" {
2338 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2339 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002340 if a.UsePlatformApis() {
2341 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2342 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002343 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002344 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002345 }
2346}
2347
satayevb98371c2021-06-15 16:49:50 +01002348// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2349func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2350 ctx.VisitDirectDeps(func(module android.Module) {
2351 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2352 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2353 if !info.ClasspathFragmentProtoGenerated {
2354 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2355 }
2356 }
2357 })
2358}
2359
2360// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002361func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002362 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2363 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002364 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2365 tag := ctx.OtherModuleDependencyTag(module)
2366 switch tag {
2367 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002368 if m, ok := module.(interface {
2369 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2370 }); ok {
2371 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002372 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2373 }
2374 }
2375 }
2376 })
2377}
2378
satayevb98371c2021-06-15 16:49:50 +01002379// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002380func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2381 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2382 if ctx.Host() || a.testApex || a.vndkApex {
2383 return
2384 }
2385
2386 // Because APEXes targeting other than system/system_ext partitions can't set
2387 // apex_available, we skip checks for these APEXes
2388 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2389 return
2390 }
2391
2392 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2393 // Requiring them and their transitive depencies with apex_available is not right
2394 // because they just add noise.
2395 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2396 return
2397 }
2398
2399 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2400 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2401 if externalDep {
2402 return false
2403 }
2404
2405 apexName := ctx.ModuleName()
2406 fromName := ctx.OtherModuleName(from)
2407 toName := ctx.OtherModuleName(to)
2408
2409 // If `to` is not actually in the same APEX as `from` then it does not need
2410 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002411 //
2412 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002413 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2414 // As soon as the dependency graph crosses the APEX boundary, don't go
2415 // further.
2416 return false
2417 }
2418
2419 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2420 return true
2421 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002422 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2423 "\n\nDependency path:%s\n\n"+
2424 "Consider adding %q to 'apex_available' property of %q",
2425 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002426 // Visit this module's dependencies to check and report any issues with their availability.
2427 return true
2428 })
2429}
2430
Jiyong Park192600a2021-08-03 07:52:17 +00002431// checkStaticExecutable ensures that executables in an APEX are not static.
2432func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002433 // No need to run this for host APEXes
2434 if ctx.Host() {
2435 return
2436 }
2437
Jiyong Park192600a2021-08-03 07:52:17 +00002438 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2439 if ctx.OtherModuleDependencyTag(module) != executableTag {
2440 return
2441 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002442
2443 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002444 apex := a.ApexVariationName()
2445 exec := ctx.OtherModuleName(module)
2446 if isStaticExecutableAllowed(apex, exec) {
2447 return
2448 }
2449 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2450 }
2451 })
2452}
2453
2454// A small list of exceptions where static executables are allowed in APEXes.
2455func isStaticExecutableAllowed(apex string, exec string) bool {
2456 m := map[string][]string{
2457 "com.android.runtime": []string{
2458 "linker",
2459 "linkerconfig",
2460 },
2461 }
2462 execNames, ok := m[apex]
2463 return ok && android.InList(exec, execNames)
2464}
2465
braleeb0c1f0c2021-06-07 22:49:13 +08002466// Collect information for opening IDE project files in java/jdeps.go.
2467func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2468 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2469 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2470 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2471 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2472}
2473
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002474var (
2475 apexAvailBaseline = makeApexAvailableBaseline()
2476 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2477)
2478
Colin Cross440e0d02020-06-11 11:32:11 -07002479func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002480 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002481 moduleName = normalizeModuleName(moduleName)
2482
Colin Cross440e0d02020-06-11 11:32:11 -07002483 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002484 return true
2485 }
2486
2487 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002488 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002489 return true
2490 }
2491
2492 return false
2493}
2494
2495func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002496 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2497 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002498 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002499 if strings.HasPrefix(moduleName, "libclang_rt.") {
2500 // This module has many arch variants that depend on the product being built.
2501 // We don't want to list them all
2502 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002503 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002504 if strings.HasPrefix(moduleName, "androidx.") {
2505 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2506 moduleName = "androidx"
2507 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002508 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002509}
2510
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002511// Transform the map of apex -> modules to module -> apexes.
2512func invertApexBaseline(m map[string][]string) map[string][]string {
2513 r := make(map[string][]string)
2514 for apex, modules := range m {
2515 for _, module := range modules {
2516 r[module] = append(r[module], apex)
2517 }
2518 }
2519 return r
2520}
2521
2522// Retrieve the baseline of apexes to which the supplied module belongs.
2523func BaselineApexAvailable(moduleName string) []string {
2524 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2525}
2526
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002527// This is a map from apex to modules, which overrides the apex_available setting for that
2528// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002529// TODO(b/147364041): remove this
2530func makeApexAvailableBaseline() map[string][]string {
2531 // The "Module separator"s below are employed to minimize merge conflicts.
2532 m := make(map[string][]string)
2533 //
2534 // Module separator
2535 //
2536 m["com.android.appsearch"] = []string{
2537 "icing-java-proto-lite",
2538 "libprotobuf-java-lite",
2539 }
2540 //
2541 // Module separator
2542 //
2543 m["com.android.bluetooth.updatable"] = []string{
2544 "android.hardware.audio.common@5.0",
2545 "android.hardware.bluetooth.a2dp@1.0",
2546 "android.hardware.bluetooth.audio@2.0",
2547 "android.hardware.bluetooth@1.0",
2548 "android.hardware.bluetooth@1.1",
2549 "android.hardware.graphics.bufferqueue@1.0",
2550 "android.hardware.graphics.bufferqueue@2.0",
2551 "android.hardware.graphics.common@1.0",
2552 "android.hardware.graphics.common@1.1",
2553 "android.hardware.graphics.common@1.2",
2554 "android.hardware.media@1.0",
2555 "android.hidl.safe_union@1.0",
2556 "android.hidl.token@1.0",
2557 "android.hidl.token@1.0-utils",
2558 "avrcp-target-service",
2559 "avrcp_headers",
2560 "bluetooth-protos-lite",
2561 "bluetooth.mapsapi",
2562 "com.android.vcard",
2563 "dnsresolver_aidl_interface-V2-java",
2564 "ipmemorystore-aidl-interfaces-V5-java",
2565 "ipmemorystore-aidl-interfaces-java",
2566 "internal_include_headers",
2567 "lib-bt-packets",
2568 "lib-bt-packets-avrcp",
2569 "lib-bt-packets-base",
2570 "libFraunhoferAAC",
2571 "libaudio-a2dp-hw-utils",
2572 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002573 "libbluetooth",
2574 "libbluetooth-types",
2575 "libbluetooth-types-header",
2576 "libbluetooth_gd",
2577 "libbluetooth_headers",
2578 "libbluetooth_jni",
2579 "libbt-audio-hal-interface",
2580 "libbt-bta",
2581 "libbt-common",
2582 "libbt-hci",
2583 "libbt-platform-protos-lite",
2584 "libbt-protos-lite",
2585 "libbt-sbc-decoder",
2586 "libbt-sbc-encoder",
2587 "libbt-stack",
2588 "libbt-utils",
2589 "libbtcore",
2590 "libbtdevice",
2591 "libbte",
2592 "libbtif",
2593 "libchrome",
2594 "libevent",
2595 "libfmq",
2596 "libg722codec",
2597 "libgui_headers",
2598 "libmedia_headers",
2599 "libmodpb64",
2600 "libosi",
2601 "libstagefright_foundation_headers",
2602 "libstagefright_headers",
2603 "libstatslog",
2604 "libstatssocket",
2605 "libtinyxml2",
2606 "libudrv-uipc",
2607 "libz",
2608 "media_plugin_headers",
2609 "net-utils-services-common",
2610 "netd_aidl_interface-unstable-java",
2611 "netd_event_listener_interface-java",
2612 "netlink-client",
2613 "networkstack-client",
2614 "sap-api-java-static",
2615 "services.net",
2616 }
2617 //
2618 // Module separator
2619 //
2620 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2621 //
2622 // Module separator
2623 //
2624 m["com.android.extservices"] = []string{
2625 "error_prone_annotations",
2626 "ExtServices-core",
2627 "ExtServices",
2628 "libtextclassifier-java",
2629 "libz_current",
2630 "textclassifier-statsd",
2631 "TextClassifierNotificationLibNoManifest",
2632 "TextClassifierServiceLibNoManifest",
2633 }
2634 //
2635 // Module separator
2636 //
2637 m["com.android.neuralnetworks"] = []string{
2638 "android.hardware.neuralnetworks@1.0",
2639 "android.hardware.neuralnetworks@1.1",
2640 "android.hardware.neuralnetworks@1.2",
2641 "android.hardware.neuralnetworks@1.3",
2642 "android.hidl.allocator@1.0",
2643 "android.hidl.memory.token@1.0",
2644 "android.hidl.memory@1.0",
2645 "android.hidl.safe_union@1.0",
2646 "libarect",
2647 "libbuildversion",
2648 "libmath",
2649 "libprocpartition",
2650 "libsync",
2651 }
2652 //
2653 // Module separator
2654 //
2655 m["com.android.media"] = []string{
2656 "android.frameworks.bufferhub@1.0",
2657 "android.hardware.cas.native@1.0",
2658 "android.hardware.cas@1.0",
2659 "android.hardware.configstore-utils",
2660 "android.hardware.configstore@1.0",
2661 "android.hardware.configstore@1.1",
2662 "android.hardware.graphics.allocator@2.0",
2663 "android.hardware.graphics.allocator@3.0",
2664 "android.hardware.graphics.bufferqueue@1.0",
2665 "android.hardware.graphics.bufferqueue@2.0",
2666 "android.hardware.graphics.common@1.0",
2667 "android.hardware.graphics.common@1.1",
2668 "android.hardware.graphics.common@1.2",
2669 "android.hardware.graphics.mapper@2.0",
2670 "android.hardware.graphics.mapper@2.1",
2671 "android.hardware.graphics.mapper@3.0",
2672 "android.hardware.media.omx@1.0",
2673 "android.hardware.media@1.0",
2674 "android.hidl.allocator@1.0",
2675 "android.hidl.memory.token@1.0",
2676 "android.hidl.memory@1.0",
2677 "android.hidl.token@1.0",
2678 "android.hidl.token@1.0-utils",
2679 "bionic_libc_platform_headers",
2680 "exoplayer2-extractor",
2681 "exoplayer2-extractor-annotation-stubs",
2682 "gl_headers",
2683 "jsr305",
2684 "libEGL",
2685 "libEGL_blobCache",
2686 "libEGL_getProcAddress",
2687 "libFLAC",
2688 "libFLAC-config",
2689 "libFLAC-headers",
2690 "libGLESv2",
2691 "libaacextractor",
2692 "libamrextractor",
2693 "libarect",
2694 "libaudio_system_headers",
2695 "libaudioclient",
2696 "libaudioclient_headers",
2697 "libaudiofoundation",
2698 "libaudiofoundation_headers",
2699 "libaudiomanager",
2700 "libaudiopolicy",
2701 "libaudioutils",
2702 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002703 "libbluetooth-types-header",
2704 "libbufferhub",
2705 "libbufferhub_headers",
2706 "libbufferhubqueue",
2707 "libc_malloc_debug_backtrace",
2708 "libcamera_client",
2709 "libcamera_metadata",
2710 "libdvr_headers",
2711 "libexpat",
2712 "libfifo",
2713 "libflacextractor",
2714 "libgrallocusage",
2715 "libgraphicsenv",
2716 "libgui",
2717 "libgui_headers",
2718 "libhardware_headers",
2719 "libinput",
2720 "liblzma",
2721 "libmath",
2722 "libmedia",
2723 "libmedia_codeclist",
2724 "libmedia_headers",
2725 "libmedia_helper",
2726 "libmedia_helper_headers",
2727 "libmedia_midiiowrapper",
2728 "libmedia_omx",
2729 "libmediautils",
2730 "libmidiextractor",
2731 "libmkvextractor",
2732 "libmp3extractor",
2733 "libmp4extractor",
2734 "libmpeg2extractor",
2735 "libnativebase_headers",
2736 "libnativewindow_headers",
2737 "libnblog",
2738 "liboggextractor",
2739 "libpackagelistparser",
2740 "libpdx",
2741 "libpdx_default_transport",
2742 "libpdx_headers",
2743 "libpdx_uds",
2744 "libprocinfo",
2745 "libspeexresampler",
2746 "libspeexresampler",
2747 "libstagefright_esds",
2748 "libstagefright_flacdec",
2749 "libstagefright_flacdec",
2750 "libstagefright_foundation",
2751 "libstagefright_foundation_headers",
2752 "libstagefright_foundation_without_imemory",
2753 "libstagefright_headers",
2754 "libstagefright_id3",
2755 "libstagefright_metadatautils",
2756 "libstagefright_mpeg2extractor",
2757 "libstagefright_mpeg2support",
2758 "libsync",
2759 "libui",
2760 "libui_headers",
2761 "libunwindstack",
2762 "libvibrator",
2763 "libvorbisidec",
2764 "libwavextractor",
2765 "libwebm",
2766 "media_ndk_headers",
2767 "media_plugin_headers",
2768 "updatable-media",
2769 }
2770 //
2771 // Module separator
2772 //
2773 m["com.android.media.swcodec"] = []string{
2774 "android.frameworks.bufferhub@1.0",
2775 "android.hardware.common-ndk_platform",
2776 "android.hardware.configstore-utils",
2777 "android.hardware.configstore@1.0",
2778 "android.hardware.configstore@1.1",
2779 "android.hardware.graphics.allocator@2.0",
2780 "android.hardware.graphics.allocator@3.0",
2781 "android.hardware.graphics.allocator@4.0",
2782 "android.hardware.graphics.bufferqueue@1.0",
2783 "android.hardware.graphics.bufferqueue@2.0",
2784 "android.hardware.graphics.common-ndk_platform",
2785 "android.hardware.graphics.common@1.0",
2786 "android.hardware.graphics.common@1.1",
2787 "android.hardware.graphics.common@1.2",
2788 "android.hardware.graphics.mapper@2.0",
2789 "android.hardware.graphics.mapper@2.1",
2790 "android.hardware.graphics.mapper@3.0",
2791 "android.hardware.graphics.mapper@4.0",
2792 "android.hardware.media.bufferpool@2.0",
2793 "android.hardware.media.c2@1.0",
2794 "android.hardware.media.c2@1.1",
2795 "android.hardware.media.omx@1.0",
2796 "android.hardware.media@1.0",
2797 "android.hardware.media@1.0",
2798 "android.hidl.memory.token@1.0",
2799 "android.hidl.memory@1.0",
2800 "android.hidl.safe_union@1.0",
2801 "android.hidl.token@1.0",
2802 "android.hidl.token@1.0-utils",
2803 "libEGL",
2804 "libFLAC",
2805 "libFLAC-config",
2806 "libFLAC-headers",
2807 "libFraunhoferAAC",
2808 "libLibGuiProperties",
2809 "libarect",
2810 "libaudio_system_headers",
2811 "libaudioutils",
2812 "libaudioutils",
2813 "libaudioutils_fixedfft",
2814 "libavcdec",
2815 "libavcenc",
2816 "libavservices_minijail",
2817 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002818 "libbinderthreadstateutils",
2819 "libbluetooth-types-header",
2820 "libbufferhub_headers",
2821 "libcodec2",
2822 "libcodec2_headers",
2823 "libcodec2_hidl@1.0",
2824 "libcodec2_hidl@1.1",
2825 "libcodec2_internal",
2826 "libcodec2_soft_aacdec",
2827 "libcodec2_soft_aacenc",
2828 "libcodec2_soft_amrnbdec",
2829 "libcodec2_soft_amrnbenc",
2830 "libcodec2_soft_amrwbdec",
2831 "libcodec2_soft_amrwbenc",
2832 "libcodec2_soft_av1dec_gav1",
2833 "libcodec2_soft_avcdec",
2834 "libcodec2_soft_avcenc",
2835 "libcodec2_soft_common",
2836 "libcodec2_soft_flacdec",
2837 "libcodec2_soft_flacenc",
2838 "libcodec2_soft_g711alawdec",
2839 "libcodec2_soft_g711mlawdec",
2840 "libcodec2_soft_gsmdec",
2841 "libcodec2_soft_h263dec",
2842 "libcodec2_soft_h263enc",
2843 "libcodec2_soft_hevcdec",
2844 "libcodec2_soft_hevcenc",
2845 "libcodec2_soft_mp3dec",
2846 "libcodec2_soft_mpeg2dec",
2847 "libcodec2_soft_mpeg4dec",
2848 "libcodec2_soft_mpeg4enc",
2849 "libcodec2_soft_opusdec",
2850 "libcodec2_soft_opusenc",
2851 "libcodec2_soft_rawdec",
2852 "libcodec2_soft_vorbisdec",
2853 "libcodec2_soft_vp8dec",
2854 "libcodec2_soft_vp8enc",
2855 "libcodec2_soft_vp9dec",
2856 "libcodec2_soft_vp9enc",
2857 "libcodec2_vndk",
2858 "libdvr_headers",
2859 "libfmq",
2860 "libfmq",
2861 "libgav1",
2862 "libgralloctypes",
2863 "libgrallocusage",
2864 "libgraphicsenv",
2865 "libgsm",
2866 "libgui_bufferqueue_static",
2867 "libgui_headers",
2868 "libhardware",
2869 "libhardware_headers",
2870 "libhevcdec",
2871 "libhevcenc",
2872 "libion",
2873 "libjpeg",
2874 "liblzma",
2875 "libmath",
2876 "libmedia_codecserviceregistrant",
2877 "libmedia_headers",
2878 "libmpeg2dec",
2879 "libnativebase_headers",
2880 "libnativewindow_headers",
2881 "libpdx_headers",
2882 "libscudo_wrapper",
2883 "libsfplugin_ccodec_utils",
2884 "libspeexresampler",
2885 "libstagefright_amrnb_common",
2886 "libstagefright_amrnbdec",
2887 "libstagefright_amrnbenc",
2888 "libstagefright_amrwbdec",
2889 "libstagefright_amrwbenc",
2890 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002891 "libstagefright_enc_common",
2892 "libstagefright_flacdec",
2893 "libstagefright_foundation",
2894 "libstagefright_foundation_headers",
2895 "libstagefright_headers",
2896 "libstagefright_m4vh263dec",
2897 "libstagefright_m4vh263enc",
2898 "libstagefright_mp3dec",
2899 "libsync",
2900 "libui",
2901 "libui_headers",
2902 "libunwindstack",
2903 "libvorbisidec",
2904 "libvpx",
2905 "libyuv",
2906 "libyuv_static",
2907 "media_ndk_headers",
2908 "media_plugin_headers",
2909 "mediaswcodec",
2910 }
2911 //
2912 // Module separator
2913 //
2914 m["com.android.mediaprovider"] = []string{
2915 "MediaProvider",
2916 "MediaProviderGoogle",
2917 "fmtlib_ndk",
2918 "libbase_ndk",
2919 "libfuse",
2920 "libfuse_jni",
2921 }
2922 //
2923 // Module separator
2924 //
2925 m["com.android.permission"] = []string{
2926 "car-ui-lib",
2927 "iconloader",
2928 "kotlin-annotations",
2929 "kotlin-stdlib",
2930 "kotlin-stdlib-jdk7",
2931 "kotlin-stdlib-jdk8",
2932 "kotlinx-coroutines-android",
2933 "kotlinx-coroutines-android-nodeps",
2934 "kotlinx-coroutines-core",
2935 "kotlinx-coroutines-core-nodeps",
2936 "permissioncontroller-statsd",
2937 "GooglePermissionController",
2938 "PermissionController",
2939 "SettingsLibActionBarShadow",
2940 "SettingsLibAppPreference",
2941 "SettingsLibBarChartPreference",
2942 "SettingsLibLayoutPreference",
2943 "SettingsLibProgressBar",
2944 "SettingsLibSearchWidget",
2945 "SettingsLibSettingsTheme",
2946 "SettingsLibRestrictedLockUtils",
2947 "SettingsLibHelpUtils",
2948 }
2949 //
2950 // Module separator
2951 //
2952 m["com.android.runtime"] = []string{
2953 "bionic_libc_platform_headers",
2954 "libarm-optimized-routines-math",
2955 "libc_aeabi",
2956 "libc_bionic",
2957 "libc_bionic_ndk",
2958 "libc_bootstrap",
2959 "libc_common",
2960 "libc_common_shared",
2961 "libc_common_static",
2962 "libc_dns",
2963 "libc_dynamic_dispatch",
2964 "libc_fortify",
2965 "libc_freebsd",
2966 "libc_freebsd_large_stack",
2967 "libc_gdtoa",
2968 "libc_init_dynamic",
2969 "libc_init_static",
2970 "libc_jemalloc_wrapper",
2971 "libc_netbsd",
2972 "libc_nomalloc",
2973 "libc_nopthread",
2974 "libc_openbsd",
2975 "libc_openbsd_large_stack",
2976 "libc_openbsd_ndk",
2977 "libc_pthread",
2978 "libc_static_dispatch",
2979 "libc_syscalls",
2980 "libc_tzcode",
2981 "libc_unwind_static",
2982 "libdebuggerd",
2983 "libdebuggerd_common_headers",
2984 "libdebuggerd_handler_core",
2985 "libdebuggerd_handler_fallback",
2986 "libdl_static",
2987 "libjemalloc5",
2988 "liblinker_main",
2989 "liblinker_malloc",
2990 "liblz4",
2991 "liblzma",
2992 "libprocinfo",
2993 "libpropertyinfoparser",
2994 "libscudo",
2995 "libstdc++",
2996 "libsystemproperties",
2997 "libtombstoned_client_static",
2998 "libunwindstack",
2999 "libz",
3000 "libziparchive",
3001 }
3002 //
3003 // Module separator
3004 //
3005 m["com.android.tethering"] = []string{
3006 "android.hardware.tetheroffload.config-V1.0-java",
3007 "android.hardware.tetheroffload.control-V1.0-java",
3008 "android.hidl.base-V1.0-java",
3009 "libcgrouprc",
3010 "libcgrouprc_format",
3011 "libtetherutilsjni",
3012 "libvndksupport",
3013 "net-utils-framework-common",
3014 "netd_aidl_interface-V3-java",
3015 "netlink-client",
3016 "networkstack-aidl-interfaces-java",
3017 "tethering-aidl-interfaces-java",
3018 "TetheringApiCurrentLib",
3019 }
3020 //
3021 // Module separator
3022 //
3023 m["com.android.wifi"] = []string{
3024 "PlatformProperties",
3025 "android.hardware.wifi-V1.0-java",
3026 "android.hardware.wifi-V1.0-java-constants",
3027 "android.hardware.wifi-V1.1-java",
3028 "android.hardware.wifi-V1.2-java",
3029 "android.hardware.wifi-V1.3-java",
3030 "android.hardware.wifi-V1.4-java",
3031 "android.hardware.wifi.hostapd-V1.0-java",
3032 "android.hardware.wifi.hostapd-V1.1-java",
3033 "android.hardware.wifi.hostapd-V1.2-java",
3034 "android.hardware.wifi.supplicant-V1.0-java",
3035 "android.hardware.wifi.supplicant-V1.1-java",
3036 "android.hardware.wifi.supplicant-V1.2-java",
3037 "android.hardware.wifi.supplicant-V1.3-java",
3038 "android.hidl.base-V1.0-java",
3039 "android.hidl.manager-V1.0-java",
3040 "android.hidl.manager-V1.1-java",
3041 "android.hidl.manager-V1.2-java",
3042 "bouncycastle-unbundled",
3043 "dnsresolver_aidl_interface-V2-java",
3044 "error_prone_annotations",
3045 "framework-wifi-pre-jarjar",
3046 "framework-wifi-util-lib",
3047 "ipmemorystore-aidl-interfaces-V3-java",
3048 "ipmemorystore-aidl-interfaces-java",
3049 "ksoap2",
3050 "libnanohttpd",
3051 "libwifi-jni",
3052 "net-utils-services-common",
3053 "netd_aidl_interface-V2-java",
3054 "netd_aidl_interface-unstable-java",
3055 "netd_event_listener_interface-java",
3056 "netlink-client",
3057 "networkstack-client",
3058 "services.net",
3059 "wifi-lite-protos",
3060 "wifi-nano-protos",
3061 "wifi-service-pre-jarjar",
3062 "wifi-service-resources",
3063 }
3064 //
3065 // Module separator
3066 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003067 m["com.android.os.statsd"] = []string{
3068 "libstatssocket",
3069 }
3070 //
3071 // Module separator
3072 //
3073 m[android.AvailableToAnyApex] = []string{
3074 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3075 "androidx",
3076 "androidx-constraintlayout_constraintlayout",
3077 "androidx-constraintlayout_constraintlayout-nodeps",
3078 "androidx-constraintlayout_constraintlayout-solver",
3079 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3080 "com.google.android.material_material",
3081 "com.google.android.material_material-nodeps",
3082
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003083 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003084 "libprofile-clang-extras",
3085 "libprofile-clang-extras_ndk",
3086 "libprofile-extras",
3087 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003088 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003089 }
3090 return m
3091}
3092
3093func init() {
3094 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3095 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3096}
3097
3098func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3099 rules := make([]android.Rule, 0, len(modules_packages))
3100 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003101 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003102 BootclasspathJar().
3103 With("apex_available", module_name).
3104 WithMatcher("permitted_packages", android.NotInList(module_packages)).
3105 Because("jars that are part of the " + module_name +
3106 " module may only allow these packages: " + strings.Join(module_packages, ",") +
3107 ". Please jarjar or move code around.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003108 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003109 }
3110 return rules
3111}
3112
3113// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
3114// Adding code to the bootclasspath in new packages will cause issues on module update.
3115func qModulesPackages() map[string][]string {
3116 return map[string][]string{
3117 "com.android.conscrypt": []string{
3118 "android.net.ssl",
3119 "com.android.org.conscrypt",
3120 },
3121 "com.android.media": []string{
3122 "android.media",
3123 },
3124 }
3125}
3126
3127// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
3128// Adding code to the bootclasspath in new packages will cause issues on module update.
3129func rModulesPackages() map[string][]string {
3130 return map[string][]string{
3131 "com.android.mediaprovider": []string{
3132 "android.provider",
3133 },
3134 "com.android.permission": []string{
3135 "android.permission",
3136 "android.app.role",
3137 "com.android.permission",
3138 "com.android.role",
3139 },
3140 "com.android.sdkext": []string{
3141 "android.os.ext",
3142 },
3143 "com.android.os.statsd": []string{
3144 "android.app",
3145 "android.os",
3146 "android.util",
3147 "com.android.internal.statsd",
3148 "com.android.server.stats",
3149 },
3150 "com.android.wifi": []string{
3151 "com.android.server.wifi",
3152 "com.android.wifi.x",
3153 "android.hardware.wifi",
3154 "android.net.wifi",
3155 },
3156 "com.android.tethering": []string{
3157 "android.net",
3158 },
3159 }
3160}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003161
3162// For Bazel / bp2build
3163
3164type bazelApexBundleAttributes struct {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003165 Manifest bazel.LabelAttribute
3166 Android_manifest bazel.LabelAttribute
3167 File_contexts bazel.LabelAttribute
3168 Key bazel.LabelAttribute
3169 Certificate bazel.LabelAttribute
3170 Min_sdk_version string
3171 Updatable bazel.BoolAttribute
3172 Installable bazel.BoolAttribute
3173 Native_shared_libs bazel.LabelListAttribute
3174 Binaries bazel.StringListAttribute
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003175 Prebuilts bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003176}
3177
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003178func ApexBundleBp2Build(ctx android.TopDownMutatorContext) {
3179 module, ok := ctx.Module().(*apexBundle)
3180 if !ok {
3181 // Not an APEX bundle
3182 return
3183 }
3184 if !module.ConvertWithBp2build(ctx) {
3185 return
3186 }
3187 if ctx.ModuleType() != "apex" {
3188 return
3189 }
3190
3191 apexBundleBp2BuildInternal(ctx, module)
3192}
3193
3194func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) {
3195 var manifestLabelAttribute bazel.LabelAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003196 if module.properties.Manifest != nil {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003197 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Manifest))
3198 }
3199
3200 var androidManifestLabelAttribute bazel.LabelAttribute
3201 if module.properties.AndroidManifest != nil {
3202 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.AndroidManifest))
3203 }
3204
3205 var fileContextsLabelAttribute bazel.LabelAttribute
3206 if module.properties.File_contexts != nil {
3207 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.File_contexts))
3208 }
3209
3210 var minSdkVersion string
3211 if module.properties.Min_sdk_version != nil {
3212 minSdkVersion = *module.properties.Min_sdk_version
3213 }
3214
3215 var keyLabelAttribute bazel.LabelAttribute
3216 if module.overridableProperties.Key != nil {
3217 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Key))
3218 }
3219
3220 var certificateLabelAttribute bazel.LabelAttribute
3221 if module.overridableProperties.Certificate != nil {
3222 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Certificate))
3223 }
3224
3225 nativeSharedLibs := module.properties.ApexNativeDependencies.Native_shared_libs
3226 nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
3227 nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
3228
Daniel Norman5a3ce132021-08-26 15:44:43 -07003229 prebuilts := module.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003230 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3231 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3232
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003233 binaries := module.properties.ApexNativeDependencies.Binaries
3234 binariesStringListAttribute := bazel.MakeStringListAttribute(binaries)
3235
3236 var updatableAttribute bazel.BoolAttribute
3237 if module.properties.Updatable != nil {
3238 updatableAttribute.Value = module.properties.Updatable
3239 }
3240
3241 var installableAttribute bazel.BoolAttribute
3242 if module.properties.Installable != nil {
3243 installableAttribute.Value = module.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003244 }
3245
3246 attrs := &bazelApexBundleAttributes{
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003247 Manifest: manifestLabelAttribute,
3248 Android_manifest: androidManifestLabelAttribute,
3249 File_contexts: fileContextsLabelAttribute,
3250 Min_sdk_version: minSdkVersion,
3251 Key: keyLabelAttribute,
3252 Certificate: certificateLabelAttribute,
3253 Updatable: updatableAttribute,
3254 Installable: installableAttribute,
3255 Native_shared_libs: nativeSharedLibsLabelListAttribute,
3256 Binaries: binariesStringListAttribute,
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003257 Prebuilts: prebuiltsLabelListAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003258 }
3259
3260 props := bazel.BazelTargetModuleProperties{
3261 Rule_class: "apex",
3262 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3263 }
3264
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +00003265 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003266}