blob: fc945422cc867074501783c8061abfc5942ffdf5 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090034 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/java"
36 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090037 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090039)
40
Jiyong Park8e6d52f2020-11-19 14:37:47 +090041func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000042 registerApexBuildComponents(android.InitRegistrationContext)
43}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044
Paul Duffin667893c2021-03-09 22:34:13 +000045func registerApexBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("apex", BundleFactory)
47 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
48 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
49 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
50 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
51 ctx.RegisterModuleType("override_apex", overrideApexFactory)
52 ctx.RegisterModuleType("apex_set", apexSetFactory)
53
Paul Duffin5dda3e32021-05-05 14:13:27 +010054 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.PreDepsMutators(RegisterPreDepsMutators)
56 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090057}
58
Paul Duffin5dda3e32021-05-05 14:13:27 +010059func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
60 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
61}
62
Jiyong Park8e6d52f2020-11-19 14:37:47 +090063func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
64 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
65 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
66}
67
68func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000069 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090070 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
71 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
72 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010073 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
74 // it should create a platform variant.
75 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090076 ctx.BottomUp("apex", apexMutator).Parallel()
77 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
78 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Spandan Das66773252022-01-15 00:23:18 +000079 // Register after apex_info mutator so that it can use ApexVariationName
80 ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090081}
82
83type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090084 // Json manifest file describing meta info of this APEX bundle. Refer to
85 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090086 Manifest *string `android:"path"`
87
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090088 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
89 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090090 AndroidManifest *string `android:"path"`
91
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090092 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
93 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090094 Apex_name *string
95
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090096 // Determines the file contexts file for setting the security contexts to files in this APEX
97 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
98 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090099 File_contexts *string `android:"path"`
100
Jiyong Park038e8522021-12-13 23:56:35 +0900101 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
102 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
103 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
104 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
105 // capability. If this property is not set, or a file is missing in the file, default config
106 // is used.
107 Canned_fs_config *string `android:"path"`
108
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900109 ApexNativeDependencies
110
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900111 Multilib apexMultilibProperties
112
Paul Duffin4b64ba02021-03-29 11:02:53 +0100113 // List of bootclasspath fragments that are embedded inside this APEX bundle.
114 Bootclasspath_fragments []string
115
satayev333a1732021-05-17 21:35:26 +0100116 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
117 Systemserverclasspath_fragments []string
118
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900119 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900120 Java_libs []string
121
Sundong Ahn80c04892021-11-23 00:57:19 +0000122 // List of sh binaries that are embedded inside this APEX bundle.
123 Sh_binaries []string
124
Paul Duffin3abc1742021-03-15 19:32:23 +0000125 // List of platform_compat_config files that are embedded inside this APEX bundle.
126 Compat_configs []string
127
Jiyong Park12a719c2021-01-07 15:31:24 +0900128 // List of filesystem images that are embedded inside this APEX bundle.
129 Filesystems []string
130
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900131 // The minimum SDK version that this APEX must support at minimum. This is usually set to
132 // the SDK version that the APEX was first introduced.
133 Min_sdk_version *string
134
135 // Whether this APEX is considered updatable or not. When set to true, this will enforce
136 // additional rules for making sure that the APEX is truly updatable. To be updatable,
137 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000138 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900139 Updatable *bool
140
Jiyong Parkf4020582021-11-29 12:37:10 +0900141 // Marks that this APEX is designed to be updatable in the future, although it's not
142 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
143 // updatable APEXes. Currently, this disables the size optimization, so that the size of
144 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
145 // false.
146 Future_updatable *bool
147
Jiyong Park1bc84122021-06-22 20:23:05 +0900148 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
149 // false`. Default is false.
150 Platform_apis *bool
151
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900152 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
153 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900154 Installable *bool
155
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900156 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
157 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
158 Use_vndk_as_stable *bool
159
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000160 // Whether this is multi-installed APEX should skip installing symbol files.
161 // Multi-installed APEXes share the same apex_name and are installed at the same time.
162 // Default is false.
163 //
164 // Should be set to true for all multi-installed APEXes except the singular
165 // default version within the multi-installed group.
166 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
167 // or else conflicting build rules may be created.
168 Multi_install_skip_symbol_files *bool
169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900170 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
171 // `name#version` or `name` which is an alias for `name#current`. If left empty,
172 // `platform#current` is implied. This value affects all modules included in this APEX. In
173 // other words, they are also built with the SDKs specified here.
174 Uses_sdks []string
175
176 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
177 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
178 // container. When set to zip, contents are stored in a zip container directly. This type is
179 // mostly for host-side debugging. When set to both, the two types are both built. Default
180 // is 'image'.
181 Payload_type *string
182
Huang Jianan13cac632021-08-02 15:02:17 +0800183 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
184 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900185 Payload_fs_type *string
186
187 // For telling the APEX to ignore special handling for system libraries such as bionic.
188 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900189 Ignore_system_library_special_case *bool
190
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100191 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100192 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100193 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900194
195 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
196 // used in tests.
197 Test_only_unsigned_payload *bool
198
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000199 // Whenever apex should be compressed, regardless of product flag used. Should be only
200 // used in tests.
201 Test_only_force_compression *bool
202
Jooyung Han09c11ad2021-10-27 03:45:31 +0900203 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
204 // with the tool to sign payload contents.
205 Custom_sign_tool *string
206
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100207 // Canonical name of this APEX bundle. Used to determine the path to the
208 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
209 // apex mutator variations. For override_apex modules, this is the name of the
210 // overridden base module.
211 ApexVariationName string `blueprint:"mutated"`
212
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900213 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900214
215 // List of sanitizer names that this APEX is enabled for
216 SanitizerNames []string `blueprint:"mutated"`
217
218 PreventInstall bool `blueprint:"mutated"`
219
220 HideFromMake bool `blueprint:"mutated"`
221
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900222 // Internal package method for this APEX. When payload_type is image, this can be either
223 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
224 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900225 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900226}
227
228type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900229 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900230 Native_shared_libs []string
231
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900232 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900233 Jni_libs []string
234
Jiyong Park99644e92020-11-17 22:21:02 +0900235 // List of rust dyn libraries
236 Rust_dyn_libs []string
237
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900238 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900239 Binaries []string
240
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900241 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900242 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900243
244 // List of filesystem images that are embedded inside this APEX bundle.
245 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900246}
247
248type apexMultilibProperties struct {
249 // Native dependencies whose compile_multilib is "first"
250 First ApexNativeDependencies
251
252 // Native dependencies whose compile_multilib is "both"
253 Both ApexNativeDependencies
254
255 // Native dependencies whose compile_multilib is "prefer32"
256 Prefer32 ApexNativeDependencies
257
258 // Native dependencies whose compile_multilib is "32"
259 Lib32 ApexNativeDependencies
260
261 // Native dependencies whose compile_multilib is "64"
262 Lib64 ApexNativeDependencies
263}
264
265type apexTargetBundleProperties struct {
266 Target struct {
267 // Multilib properties only for android.
268 Android struct {
269 Multilib apexMultilibProperties
270 }
271
272 // Multilib properties only for host.
273 Host struct {
274 Multilib apexMultilibProperties
275 }
276
277 // Multilib properties only for host linux_bionic.
278 Linux_bionic struct {
279 Multilib apexMultilibProperties
280 }
281
282 // Multilib properties only for host linux_glibc.
283 Linux_glibc struct {
284 Multilib apexMultilibProperties
285 }
286 }
287}
288
Jiyong Park59140302020-12-14 18:44:04 +0900289type apexArchBundleProperties struct {
290 Arch struct {
291 Arm struct {
292 ApexNativeDependencies
293 }
294 Arm64 struct {
295 ApexNativeDependencies
296 }
297 X86 struct {
298 ApexNativeDependencies
299 }
300 X86_64 struct {
301 ApexNativeDependencies
302 }
303 }
304}
305
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900306// These properties can be used in override_apex to override the corresponding properties in the
307// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900308type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900309 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900310 Apps []string
311
Daniel Norman5a3ce132021-08-26 15:44:43 -0700312 // List of prebuilt files that are embedded inside this APEX bundle.
313 Prebuilts []string
314
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900315 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900316 Rros []string
317
markchien7c803b82021-08-26 22:10:06 +0800318 // List of BPF programs inside this APEX bundle.
319 Bpfs []string
320
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900321 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
322 // Soong). This does not completely prevent installation of the overridden binaries, but if
323 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
324 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900325 Overrides []string
326
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900327 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900328 Logging_parent string
329
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900330 // Apex Container package name. Override value for attribute package:name in
331 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900332 Package_name string
333
334 // A txt file containing list of files that are allowed to be included in this APEX.
335 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700336
337 // Name of the apex_key module that provides the private key to sign this APEX bundle.
338 Key *string
339
340 // Specifies the certificate and the private key to sign the zip container of this APEX. If
341 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
342 // as the certificate and the private key, respectively. If this is ":module", then the
343 // certificate and the private key are provided from the android_app_certificate module
344 // named "module".
345 Certificate *string
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -0400346
347 // Whether this APEX can be compressed or not. Setting this property to false means this
348 // APEX will never be compressed. When set to true, APEX will be compressed if other
349 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
350 // Default: false.
351 Compressible *bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352}
353
354type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900355 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356 android.ModuleBase
357 android.DefaultableModuleBase
358 android.OverridableModuleBase
359 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400360 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363 properties apexBundleProperties
364 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900365 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900366 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900367 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900368
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 ///////////////////////////////////////////////////////////////////////////////////////////
370 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900372 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800373 publicKeyFile android.Path
374 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900375
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800377 containerCertificateFile android.Path
378 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900379
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900380 // Flags for special variants of APEX
381 testApex bool
382 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900384 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
385 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900386 primaryApexType bool
387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900388 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900389 suffix string
390
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900391 // File system type of apex_payload.img
392 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900393
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900394 // Whether to create symlink to the system file instead of having a file inside the apex or
395 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900396 linkToSystemLib bool
397
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900398 // List of files to be included in this APEX. This is filled in the first part of
399 // GenerateAndroidBuildActions.
400 filesInfo []apexFile
401
402 // List of other module names that should be installed when this APEX gets installed.
403 requiredDeps []string
404
405 ///////////////////////////////////////////////////////////////////////////////////////////
406 // Outputs (final and intermediates)
407
408 // Processed apex manifest in JSONson format (for Q)
409 manifestJsonOut android.WritablePath
410
411 // Processed apex manifest in PB format (for R+)
412 manifestPbOut android.WritablePath
413
414 // Processed file_contexts files
415 fileContexts android.WritablePath
416
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900417 // Struct holding the merged notice file paths in different formats
418 mergedNotices android.NoticeOutputs
419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900420 // The built APEX file. This is the main product.
421 outputFile android.WritablePath
422
423 // The built APEX file in app bundle format. This file is not directly installed to the
424 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
425 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
426 // system) to be merged into a single app bundle file that Play accepts. See
427 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
428 bundleModuleFile android.WritablePath
429
Colin Cross6340ea52021-11-04 12:01:18 -0700430 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900431 installDir android.InstallPath
432
Colin Cross6340ea52021-11-04 12:01:18 -0700433 // Path where this APEX was installed.
434 installedFile android.InstallPath
435
436 // Installed locations of symlinks for backward compatibility.
437 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900438
439 // Text file having the list of individual files that are included in this APEX. Used for
440 // debugging purpose.
441 installedFilesFile android.WritablePath
442
443 // List of module names that this APEX is including (to be shown via *-deps-info target).
444 // Used for debugging purpose.
445 android.ApexBundleDepsInfo
446
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900447 // Optional list of lint report zip files for apexes that contain java or app modules
448 lintReports android.Paths
449
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900450 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000451
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000452 isCompressed bool
453
sophiezc80a2b32020-11-12 16:39:19 +0000454 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700455 nativeApisUsedByModuleFile android.ModuleOutPath
456 nativeApisBackedByModuleFile android.ModuleOutPath
457 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800458
459 // Collect the module directory for IDE info in java/jdeps.go.
460 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900461}
462
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900463// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900464type apexFileClass int
465
Jooyung Han72bd2f82019-10-23 16:46:38 +0900466const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900467 app apexFileClass = iota
468 appSet
469 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900470 goBinary
471 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900472 nativeExecutable
473 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900474 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900475 pyBinary
476 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900477)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900478
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900479// apexFile represents a file in an APEX bundle. This is created during the first half of
480// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
481// of the function, this is used to create commands that copies the files into a staging directory,
482// where they are packaged into the APEX file. This struct is also used for creating Make modules
483// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900484type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900485 // buildFile is put in the installDir inside the APEX.
486 builtFile android.Path
487 noticeFiles android.Paths
488 installDir string
489 customStem string
490 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900491
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900492 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
493 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
494 // suffix>]
495 androidMkModuleName string // becomes LOCAL_MODULE
496 class apexFileClass // becomes LOCAL_MODULE_CLASS
497 moduleDir string // becomes LOCAL_PATH
498 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
499 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
500 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
501 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900502
503 jacocoReportClassesFile android.Path // only for javalibs and apps
504 lintDepSets java.LintDepSets // only for javalibs and apps
505 certificate java.Certificate // only for apps
506 overriddenPackageName string // only for apps
507
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900508 transitiveDep bool
509 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900510
Jiyong Park57621b22021-01-20 20:33:11 +0900511 multilib string
512
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900513 // TODO(jiyong): remove this
514 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900515}
516
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900517// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900518func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
519 ret := apexFile{
520 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900522 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523 class: class,
524 module: module,
525 }
526 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900527 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900528 ret.moduleDir = ctx.OtherModuleDir(module)
529 ret.requiredModuleNames = module.RequiredModuleNames()
530 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
531 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900532 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900533 }
534 return ret
535}
536
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900537func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900538 return af.builtFile != nil && af.builtFile.String() != ""
539}
540
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900541// apexRelativePath returns the relative path of the given path from the install directory of this
542// apexFile.
543// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900544func (af *apexFile) apexRelativePath(path string) string {
545 return filepath.Join(af.installDir, path)
546}
547
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900548// path returns path of this apex file relative to the APEX root
549func (af *apexFile) path() string {
550 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900551}
552
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900553// stem returns the base filename of this apex file
554func (af *apexFile) stem() string {
555 if af.customStem != "" {
556 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900557 }
558 return af.builtFile.Base()
559}
560
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900561// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
562func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900563 var ret []string
564 for _, symlink := range af.symlinks {
565 ret = append(ret, af.apexRelativePath(symlink))
566 }
567 return ret
568}
569
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900570// availableToPlatform tests whether this apexFile is from a module that can be installed to the
571// platform.
572func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900573 if af.module == nil {
574 return false
575 }
576 if am, ok := af.module.(android.ApexModule); ok {
577 return am.AvailableFor(android.AvailableToPlatform)
578 }
579 return false
580}
581
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900582////////////////////////////////////////////////////////////////////////////////////////////////////
583// Mutators
584//
585// Brief description about mutators for APEX. The following three mutators are the most important
586// ones.
587//
588// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
589// to the (direct) dependencies of this APEX bundle.
590//
Paul Duffin949abc02020-12-08 10:34:30 +0000591// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900592// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
593// modules are marked as being included in the APEX via BuildForApex().
594//
Paul Duffin949abc02020-12-08 10:34:30 +0000595// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
596// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900597
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900598type dependencyTag struct {
599 blueprint.BaseDependencyTag
600 name string
601
602 // Determines if the dependent will be part of the APEX payload. Can be false for the
603 // dependencies to the signing key module, etc.
604 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000605
606 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
607 // replacement. This is needed because some prebuilt modules do not provide all the information
608 // needed by the apex.
609 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900610}
611
Paul Duffin8c535da2021-03-17 14:51:03 +0000612func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
613 return !d.sourceOnly
614}
615
616var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
617
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900618var (
Paul Duffin0b817782021-03-17 15:02:19 +0000619 androidAppTag = dependencyTag{name: "androidApp", payload: true}
620 bpfTag = dependencyTag{name: "bpf", payload: true}
621 certificateTag = dependencyTag{name: "certificate"}
622 executableTag = dependencyTag{name: "executable", payload: true}
623 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100624 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100625 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000626 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000627 javaLibTag = dependencyTag{name: "javaLib", payload: true}
628 jniLibTag = dependencyTag{name: "jniLib", payload: true}
629 keyTag = dependencyTag{name: "key"}
630 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
631 rroTag = dependencyTag{name: "rro", payload: true}
632 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
633 testForTag = dependencyTag{name: "test for"}
634 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000635 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900636)
637
638// TODO(jiyong): shorten this function signature
639func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900640 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900641 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900642 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900643
644 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900645 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900646 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
647 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900648 }
649
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900650 // Use *FarVariation* to be able to depend on modules having conflicting variations with
651 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
652 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900653 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900654 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900655 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
656 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900657 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900658 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900659}
660
661func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900662 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900663 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
664 } else {
665 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
666 if ctx.Os().Bionic() {
667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
668 } else {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
670 }
671 }
672}
673
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900674// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
675// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
676func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
677 deviceConfig := ctx.DeviceConfig()
678 if a.vndkApex {
679 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900680 }
681
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900682 var prefix string
683 var vndkVersion string
684 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000685 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900686 prefix = cc.VendorVariationPrefix
687 vndkVersion = deviceConfig.VndkVersion()
688 } else if a.ProductSpecific() {
689 prefix = cc.ProductVariationPrefix
690 vndkVersion = deviceConfig.ProductVndkVersion()
691 }
692 }
693 if vndkVersion == "current" {
694 vndkVersion = deviceConfig.PlatformVndkVersion()
695 }
696 if vndkVersion != "" {
697 return prefix + vndkVersion
698 }
699
700 return android.CoreVariation // The usual case
701}
702
703func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900704 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
705 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
706 // each target os/architectures, appropriate dependencies are selected by their
707 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900708 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900709 imageVariation := a.getImageVariation(ctx)
710
711 a.combineProperties(ctx)
712
713 has32BitTarget := false
714 for _, target := range targets {
715 if target.Arch.ArchType.Multilib == "lib32" {
716 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000717 }
718 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900719 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900720 // Don't include artifacts for the host cross targets because there is no way for us
721 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900722 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900723 continue
724 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000725
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900726 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000727
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900728 // Add native modules targeting both ABIs. When multilib.* is omitted for
729 // native_shared_libs/jni_libs/tests, it implies multilib.both
730 depsList = append(depsList, a.properties.Multilib.Both)
731 depsList = append(depsList, ApexNativeDependencies{
732 Native_shared_libs: a.properties.Native_shared_libs,
733 Tests: a.properties.Tests,
734 Jni_libs: a.properties.Jni_libs,
735 Binaries: nil,
736 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900737
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900738 // Add native modules targeting the first ABI When multilib.* is omitted for
739 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900740 isPrimaryAbi := i == 0
741 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900742 depsList = append(depsList, a.properties.Multilib.First)
743 depsList = append(depsList, ApexNativeDependencies{
744 Native_shared_libs: nil,
745 Tests: nil,
746 Jni_libs: nil,
747 Binaries: a.properties.Binaries,
748 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900749 }
750
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900751 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900752 switch target.Arch.ArchType.Multilib {
753 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900754 depsList = append(depsList, a.properties.Multilib.Lib32)
755 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900756 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900757 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900758 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900759 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 }
761 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900762
Jiyong Park59140302020-12-14 18:44:04 +0900763 // Add native modules targeting a specific arch variant
764 switch target.Arch.ArchType {
765 case android.Arm:
766 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
767 case android.Arm64:
768 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
769 case android.X86:
770 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
771 case android.X86_64:
772 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
773 default:
774 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
775 }
776
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900777 for _, d := range depsList {
778 addDependenciesForNativeModules(ctx, d, target, imageVariation)
779 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000780 ctx.AddFarVariationDependencies([]blueprint.Variation{
781 {Mutator: "os", Variation: target.OsVariation()},
782 {Mutator: "arch", Variation: target.ArchVariation()},
783 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900784 }
785
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900786 // Common-arch dependencies come next
787 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100788 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100789 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900790 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900791 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000792 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900793
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900794 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
795 // This field currently isn't used.
796 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900797 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
798 if len(a.properties.Uses_sdks) > 0 {
799 sdkRefs := []android.SdkRef{}
800 for _, str := range a.properties.Uses_sdks {
801 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
802 sdkRefs = append(sdkRefs, parsed)
803 }
804 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100805 }
806}
807
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900808// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900809func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
810 if a.overridableProperties.Allowed_files != nil {
811 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100812 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900813
814 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
815 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800816 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900817 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700818 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
819 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
820 // regardless of the TARGET_PREFER_* setting. See b/144532908
821 arches := ctx.DeviceConfig().Arches()
822 if len(arches) != 0 {
823 archForPrebuiltEtc := arches[0]
824 for _, arch := range arches {
825 // Prefer 64-bit arch if there is any
826 if arch.ArchType.Multilib == "lib64" {
827 archForPrebuiltEtc = arch
828 break
829 }
830 }
831 ctx.AddFarVariationDependencies([]blueprint.Variation{
832 {Mutator: "os", Variation: ctx.Os().String()},
833 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
834 }, prebuiltTag, prebuilts...)
835 }
836 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700837
838 // Dependencies for signing
839 if String(a.overridableProperties.Key) == "" {
840 ctx.PropertyErrorf("key", "missing")
841 return
842 }
843 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
844
845 cert := android.SrcIsModule(a.getCertString(ctx))
846 if cert != "" {
847 ctx.AddDependency(ctx.Module(), certificateTag, cert)
848 // empty cert is not an error. Cert and private keys will be directly found under
849 // PRODUCT_DEFAULT_DEV_CERTIFICATE
850 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100851}
852
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900853type ApexBundleInfo struct {
854 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100855}
856
Paul Duffin949abc02020-12-08 10:34:30 +0000857var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900858
Paul Duffina7d6a892020-12-07 17:39:59 +0000859var _ ApexInfoMutator = (*apexBundle)(nil)
860
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100861func (a *apexBundle) ApexVariationName() string {
862 return a.properties.ApexVariationName
863}
864
Paul Duffina7d6a892020-12-07 17:39:59 +0000865// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900866// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
867// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
868// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
869// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000870//
871// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
872// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
873// The apexMutator uses that list to create module variants for the apexes to which it belongs.
874// The relationship between module variants and apexes is not one-to-one as variants will be
875// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000876func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900877
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900878 // The VNDK APEX is special. For the APEX, the membership is described in a very different
879 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
880 // libraries are self-identified by their vndk.enabled properties. There is no need to run
881 // this mutator for the APEX as nothing will be collected. So, let's return fast.
882 if a.vndkApex {
883 return
884 }
885
886 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
887 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
888 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
889 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
890 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900891 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
892 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900893 if proptools.Bool(a.properties.Use_vndk_as_stable) {
894 if !useVndk {
895 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
896 }
897 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
898 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
899 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
900 }
901 })
902 if mctx.Failed() {
903 return
904 }
Jooyung Handf78e212020-07-22 15:54:47 +0900905 }
906
Colin Cross56a83212020-09-15 18:30:11 -0700907 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900908 am, ok := child.(android.ApexModule)
909 if !ok || !am.CanHaveApexVariants() {
910 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900911 }
Paul Duffin573989d2021-03-17 13:25:29 +0000912 depTag := mctx.OtherModuleDependencyTag(child)
913
914 // Check to see if the tag always requires that the child module has an apex variant for every
915 // apex variant of the parent module. If it does not then it is still possible for something
916 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
917 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
918 return true
919 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000920 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900921 return false
922 }
Jooyung Handf78e212020-07-22 15:54:47 +0900923 if excludeVndkLibs {
924 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
925 return false
926 }
927 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900928 // By default, all the transitive dependencies are collected, unless filtered out
929 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700930 return true
931 }
932
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900933 // Records whether a certain module is included in this apexBundle via direct dependency or
934 // inndirect dependency.
935 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700936 mctx.WalkDeps(func(child, parent android.Module) bool {
937 if !continueApexDepsWalk(child, parent) {
938 return false
939 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900940 // If the parent is apexBundle, this child is directly depended.
941 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900942 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700943 contents[depName] = contents[depName].Add(directDep)
944 return true
945 })
946
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900947 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900948 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700949 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
950 Contents: apexContents,
951 })
952
Jooyung Haned124c32021-01-26 11:43:46 +0900953 minSdkVersion := a.minSdkVersion(mctx)
954 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
955 if minSdkVersion.IsNone() {
956 minSdkVersion = android.FutureApiLevel
957 }
958
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900959 // This is the main part of this mutator. Mark the collected dependencies that they need to
960 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900961
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100962 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
963 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700964 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100965 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900966 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700967 RequiredSdks: a.RequiredSdks(),
968 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900969 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100970 InApexVariants: []string{apexVariationName},
971 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700972 ApexContents: []*android.ApexContents{apexContents},
973 }
Colin Cross56a83212020-09-15 18:30:11 -0700974 mctx.WalkDeps(func(child, parent android.Module) bool {
975 if !continueApexDepsWalk(child, parent) {
976 return false
977 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900978 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900979 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900980 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900981}
982
Paul Duffina7d6a892020-12-07 17:39:59 +0000983type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100984 // ApexVariationName returns the name of the APEX variation to use in the apex
985 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
986 ApexVariationName() string
987
Paul Duffina7d6a892020-12-07 17:39:59 +0000988 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
989 // depended upon by an apex and which require an apex specific variant.
990 ApexInfoMutator(android.TopDownMutatorContext)
991}
992
993// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
994// specific variant to modules that support the ApexInfoMutator.
995func apexInfoMutator(mctx android.TopDownMutatorContext) {
996 if !mctx.Module().Enabled() {
997 return
998 }
999
1000 if a, ok := mctx.Module().(ApexInfoMutator); ok {
1001 a.ApexInfoMutator(mctx)
1002 return
1003 }
1004}
1005
Spandan Das66773252022-01-15 00:23:18 +00001006// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
1007// This check is enforced for updatable modules
1008func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
1009 if !mctx.Module().Enabled() {
1010 return
1011 }
Spandan Das08c911f2022-01-21 22:07:26 +00001012 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +00001013 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001014 // b/208656169 Do not propagate strict updatability linting to libcore/
1015 // These libs are available on the classpath during compilation
1016 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1017 // Only skip libraries defined in libcore root, not subdirectories
1018 if mctx.OtherModuleDir(child) == "libcore" {
1019 // Do not traverse transitive deps of libcore/ libs
1020 return false
1021 }
Spandan Das66773252022-01-15 00:23:18 +00001022 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1023 lintable.SetStrictUpdatabilityLinting(true)
1024 }
1025 // visit transitive deps
1026 return true
1027 })
1028 }
1029}
1030
Spandan Das08c911f2022-01-21 22:07:26 +00001031// TODO: b/215736885 Whittle the denylist
1032// Transitive deps of certain mainline modules baseline NewApi errors
1033// Skip these mainline modules for now
1034var (
1035 skipStrictUpdatabilityLintAllowlist = []string{
1036 "com.android.art",
1037 "com.android.art.debug",
1038 "com.android.conscrypt",
1039 "com.android.media",
1040 // test apexes
1041 "test_com.android.art",
1042 "test_com.android.conscrypt",
1043 "test_com.android.media",
1044 "test_jitzygote_com.android.art",
1045 }
1046)
1047
1048func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1049 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1050}
1051
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001052// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1053// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1054// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001055func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1056 if !mctx.Module().Enabled() {
1057 return
1058 }
1059 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001060 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1061 }
1062}
1063
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001064// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1065// the apex in order to retrieve its contents later.
1066// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001067func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1068 if !mctx.Module().Enabled() {
1069 return
1070 }
Colin Cross56a83212020-09-15 18:30:11 -07001071 if am, ok := mctx.Module().(android.ApexModule); ok {
1072 if testFor := am.TestFor(); len(testFor) > 0 {
1073 mctx.AddFarVariationDependencies([]blueprint.Variation{
1074 {Mutator: "os", Variation: am.Target().OsVariation()},
1075 {"arch", "common"},
1076 }, testForTag, testFor...)
1077 }
1078 }
1079}
1080
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001081// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001082func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1083 if !mctx.Module().Enabled() {
1084 return
1085 }
Colin Cross56a83212020-09-15 18:30:11 -07001086 if _, ok := mctx.Module().(android.ApexModule); ok {
1087 var contents []*android.ApexContents
1088 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1089 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1090 contents = append(contents, abInfo.Contents)
1091 }
1092 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1093 ApexContents: contents,
1094 })
Colin Crossaede88c2020-08-11 12:17:01 -07001095 }
1096}
1097
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001098// markPlatformAvailability marks whether or not a module can be available to platform. A module
1099// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1100// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1101// be) available to platform
1102// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001103func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1104 // Host and recovery are not considered as platform
1105 if mctx.Host() || mctx.Module().InstallInRecovery() {
1106 return
1107 }
1108
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001109 am, ok := mctx.Module().(android.ApexModule)
1110 if !ok {
1111 return
1112 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001113
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001114 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001115
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001116 // If any of the dep is not available to platform, this module is also considered as being
1117 // not available to platform even if it has "//apex_available:platform"
1118 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001119 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001120 // if the dependency crosses apex boundary, don't consider it
1121 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001122 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001123 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1124 availableToPlatform = false
1125 // TODO(b/154889534) trigger an error when 'am' has
1126 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001127 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001128 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001129
Paul Duffinb5769c12021-05-12 16:16:51 +01001130 // Exception 1: check to see if the module always requires it.
1131 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001132 availableToPlatform = true
1133 }
1134
1135 // Exception 2: bootstrap bionic libraries are also always available to platform
1136 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1137 availableToPlatform = true
1138 }
1139
1140 if !availableToPlatform {
1141 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001142 }
1143}
1144
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001145// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001146// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001147func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001148 if !mctx.Module().Enabled() {
1149 return
1150 }
Colin Cross56a83212020-09-15 18:30:11 -07001151
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001152 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001153 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001154 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001155 return
1156 }
1157
1158 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001159 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1160 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001161 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001162 if strings.HasPrefix(apexBundleName, "com.android.art") {
1163 // Create an alias from the platform variant. This is done to make
1164 // test_for dependencies work for modules that are split by the APEX
1165 // mutator, since test_for dependencies always go to the platform variant.
1166 // This doesn't happen for normal APEXes that are disjunct, so only do
1167 // this for the overlapping ART APEXes.
1168 // TODO(b/183882457): Remove this if the test_for functionality is
1169 // refactored to depend on the proper APEX variants instead of platform.
1170 mctx.CreateAliasVariation("", apexBundleName)
1171 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001172 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1173 apexBundleName := o.GetOverriddenModuleName()
1174 if apexBundleName == "" {
1175 mctx.ModuleErrorf("base property is not set")
1176 return
1177 }
1178 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001179 if strings.HasPrefix(apexBundleName, "com.android.art") {
1180 // TODO(b/183882457): See note for CreateAliasVariation above.
1181 mctx.CreateAliasVariation("", apexBundleName)
1182 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001183 }
1184}
Sundong Ahne9b55722019-09-06 17:37:42 +09001185
Paul Duffin6717d882021-06-15 19:09:41 +01001186// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1187// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001188func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001189 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001190 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001191 return !a.vndkApex
1192 }
1193
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001194 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001195}
1196
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001197// See android.UpdateDirectlyInAnyApex
1198// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001199func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1200 if !mctx.Module().Enabled() {
1201 return
1202 }
1203 if am, ok := mctx.Module().(android.ApexModule); ok {
1204 android.UpdateDirectlyInAnyApex(mctx, am)
1205 }
1206}
1207
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001208// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001209type apexPackaging int
1210
1211const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001212 // imageApex is a packaging method where contents are included in a filesystem image which
1213 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001214 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001215
1216 // zipApex is a packaging method where contents are directly included in the zip container.
1217 // This is used for host-side testing - because the contents are easily accessible by
1218 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001219 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001220
1221 // flattendApex is a packaging method where contents are not included in the APEX file, but
1222 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1223 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001224 flattenedApex
1225)
1226
1227const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001228 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001229 imageApexSuffix = ".apex"
1230 imageCapexSuffix = ".capex"
1231 zipApexSuffix = ".zipapex"
1232 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001233
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001234 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001235 imageApexType = "image"
1236 zipApexType = "zip"
1237 flattenedApexType = "flattened"
1238
Dan Willemsen47e1a752021-10-16 18:36:13 -07001239 ext4FsType = "ext4"
1240 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001241 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001242)
1243
1244// The suffix for the output "file", not the module
1245func (a apexPackaging) suffix() string {
1246 switch a {
1247 case imageApex:
1248 return imageApexSuffix
1249 case zipApex:
1250 return zipApexSuffix
1251 default:
1252 panic(fmt.Errorf("unknown APEX type %d", a))
1253 }
1254}
1255
1256func (a apexPackaging) name() string {
1257 switch a {
1258 case imageApex:
1259 return imageApexType
1260 case zipApex:
1261 return zipApexType
1262 default:
1263 panic(fmt.Errorf("unknown APEX type %d", a))
1264 }
1265}
1266
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001267// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1268// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001269func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001270 if !mctx.Module().Enabled() {
1271 return
1272 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001273 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001274 var variants []string
1275 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1276 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001277 // This is the normal case. Note that both image and flattend APEXes are
1278 // created. The image type is installed to the system partition, while the
1279 // flattened APEX is (optionally) installed to the system_ext partition.
1280 // This is mostly for GSI which has to support wide range of devices. If GSI
1281 // is installed on a newer (APEX-capable) device, the image APEX in the
1282 // system will be used. However, if the same GSI is installed on an old
1283 // device which can't support image APEX, the flattened APEX in the
1284 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001285 variants = append(variants, imageApexType, flattenedApexType)
1286 case "zip":
1287 variants = append(variants, zipApexType)
1288 case "both":
1289 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1290 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001291 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001292 return
1293 }
1294
1295 modules := mctx.CreateLocalVariations(variants...)
1296
1297 for i, v := range variants {
1298 switch v {
1299 case imageApexType:
1300 modules[i].(*apexBundle).properties.ApexType = imageApex
1301 case zipApexType:
1302 modules[i].(*apexBundle).properties.ApexType = zipApex
1303 case flattenedApexType:
1304 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001305 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001306 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001307 modules[i].(*apexBundle).MakeAsSystemExt()
1308 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001309 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001310 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001311 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001312 // payload_type is forcibly overridden to "image"
1313 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001314 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001315 }
1316}
1317
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001318var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001319
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001320// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001321func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1322 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001323 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001324 return true
1325}
1326
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001327var _ android.OutputFileProducer = (*apexBundle)(nil)
1328
1329// Implements android.OutputFileProducer
1330func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1331 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001332 case "", android.DefaultDistTag:
1333 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001334 return android.Paths{a.outputFile}, nil
1335 default:
1336 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1337 }
1338}
1339
1340var _ cc.Coverage = (*apexBundle)(nil)
1341
1342// Implements cc.Coverage
1343func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1344 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1345}
1346
1347// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001348func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001349 a.properties.PreventInstall = true
1350}
1351
1352// Implements cc.Coverage
1353func (a *apexBundle) HideFromMake() {
1354 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001355 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1356 // TODO(ccross): untangle these
1357 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001358}
1359
1360// Implements cc.Coverage
1361func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1362 a.properties.IsCoverageVariant = coverage
1363}
1364
1365// Implements cc.Coverage
1366func (a *apexBundle) EnableCoverageIfNeeded() {}
1367
1368var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1369
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001370// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001371func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001372 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001373}
1374
Jiyong Parkf4020582021-11-29 12:37:10 +09001375func (a *apexBundle) FutureUpdatable() bool {
1376 return proptools.BoolDefault(a.properties.Future_updatable, false)
1377}
1378
Jiyong Park1bc84122021-06-22 20:23:05 +09001379func (a *apexBundle) UsePlatformApis() bool {
1380 return proptools.BoolDefault(a.properties.Platform_apis, false)
1381}
1382
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001383// getCertString returns the name of the cert that should be used to sign this APEX. This is
1384// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001385func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001386 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001387 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1388 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1389 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001390 if a.vndkApex {
1391 moduleName = vndkApexName
1392 }
1393 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001394 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001395 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001396 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001397 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001398}
1399
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001400// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001401func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001402 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001403}
1404
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001405// See the generate_hashtree property
1406func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001407 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001408}
1409
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001410// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001411func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1412 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1413}
1414
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001415// See the test_only_force_compression property
1416func (a *apexBundle) testOnlyShouldForceCompression() bool {
1417 return proptools.Bool(a.properties.Test_only_force_compression)
1418}
1419
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001420// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1421// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1422// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001423
Jiyong Parkf97782b2019-02-13 20:28:58 +09001424func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1425 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1426 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1427 }
1428}
1429
Jiyong Park388ef3f2019-01-28 19:47:32 +09001430func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001431 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1432 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001433 }
1434
1435 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001436 globalSanitizerNames := []string{}
1437 if a.Host() {
1438 globalSanitizerNames = ctx.Config().SanitizeHost()
1439 } else {
1440 arches := ctx.Config().SanitizeDeviceArch()
1441 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1442 globalSanitizerNames = ctx.Config().SanitizeDevice()
1443 }
1444 }
1445 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001446}
1447
Jooyung Han8ce8db92020-05-15 19:05:05 +09001448func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001449 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1450 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001451 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001452 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001453 for _, target := range ctx.MultiTargets() {
1454 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001455 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1456 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1457 Tests: nil,
1458 Jni_libs: nil,
1459 Binaries: nil,
1460 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001461 break
1462 }
1463 }
1464 }
1465}
1466
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001467// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1468// returned apexFile saves information about the Soong module that will be used for creating the
1469// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001470func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001471 // Decide the APEX-local directory by the multilib of the library In the future, we may
1472 // query this to the module.
1473 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001474 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001475 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001476 case "lib32":
1477 dirInApex = "lib"
1478 case "lib64":
1479 dirInApex = "lib64"
1480 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001481 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001482 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001483 }
Jooyung Han35155c42020-02-06 17:33:20 +09001484 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001485 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001486 // Special case for Bionic libs and other libs installed with them. This is to
1487 // prevent those libs from being included in the search path
1488 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1489 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1490 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1491 // will be loaded into the default linker namespace (aka "platform" namespace). If
1492 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1493 // be loaded again into the runtime linker namespace, which will result in double
1494 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001495 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001496 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001497
Jiyong Parkf653b052019-11-18 15:39:01 +09001498 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001499 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1500 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001501}
1502
Jiyong Park1833cef2019-12-13 13:28:36 +09001503func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001504 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001505 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001506 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001507 }
Jooyung Han35155c42020-02-06 17:33:20 +09001508 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001509 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001510 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1511 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001512 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001513 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001514 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001515}
1516
Jiyong Park99644e92020-11-17 22:21:02 +09001517func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1518 dirInApex := "bin"
1519 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1520 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1521 }
1522 fileToCopy := rustm.OutputFile().Path()
1523 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1524 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1525 return af
1526}
1527
1528func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1529 // Decide the APEX-local directory by the multilib of the library
1530 // In the future, we may query this to the module.
1531 var dirInApex string
1532 switch rustm.Arch().ArchType.Multilib {
1533 case "lib32":
1534 dirInApex = "lib"
1535 case "lib64":
1536 dirInApex = "lib64"
1537 }
1538 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1539 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1540 }
1541 fileToCopy := rustm.OutputFile().Path()
1542 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1543 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1544}
1545
Jiyong Park1833cef2019-12-13 13:28:36 +09001546func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001547 dirInApex := "bin"
1548 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001549 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001550}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001551
Jiyong Park1833cef2019-12-13 13:28:36 +09001552func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001553 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001554 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001555 // NB: Since go binaries are static we don't need the module for anything here, which is
1556 // good since the go tool is a blueprint.Module not an android.Module like we would
1557 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001558 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001559}
1560
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001561func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001562 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001563 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1564 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1565 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001566 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001567 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001568 af.symlinks = sh.Symlinks()
1569 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001570}
1571
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001572func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001573 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001574 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001575 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001576}
1577
atrost6e126252020-01-27 17:01:16 +00001578func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1579 dirInApex := filepath.Join("etc", config.SubDir())
1580 fileToCopy := config.CompatConfig()
1581 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1582}
1583
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001584// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1585// way.
1586type javaModule interface {
1587 android.Module
1588 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001589 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001590 JacocoReportClassesFile() android.Path
1591 LintDepSets() java.LintDepSets
1592 Stem() string
1593}
1594
1595var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001596var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001597var _ javaModule = (*java.SdkLibrary)(nil)
1598var _ javaModule = (*java.DexImport)(nil)
1599var _ javaModule = (*java.SdkLibraryImport)(nil)
1600
Paul Duffin190fdef2021-04-26 10:33:59 +01001601// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001602func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001603 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001604}
1605
1606// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1607func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001608 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001609 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001610 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1611 af.lintDepSets = module.LintDepSets()
1612 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001613 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1614 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1615 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1616 }
1617 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001618 return af
1619}
1620
1621// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1622// the same way.
1623type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001624 android.Module
1625 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001626 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001627 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001628 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001629 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001630 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001631 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001632}
1633
1634var _ androidApp = (*java.AndroidApp)(nil)
1635var _ androidApp = (*java.AndroidAppImport)(nil)
1636
1637func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001638 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001639 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001640 appDir = "priv-app"
1641 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001642 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001643 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001644 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001645 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001646 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001647 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001648
1649 if app, ok := aapp.(interface {
1650 OverriddenManifestPackageName() string
1651 }); ok {
1652 af.overriddenPackageName = app.OverriddenManifestPackageName()
1653 }
Jiyong Park618922e2020-01-08 13:35:43 +09001654 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001655}
1656
Jiyong Park69aeba92020-04-24 21:16:36 +09001657func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1658 rroDir := "overlay"
1659 dirInApex := filepath.Join(rroDir, rro.Theme())
1660 fileToCopy := rro.OutputFile()
1661 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1662 af.certificate = rro.Certificate()
1663
1664 if a, ok := rro.(interface {
1665 OverriddenManifestPackageName() string
1666 }); ok {
1667 af.overriddenPackageName = a.OverriddenManifestPackageName()
1668 }
1669 return af
1670}
1671
Ken Chenfad7f9d2021-11-10 22:02:57 +08001672func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1673 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001674 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1675}
1676
Jiyong Park12a719c2021-01-07 15:31:24 +09001677func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1678 dirInApex := filepath.Join("etc", "fs")
1679 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1680}
1681
Paul Duffin064b70c2020-11-02 17:32:38 +00001682// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001683// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1684// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1685// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001686func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001687 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001688 am, ok := child.(android.ApexModule)
1689 if !ok || !am.CanHaveApexVariants() {
1690 return false
1691 }
1692
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001693 // Filter-out unwanted depedendencies
1694 depTag := ctx.OtherModuleDependencyTag(child)
1695 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1696 return false
1697 }
1698 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001699 return false
1700 }
1701
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001702 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001703 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001704
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001705 // Visit actually
1706 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001707 })
1708}
1709
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001710// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1711type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001712
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001713const (
1714 ext4 fsType = iota
1715 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001716 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001717)
Artur Satayev849f8442020-04-28 14:57:42 +01001718
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001719func (f fsType) string() string {
1720 switch f {
1721 case ext4:
1722 return ext4FsType
1723 case f2fs:
1724 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001725 case erofs:
1726 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001727 default:
1728 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001729 }
1730}
1731
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001732// Creates build rules for an APEX. It consists of the following major steps:
1733//
1734// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1735// 2) traverse the dependency tree to collect apexFile structs from them.
1736// 3) some fields in apexBundle struct are configured
1737// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001738func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001739 ////////////////////////////////////////////////////////////////////////////////////////////
1740 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001741 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001742 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001743 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001744 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001745 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001746 if len(a.properties.Tests) > 0 && !a.testApex {
1747 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1748 return
1749 }
Jiyong Park678c8812020-02-07 17:25:49 +09001750
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001751 ////////////////////////////////////////////////////////////////////////////////////////////
1752 // 2) traverse the dependency tree to collect apexFile structs from them.
1753
1754 // all the files that will be included in this APEX
1755 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001756
Jooyung Hane1633032019-08-01 17:41:43 +09001757 // native lib dependencies
1758 var provideNativeLibs []string
1759 var requireNativeLibs []string
1760
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001761 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1762
braleeb0c1f0c2021-06-07 22:49:13 +08001763 // Collect the module directory for IDE info in java/jdeps.go.
1764 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1765
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001766 // TODO(jiyong): do this using WalkPayloadDeps
1767 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001768 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001769 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001770 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1771 return false
1772 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001773 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1774 return false
1775 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001776 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001777 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001778 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001779 case sharedLibTag, jniLibTag:
1780 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001781 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001782 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1783 fi.isJniLib = isJniLib
1784 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001785 // Collect the list of stub-providing libs except:
1786 // - VNDK libs are only for vendors
1787 // - bootstrap bionic libs are treated as provided by system
1788 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001789 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001790 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001791 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001792 } else if r, ok := child.(*rust.Module); ok {
1793 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001794 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001795 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001796 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001797 propertyName := "native_shared_libs"
1798 if isJniLib {
1799 propertyName = "jni_libs"
1800 }
1801 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001802 }
1803 case executableTag:
1804 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001805 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001806 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001807 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001808 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001809 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001810 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001811 } else if rust, ok := child.(*rust.Module); ok {
1812 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1813 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001814 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001815 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1816 }
1817 case shBinaryTag:
1818 if sh, ok := child.(*sh.ShBinary); ok {
1819 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1820 } else {
1821 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001822 }
Paul Duffin94f19632021-04-20 12:40:07 +01001823 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001824 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001825 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1826 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001827 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001828 return false
1829 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001830
Paul Duffincc33ec82021-04-25 23:14:55 +01001831 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1832 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001833 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1834 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1835 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001836 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001837 }
satayev333a1732021-05-17 21:35:26 +01001838 case sscpfTag:
1839 {
1840 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1841 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1842 return false
1843 }
satayevb98371c2021-06-15 16:49:50 +01001844 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1845 filesInfo = append(filesInfo, *af)
1846 }
satayev333a1732021-05-17 21:35:26 +01001847 return true
1848 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001849 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001850 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001851 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001852 af := apexFileForJavaModule(ctx, child.(javaModule))
1853 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001854 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1855 return false
1856 }
1857 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001858 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001859 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001860 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001861 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001862 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001863 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001864 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001865 return true // track transitive dependencies
1866 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001867 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001868 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001869 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001870 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1871 appDir := "app"
1872 if ap.Privileged() {
1873 appDir = "priv-app"
1874 }
Yo Chiange8128052020-07-23 20:09:18 +08001875 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001876 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1877 af.certificate = java.PresignedCertificate
1878 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001879 } else {
1880 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1881 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001882 case rroTag:
1883 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1884 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1885 } else {
1886 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1887 }
markchien2f59ec92020-09-02 16:23:38 +08001888 case bpfTag:
1889 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1890 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001891 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001892 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001893 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001894 }
1895 } else {
1896 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1897 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001898 case fsTag:
1899 if fs, ok := child.(filesystem.Filesystem); ok {
1900 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1901 } else {
1902 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1903 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001904 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001905 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001906 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001907 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001908 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001909 }
Paul Duffin0b817782021-03-17 15:02:19 +00001910 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001911 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1912 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1913 } else {
1914 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1915 }
Roland Levillain630846d2019-06-26 12:48:34 +01001916 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001917 if ccTest, ok := child.(*cc.Module); ok {
1918 if ccTest.IsTestPerSrcAllTestsVariation() {
1919 // Multiple-output test module (where `test_per_src: true`).
1920 //
1921 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1922 // We do not add this variation to `filesInfo`, as it has no output;
1923 // however, we do add the other variations of this module as indirect
1924 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001925 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001926 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001927 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001928 af.class = nativeTest
1929 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001930 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001931 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001932 } else {
1933 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1934 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001935 case keyTag:
1936 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001937 a.privateKeyFile = key.privateKeyFile
1938 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001939 } else {
1940 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001941 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001942 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001943 case certificateTag:
1944 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001945 a.containerCertificateFile = dep.Certificate.Pem
1946 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001947 } else {
1948 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1949 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001950 case android.PrebuiltDepTag:
1951 // If the prebuilt is force disabled, remember to delete the prebuilt file
1952 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001953 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001954 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1955 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001956 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001957 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001958 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001959 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001960 // We cannot use a switch statement on `depTag` here as the checked
1961 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001962 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001963 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001964 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001965 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001966 return false
1967 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001968 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1969 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001970
1971 // Always track transitive dependencies for host.
1972 if a.Host() {
1973 filesInfo = append(filesInfo, af)
1974 return true
1975 }
1976
Colin Cross56a83212020-09-15 18:30:11 -07001977 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001978 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001979 // If the dependency is a stubs lib, don't include it in this APEX,
1980 // but make sure that the lib is installed on the device.
1981 // In case no APEX is having the lib, the lib is installed to the system
1982 // partition.
1983 //
1984 // Always include if we are a host-apex however since those won't have any
1985 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001986 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001987 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001988 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001989 if !android.InList(name, a.requiredDeps) {
1990 a.requiredDeps = append(a.requiredDeps, name)
1991 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001992 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001993 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001994 // Don't track further
1995 return false
1996 }
Jiyong Parke3867542020-12-03 17:28:25 +09001997
1998 // If the dep is not considered to be in the same
1999 // apex, don't add it to filesInfo so that it is not
2000 // included in this APEX.
2001 // TODO(jiyong): move this to at the top of the
2002 // else-if clause for the indirect dependencies.
2003 // Currently, that's impossible because we would
2004 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002005 // DepIsInSameAPex is false. We also shouldn't do
2006 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002007 //
2008 // TODO(jiyong): explain why the same module is passed in twice.
2009 // Switching the first am to parent breaks lots of tests.
2010 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002011 return false
2012 }
2013
Jiyong Parkf653b052019-11-18 15:39:01 +09002014 filesInfo = append(filesInfo, af)
2015 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002016 } else if rm, ok := child.(*rust.Module); ok {
2017 af := apexFileForRustLibrary(ctx, rm)
2018 af.transitiveDep = true
2019 filesInfo = append(filesInfo, af)
2020 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002021 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002022 } else if cc.IsTestPerSrcDepTag(depTag) {
2023 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002024 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002025 // Handle modules created as `test_per_src` variations of a single test module:
2026 // use the name of the generated test binary (`fileToCopy`) instead of the name
2027 // of the original test module (`depName`, shared by all `test_per_src`
2028 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002029 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002030 // these are not considered transitive dep
2031 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002032 filesInfo = append(filesInfo, af)
2033 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002034 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002035 } else if cc.IsHeaderDepTag(depTag) {
2036 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002037 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002038 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2039 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002040 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002041 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002042 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2043 }
Jiyong Park99644e92020-11-17 22:21:02 +09002044 } else if rust.IsDylibDepTag(depTag) {
2045 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2046 af := apexFileForRustLibrary(ctx, rustm)
2047 af.transitiveDep = true
2048 filesInfo = append(filesInfo, af)
2049 return true // track transitive dependencies
2050 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002051 } else if rust.IsRlibDepTag(depTag) {
2052 // Rlib is statically linked, but it might have shared lib
2053 // dependencies. Track them.
2054 return true
Paul Duffin65898052021-04-20 22:47:03 +01002055 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002056 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002057 switch child.(type) {
2058 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002059 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002060 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002061 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002062 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002063 return false
2064 }
2065 filesInfo = append(filesInfo, af)
2066 return true // track transitive dependencies
2067 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002068 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 +00002069 }
satayev333a1732021-05-17 21:35:26 +01002070 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2071 // Add the contents of the systemserverclasspath fragment to the apex.
2072 switch child.(type) {
2073 case *java.Library, *java.SdkLibrary:
2074 af := apexFileForJavaModule(ctx, child.(javaModule))
2075 filesInfo = append(filesInfo, af)
2076 return true // track transitive dependencies
2077 default:
2078 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2079 }
Colin Cross56a83212020-09-15 18:30:11 -07002080 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2081 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002082 } else if depTag == android.DarwinUniversalVariantTag {
2083 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002084 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002085 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002086 }
2087 }
2088 }
2089 return false
2090 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002091 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002092 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002093 return
2094 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002095
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002096 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002097 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002098 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002099 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002100 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002101 if e, ok := encountered[dest]; !ok {
2102 encountered[dest] = f
2103 } else {
2104 // If a module is directly included and also transitively depended on
2105 // consider it as directly included.
2106 e.transitiveDep = e.transitiveDep && f.transitiveDep
2107 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002108 }
2109 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002110 var result []apexFile
2111 for _, v := range encountered {
2112 result = append(result, v)
2113 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002114 return result
2115 }
2116 filesInfo = removeDup(filesInfo)
2117
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002118 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002119 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002120 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2121 // changes.
2122 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002123 })
2124
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002125 ////////////////////////////////////////////////////////////////////////////////////////////
2126 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002127 a.installDir = android.PathForModuleInstall(ctx, "apex")
2128 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002129
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002130 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002131 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002132 switch a.properties.ApexType {
2133 case imageApex:
2134 if buildFlattenedAsDefault {
2135 a.suffix = imageApexSuffix
2136 } else {
2137 a.suffix = ""
2138 a.primaryApexType = true
2139
2140 if ctx.Config().InstallExtraFlattenedApexes() {
2141 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2142 }
2143 }
2144 case zipApex:
2145 if proptools.String(a.properties.Payload_type) == "zip" {
2146 a.suffix = ""
2147 a.primaryApexType = true
2148 } else {
2149 a.suffix = zipApexSuffix
2150 }
2151 case flattenedApex:
2152 if buildFlattenedAsDefault {
2153 a.suffix = ""
2154 a.primaryApexType = true
2155 } else {
2156 a.suffix = flattenedSuffix
2157 }
2158 }
2159
Theotime Combes4ba38c12020-06-12 12:46:59 +00002160 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2161 case ext4FsType:
2162 a.payloadFsType = ext4
2163 case f2fsFsType:
2164 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002165 case erofsFsType:
2166 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002167 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002168 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 +00002169 }
2170
Jiyong Park7cd10e32020-01-14 09:22:18 +09002171 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2172 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2173 // the same library in the system partition, thus effectively sharing the same libraries
2174 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2175 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002176 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002177
Jooyung Han85d61762020-06-24 23:50:26 +09002178 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2179 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002180 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002181 a.linkToSystemLib = false
2182 }
2183
Jiyong Park4da07972021-01-05 21:01:11 +09002184 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002185 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002186
Jiyong Park9d677202020-02-19 16:29:35 +09002187 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002188 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002189 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002190 a.linkToSystemLib = false
2191 }
2192
Jiyong Park638d30e2020-02-26 18:27:19 +09002193 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2194 if ctx.Host() {
2195 a.linkToSystemLib = false
2196 }
2197
Colin Cross6340ea52021-11-04 12:01:18 -07002198 if a.properties.ApexType != zipApex {
2199 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2200 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002201
2202 ////////////////////////////////////////////////////////////////////////////////////////////
2203 // 4) generate the build rules to create the APEX. This is done in builder.go.
2204 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002205 if a.properties.ApexType == flattenedApex {
2206 a.buildFlattenedApex(ctx)
2207 } else {
2208 a.buildUnflattenedApex(ctx)
2209 }
Jiyong Park956305c2020-01-09 12:32:06 +09002210 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002211 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002212
2213 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2214 if a.installable() {
2215 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2216 // along with other ordinary files. (Note that this is done by apexer for
2217 // non-flattened APEXes)
2218 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2219
2220 // Place the public key as apex_pubkey. This is also done by apexer for
2221 // non-flattened APEXes case.
2222 // TODO(jiyong): Why do we need this CP rule?
2223 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2224 ctx.Build(pctx, android.BuildParams{
2225 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002226 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002227 Output: copiedPubkey,
2228 })
2229 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2230 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002231}
2232
Paul Duffincc33ec82021-04-25 23:14:55 +01002233// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2234// the bootclasspath_fragment contributes to the apex.
2235func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2236 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2237 var filesToAdd []apexFile
2238
2239 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002240 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2241 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2242 dirInApex := filepath.Join("javalib", arch.String())
2243 for _, f := range files {
2244 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2245 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2246 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2247 filesToAdd = append(filesToAdd, af)
2248 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002249 }
2250 }
2251
satayev3db35472021-05-06 23:59:58 +01002252 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002253 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2254 filesToAdd = append(filesToAdd, *af)
2255 }
satayev3db35472021-05-06 23:59:58 +01002256
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002257 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2258 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2259 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2260
2261 if pathOnHost != nil {
2262 // We need to copy the profile to a temporary path with the right filename because the apexer
2263 // will take the filename as is.
2264 ctx.Build(pctx, android.BuildParams{
2265 Rule: android.Cp,
2266 Input: pathOnHost,
2267 Output: tempPath,
2268 })
2269 } else {
2270 // At this point, the boot image profile cannot be generated. It is probably because the boot
2271 // image profile source file does not exist on the branch, or it is not available for the
2272 // current build target.
2273 // However, we cannot enforce the boot image profile to be generated because some build
2274 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2275 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2276 // only if the APEX is being built.
2277 ctx.Build(pctx, android.BuildParams{
2278 Rule: android.ErrorRule,
2279 Output: tempPath,
2280 Args: map[string]string{
2281 "error": "Boot image profile cannot be generated",
2282 },
2283 })
2284 }
2285
2286 androidMkModuleName := filepath.Base(pathInApex)
2287 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2288 filesToAdd = append(filesToAdd, af)
2289 }
2290
Paul Duffincc33ec82021-04-25 23:14:55 +01002291 return filesToAdd
2292}
2293
satayevb98371c2021-06-15 16:49:50 +01002294// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2295// the module contributes to the apex; or nil if the proto config was not generated.
2296func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2297 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2298 if !info.ClasspathFragmentProtoGenerated {
2299 return nil
2300 }
2301 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2302 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2303 return &af
satayev14e49132021-05-17 21:03:07 +01002304}
2305
Paul Duffincc33ec82021-04-25 23:14:55 +01002306// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2307// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002308func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2309 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2310
2311 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2312 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002313 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2314 if err != nil {
2315 ctx.ModuleErrorf("%s", err)
2316 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002317
2318 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2319 // bootclasspath_fragment.
2320 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2321 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002322}
2323
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002324///////////////////////////////////////////////////////////////////////////////////////////////////
2325// Factory functions
2326//
2327
2328func newApexBundle() *apexBundle {
2329 module := &apexBundle{}
2330
2331 module.AddProperties(&module.properties)
2332 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002333 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002334 module.AddProperties(&module.overridableProperties)
2335
2336 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2337 android.InitDefaultableModule(module)
2338 android.InitSdkAwareModule(module)
2339 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002340 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002341 return module
2342}
2343
Paul Duffineb8051d2021-10-18 17:49:39 +01002344func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002345 bundle := newApexBundle()
2346 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002347 return bundle
2348}
2349
2350// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2351// certain compatibility checks such as apex_available are not done for apex_test.
2352func testApexBundleFactory() android.Module {
2353 bundle := newApexBundle()
2354 bundle.testApex = true
2355 return bundle
2356}
2357
2358// apex packages other modules into an APEX file which is a packaging format for system-level
2359// components like binaries, shared libraries, etc.
2360func BundleFactory() android.Module {
2361 return newApexBundle()
2362}
2363
2364type Defaults struct {
2365 android.ModuleBase
2366 android.DefaultsModuleBase
2367}
2368
2369// apex_defaults provides defaultable properties to other apex modules.
2370func defaultsFactory() android.Module {
2371 return DefaultsFactory()
2372}
2373
2374func DefaultsFactory(props ...interface{}) android.Module {
2375 module := &Defaults{}
2376
2377 module.AddProperties(props...)
2378 module.AddProperties(
2379 &apexBundleProperties{},
2380 &apexTargetBundleProperties{},
2381 &overridableProperties{},
2382 )
2383
2384 android.InitDefaultsModule(module)
2385 return module
2386}
2387
2388type OverrideApex struct {
2389 android.ModuleBase
2390 android.OverrideModuleBase
2391}
2392
2393func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2394 // All the overrides happen in the base module.
2395}
2396
2397// override_apex is used to create an apex module based on another apex module by overriding some of
2398// its properties.
2399func overrideApexFactory() android.Module {
2400 m := &OverrideApex{}
2401
2402 m.AddProperties(&overridableProperties{})
2403
2404 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2405 android.InitOverrideModule(m)
2406 return m
2407}
2408
2409///////////////////////////////////////////////////////////////////////////////////////////////////
2410// Vality check routines
2411//
2412// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2413// certain conditions are not met.
2414//
2415// TODO(jiyong): move these checks to a separate go file.
2416
satayevad991492021-12-03 18:58:32 +00002417var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2418
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002419// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2420// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002421func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002422 if a.testApex || a.vndkApex {
2423 return
2424 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002425 // apexBundle::minSdkVersion reports its own errors.
2426 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002427 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002428}
2429
satayevad991492021-12-03 18:58:32 +00002430func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2431 return android.SdkSpec{
2432 Kind: android.SdkNone,
2433 ApiLevel: a.minSdkVersion(ctx),
2434 Raw: String(a.properties.Min_sdk_version),
2435 }
2436}
2437
2438func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002439 ver := proptools.String(a.properties.Min_sdk_version)
2440 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002441 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002442 }
2443 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2444 if err != nil {
2445 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2446 return android.NoneApiLevel
2447 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002448 return apiLevel
2449}
2450
2451// Ensures that a lib providing stub isn't statically linked
2452func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2453 // Practically, we only care about regular APEXes on the device.
2454 if ctx.Host() || a.testApex || a.vndkApex {
2455 return
2456 }
2457
2458 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2459
2460 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2461 if ccm, ok := to.(*cc.Module); ok {
2462 apexName := ctx.ModuleName()
2463 fromName := ctx.OtherModuleName(from)
2464 toName := ctx.OtherModuleName(to)
2465
2466 // If `to` is not actually in the same APEX as `from` then it does not need
2467 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002468 //
2469 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002470 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2471 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2472 return false
2473 }
2474
2475 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2476 // exception to this rule. It can't make the static dependencies dynamic
2477 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002478 // Same rule should be applied to linkerconfig, because it should be executed
2479 // only with static linked libraries before linker is available with ld.config.txt
2480 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002481 return false
2482 }
2483
2484 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2485 if isStubLibraryFromOtherApex && !externalDep {
2486 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2487 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2488 }
2489
2490 }
2491 return true
2492 })
2493}
2494
satayevb98371c2021-06-15 16:49:50 +01002495// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002496func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2497 if a.Updatable() {
2498 if String(a.properties.Min_sdk_version) == "" {
2499 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2500 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002501 if a.UsePlatformApis() {
2502 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2503 }
Daniel Norman69109112021-12-02 12:52:42 -08002504 if a.SocSpecific() || a.DeviceSpecific() {
2505 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2506 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002507 if a.FutureUpdatable() {
2508 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2509 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002510 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002511 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002512 }
2513}
2514
satayevb98371c2021-06-15 16:49:50 +01002515// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2516func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2517 ctx.VisitDirectDeps(func(module android.Module) {
2518 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2519 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2520 if !info.ClasspathFragmentProtoGenerated {
2521 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2522 }
2523 }
2524 })
2525}
2526
2527// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002528func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002529 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2530 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002531 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2532 tag := ctx.OtherModuleDependencyTag(module)
2533 switch tag {
2534 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002535 if m, ok := module.(interface {
2536 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2537 }); ok {
2538 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002539 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2540 }
2541 }
2542 }
2543 })
2544}
2545
satayevb98371c2021-06-15 16:49:50 +01002546// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002547func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2548 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2549 if ctx.Host() || a.testApex || a.vndkApex {
2550 return
2551 }
2552
2553 // Because APEXes targeting other than system/system_ext partitions can't set
2554 // apex_available, we skip checks for these APEXes
2555 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2556 return
2557 }
2558
2559 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2560 // Requiring them and their transitive depencies with apex_available is not right
2561 // because they just add noise.
2562 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2563 return
2564 }
2565
2566 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2567 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2568 if externalDep {
2569 return false
2570 }
2571
2572 apexName := ctx.ModuleName()
2573 fromName := ctx.OtherModuleName(from)
2574 toName := ctx.OtherModuleName(to)
2575
2576 // If `to` is not actually in the same APEX as `from` then it does not need
2577 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002578 //
2579 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002580 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2581 // As soon as the dependency graph crosses the APEX boundary, don't go
2582 // further.
2583 return false
2584 }
2585
2586 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2587 return true
2588 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002589 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2590 "\n\nDependency path:%s\n\n"+
2591 "Consider adding %q to 'apex_available' property of %q",
2592 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002593 // Visit this module's dependencies to check and report any issues with their availability.
2594 return true
2595 })
2596}
2597
Jiyong Park192600a2021-08-03 07:52:17 +00002598// checkStaticExecutable ensures that executables in an APEX are not static.
2599func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002600 // No need to run this for host APEXes
2601 if ctx.Host() {
2602 return
2603 }
2604
Jiyong Park192600a2021-08-03 07:52:17 +00002605 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2606 if ctx.OtherModuleDependencyTag(module) != executableTag {
2607 return
2608 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002609
2610 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002611 apex := a.ApexVariationName()
2612 exec := ctx.OtherModuleName(module)
2613 if isStaticExecutableAllowed(apex, exec) {
2614 return
2615 }
2616 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2617 }
2618 })
2619}
2620
2621// A small list of exceptions where static executables are allowed in APEXes.
2622func isStaticExecutableAllowed(apex string, exec string) bool {
2623 m := map[string][]string{
2624 "com.android.runtime": []string{
2625 "linker",
2626 "linkerconfig",
2627 },
2628 }
2629 execNames, ok := m[apex]
2630 return ok && android.InList(exec, execNames)
2631}
2632
braleeb0c1f0c2021-06-07 22:49:13 +08002633// Collect information for opening IDE project files in java/jdeps.go.
2634func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2635 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2636 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2637 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2638 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2639}
2640
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002641var (
2642 apexAvailBaseline = makeApexAvailableBaseline()
2643 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2644)
2645
Colin Cross440e0d02020-06-11 11:32:11 -07002646func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002647 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002648 moduleName = normalizeModuleName(moduleName)
2649
Colin Cross440e0d02020-06-11 11:32:11 -07002650 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002651 return true
2652 }
2653
2654 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002655 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002656 return true
2657 }
2658
2659 return false
2660}
2661
2662func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002663 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2664 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002665 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002666 if strings.HasPrefix(moduleName, "libclang_rt.") {
2667 // This module has many arch variants that depend on the product being built.
2668 // We don't want to list them all
2669 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002670 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002671 if strings.HasPrefix(moduleName, "androidx.") {
2672 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2673 moduleName = "androidx"
2674 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002675 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002676}
2677
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002678// Transform the map of apex -> modules to module -> apexes.
2679func invertApexBaseline(m map[string][]string) map[string][]string {
2680 r := make(map[string][]string)
2681 for apex, modules := range m {
2682 for _, module := range modules {
2683 r[module] = append(r[module], apex)
2684 }
2685 }
2686 return r
2687}
2688
2689// Retrieve the baseline of apexes to which the supplied module belongs.
2690func BaselineApexAvailable(moduleName string) []string {
2691 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2692}
2693
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002694// This is a map from apex to modules, which overrides the apex_available setting for that
2695// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002696// TODO(b/147364041): remove this
2697func makeApexAvailableBaseline() map[string][]string {
2698 // The "Module separator"s below are employed to minimize merge conflicts.
2699 m := make(map[string][]string)
2700 //
2701 // Module separator
2702 //
2703 m["com.android.appsearch"] = []string{
2704 "icing-java-proto-lite",
2705 "libprotobuf-java-lite",
2706 }
2707 //
2708 // Module separator
2709 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002710 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002711 "android.hardware.audio.common@5.0",
2712 "android.hardware.bluetooth.a2dp@1.0",
2713 "android.hardware.bluetooth.audio@2.0",
2714 "android.hardware.bluetooth@1.0",
2715 "android.hardware.bluetooth@1.1",
2716 "android.hardware.graphics.bufferqueue@1.0",
2717 "android.hardware.graphics.bufferqueue@2.0",
2718 "android.hardware.graphics.common@1.0",
2719 "android.hardware.graphics.common@1.1",
2720 "android.hardware.graphics.common@1.2",
2721 "android.hardware.media@1.0",
2722 "android.hidl.safe_union@1.0",
2723 "android.hidl.token@1.0",
2724 "android.hidl.token@1.0-utils",
2725 "avrcp-target-service",
2726 "avrcp_headers",
2727 "bluetooth-protos-lite",
2728 "bluetooth.mapsapi",
2729 "com.android.vcard",
2730 "dnsresolver_aidl_interface-V2-java",
2731 "ipmemorystore-aidl-interfaces-V5-java",
2732 "ipmemorystore-aidl-interfaces-java",
2733 "internal_include_headers",
2734 "lib-bt-packets",
2735 "lib-bt-packets-avrcp",
2736 "lib-bt-packets-base",
2737 "libFraunhoferAAC",
2738 "libaudio-a2dp-hw-utils",
2739 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002740 "libbluetooth",
2741 "libbluetooth-types",
2742 "libbluetooth-types-header",
2743 "libbluetooth_gd",
2744 "libbluetooth_headers",
2745 "libbluetooth_jni",
2746 "libbt-audio-hal-interface",
2747 "libbt-bta",
2748 "libbt-common",
2749 "libbt-hci",
2750 "libbt-platform-protos-lite",
2751 "libbt-protos-lite",
2752 "libbt-sbc-decoder",
2753 "libbt-sbc-encoder",
2754 "libbt-stack",
2755 "libbt-utils",
2756 "libbtcore",
2757 "libbtdevice",
2758 "libbte",
2759 "libbtif",
2760 "libchrome",
2761 "libevent",
2762 "libfmq",
2763 "libg722codec",
2764 "libgui_headers",
2765 "libmedia_headers",
2766 "libmodpb64",
2767 "libosi",
2768 "libstagefright_foundation_headers",
2769 "libstagefright_headers",
2770 "libstatslog",
2771 "libstatssocket",
2772 "libtinyxml2",
2773 "libudrv-uipc",
2774 "libz",
2775 "media_plugin_headers",
2776 "net-utils-services-common",
2777 "netd_aidl_interface-unstable-java",
2778 "netd_event_listener_interface-java",
2779 "netlink-client",
2780 "networkstack-client",
2781 "sap-api-java-static",
2782 "services.net",
2783 }
2784 //
2785 // Module separator
2786 //
2787 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2788 //
2789 // Module separator
2790 //
2791 m["com.android.extservices"] = []string{
2792 "error_prone_annotations",
2793 "ExtServices-core",
2794 "ExtServices",
2795 "libtextclassifier-java",
2796 "libz_current",
2797 "textclassifier-statsd",
2798 "TextClassifierNotificationLibNoManifest",
2799 "TextClassifierServiceLibNoManifest",
2800 }
2801 //
2802 // Module separator
2803 //
2804 m["com.android.neuralnetworks"] = []string{
2805 "android.hardware.neuralnetworks@1.0",
2806 "android.hardware.neuralnetworks@1.1",
2807 "android.hardware.neuralnetworks@1.2",
2808 "android.hardware.neuralnetworks@1.3",
2809 "android.hidl.allocator@1.0",
2810 "android.hidl.memory.token@1.0",
2811 "android.hidl.memory@1.0",
2812 "android.hidl.safe_union@1.0",
2813 "libarect",
2814 "libbuildversion",
2815 "libmath",
2816 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002817 }
2818 //
2819 // Module separator
2820 //
2821 m["com.android.media"] = []string{
2822 "android.frameworks.bufferhub@1.0",
2823 "android.hardware.cas.native@1.0",
2824 "android.hardware.cas@1.0",
2825 "android.hardware.configstore-utils",
2826 "android.hardware.configstore@1.0",
2827 "android.hardware.configstore@1.1",
2828 "android.hardware.graphics.allocator@2.0",
2829 "android.hardware.graphics.allocator@3.0",
2830 "android.hardware.graphics.bufferqueue@1.0",
2831 "android.hardware.graphics.bufferqueue@2.0",
2832 "android.hardware.graphics.common@1.0",
2833 "android.hardware.graphics.common@1.1",
2834 "android.hardware.graphics.common@1.2",
2835 "android.hardware.graphics.mapper@2.0",
2836 "android.hardware.graphics.mapper@2.1",
2837 "android.hardware.graphics.mapper@3.0",
2838 "android.hardware.media.omx@1.0",
2839 "android.hardware.media@1.0",
2840 "android.hidl.allocator@1.0",
2841 "android.hidl.memory.token@1.0",
2842 "android.hidl.memory@1.0",
2843 "android.hidl.token@1.0",
2844 "android.hidl.token@1.0-utils",
2845 "bionic_libc_platform_headers",
2846 "exoplayer2-extractor",
2847 "exoplayer2-extractor-annotation-stubs",
2848 "gl_headers",
2849 "jsr305",
2850 "libEGL",
2851 "libEGL_blobCache",
2852 "libEGL_getProcAddress",
2853 "libFLAC",
2854 "libFLAC-config",
2855 "libFLAC-headers",
2856 "libGLESv2",
2857 "libaacextractor",
2858 "libamrextractor",
2859 "libarect",
2860 "libaudio_system_headers",
2861 "libaudioclient",
2862 "libaudioclient_headers",
2863 "libaudiofoundation",
2864 "libaudiofoundation_headers",
2865 "libaudiomanager",
2866 "libaudiopolicy",
2867 "libaudioutils",
2868 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002869 "libbluetooth-types-header",
2870 "libbufferhub",
2871 "libbufferhub_headers",
2872 "libbufferhubqueue",
2873 "libc_malloc_debug_backtrace",
2874 "libcamera_client",
2875 "libcamera_metadata",
2876 "libdvr_headers",
2877 "libexpat",
2878 "libfifo",
2879 "libflacextractor",
2880 "libgrallocusage",
2881 "libgraphicsenv",
2882 "libgui",
2883 "libgui_headers",
2884 "libhardware_headers",
2885 "libinput",
2886 "liblzma",
2887 "libmath",
2888 "libmedia",
2889 "libmedia_codeclist",
2890 "libmedia_headers",
2891 "libmedia_helper",
2892 "libmedia_helper_headers",
2893 "libmedia_midiiowrapper",
2894 "libmedia_omx",
2895 "libmediautils",
2896 "libmidiextractor",
2897 "libmkvextractor",
2898 "libmp3extractor",
2899 "libmp4extractor",
2900 "libmpeg2extractor",
2901 "libnativebase_headers",
2902 "libnativewindow_headers",
2903 "libnblog",
2904 "liboggextractor",
2905 "libpackagelistparser",
2906 "libpdx",
2907 "libpdx_default_transport",
2908 "libpdx_headers",
2909 "libpdx_uds",
2910 "libprocinfo",
2911 "libspeexresampler",
2912 "libspeexresampler",
2913 "libstagefright_esds",
2914 "libstagefright_flacdec",
2915 "libstagefright_flacdec",
2916 "libstagefright_foundation",
2917 "libstagefright_foundation_headers",
2918 "libstagefright_foundation_without_imemory",
2919 "libstagefright_headers",
2920 "libstagefright_id3",
2921 "libstagefright_metadatautils",
2922 "libstagefright_mpeg2extractor",
2923 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002924 "libui",
2925 "libui_headers",
2926 "libunwindstack",
2927 "libvibrator",
2928 "libvorbisidec",
2929 "libwavextractor",
2930 "libwebm",
2931 "media_ndk_headers",
2932 "media_plugin_headers",
2933 "updatable-media",
2934 }
2935 //
2936 // Module separator
2937 //
2938 m["com.android.media.swcodec"] = []string{
2939 "android.frameworks.bufferhub@1.0",
2940 "android.hardware.common-ndk_platform",
2941 "android.hardware.configstore-utils",
2942 "android.hardware.configstore@1.0",
2943 "android.hardware.configstore@1.1",
2944 "android.hardware.graphics.allocator@2.0",
2945 "android.hardware.graphics.allocator@3.0",
2946 "android.hardware.graphics.allocator@4.0",
2947 "android.hardware.graphics.bufferqueue@1.0",
2948 "android.hardware.graphics.bufferqueue@2.0",
2949 "android.hardware.graphics.common-ndk_platform",
2950 "android.hardware.graphics.common@1.0",
2951 "android.hardware.graphics.common@1.1",
2952 "android.hardware.graphics.common@1.2",
2953 "android.hardware.graphics.mapper@2.0",
2954 "android.hardware.graphics.mapper@2.1",
2955 "android.hardware.graphics.mapper@3.0",
2956 "android.hardware.graphics.mapper@4.0",
2957 "android.hardware.media.bufferpool@2.0",
2958 "android.hardware.media.c2@1.0",
2959 "android.hardware.media.c2@1.1",
2960 "android.hardware.media.omx@1.0",
2961 "android.hardware.media@1.0",
2962 "android.hardware.media@1.0",
2963 "android.hidl.memory.token@1.0",
2964 "android.hidl.memory@1.0",
2965 "android.hidl.safe_union@1.0",
2966 "android.hidl.token@1.0",
2967 "android.hidl.token@1.0-utils",
2968 "libEGL",
2969 "libFLAC",
2970 "libFLAC-config",
2971 "libFLAC-headers",
2972 "libFraunhoferAAC",
2973 "libLibGuiProperties",
2974 "libarect",
2975 "libaudio_system_headers",
2976 "libaudioutils",
2977 "libaudioutils",
2978 "libaudioutils_fixedfft",
2979 "libavcdec",
2980 "libavcenc",
2981 "libavservices_minijail",
2982 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002983 "libbinderthreadstateutils",
2984 "libbluetooth-types-header",
2985 "libbufferhub_headers",
2986 "libcodec2",
2987 "libcodec2_headers",
2988 "libcodec2_hidl@1.0",
2989 "libcodec2_hidl@1.1",
2990 "libcodec2_internal",
2991 "libcodec2_soft_aacdec",
2992 "libcodec2_soft_aacenc",
2993 "libcodec2_soft_amrnbdec",
2994 "libcodec2_soft_amrnbenc",
2995 "libcodec2_soft_amrwbdec",
2996 "libcodec2_soft_amrwbenc",
2997 "libcodec2_soft_av1dec_gav1",
2998 "libcodec2_soft_avcdec",
2999 "libcodec2_soft_avcenc",
3000 "libcodec2_soft_common",
3001 "libcodec2_soft_flacdec",
3002 "libcodec2_soft_flacenc",
3003 "libcodec2_soft_g711alawdec",
3004 "libcodec2_soft_g711mlawdec",
3005 "libcodec2_soft_gsmdec",
3006 "libcodec2_soft_h263dec",
3007 "libcodec2_soft_h263enc",
3008 "libcodec2_soft_hevcdec",
3009 "libcodec2_soft_hevcenc",
3010 "libcodec2_soft_mp3dec",
3011 "libcodec2_soft_mpeg2dec",
3012 "libcodec2_soft_mpeg4dec",
3013 "libcodec2_soft_mpeg4enc",
3014 "libcodec2_soft_opusdec",
3015 "libcodec2_soft_opusenc",
3016 "libcodec2_soft_rawdec",
3017 "libcodec2_soft_vorbisdec",
3018 "libcodec2_soft_vp8dec",
3019 "libcodec2_soft_vp8enc",
3020 "libcodec2_soft_vp9dec",
3021 "libcodec2_soft_vp9enc",
3022 "libcodec2_vndk",
3023 "libdvr_headers",
3024 "libfmq",
3025 "libfmq",
3026 "libgav1",
3027 "libgralloctypes",
3028 "libgrallocusage",
3029 "libgraphicsenv",
3030 "libgsm",
3031 "libgui_bufferqueue_static",
3032 "libgui_headers",
3033 "libhardware",
3034 "libhardware_headers",
3035 "libhevcdec",
3036 "libhevcenc",
3037 "libion",
3038 "libjpeg",
3039 "liblzma",
3040 "libmath",
3041 "libmedia_codecserviceregistrant",
3042 "libmedia_headers",
3043 "libmpeg2dec",
3044 "libnativebase_headers",
3045 "libnativewindow_headers",
3046 "libpdx_headers",
3047 "libscudo_wrapper",
3048 "libsfplugin_ccodec_utils",
3049 "libspeexresampler",
3050 "libstagefright_amrnb_common",
3051 "libstagefright_amrnbdec",
3052 "libstagefright_amrnbenc",
3053 "libstagefright_amrwbdec",
3054 "libstagefright_amrwbenc",
3055 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003056 "libstagefright_enc_common",
3057 "libstagefright_flacdec",
3058 "libstagefright_foundation",
3059 "libstagefright_foundation_headers",
3060 "libstagefright_headers",
3061 "libstagefright_m4vh263dec",
3062 "libstagefright_m4vh263enc",
3063 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003064 "libui",
3065 "libui_headers",
3066 "libunwindstack",
3067 "libvorbisidec",
3068 "libvpx",
3069 "libyuv",
3070 "libyuv_static",
3071 "media_ndk_headers",
3072 "media_plugin_headers",
3073 "mediaswcodec",
3074 }
3075 //
3076 // Module separator
3077 //
3078 m["com.android.mediaprovider"] = []string{
3079 "MediaProvider",
3080 "MediaProviderGoogle",
3081 "fmtlib_ndk",
3082 "libbase_ndk",
3083 "libfuse",
3084 "libfuse_jni",
3085 }
3086 //
3087 // Module separator
3088 //
3089 m["com.android.permission"] = []string{
3090 "car-ui-lib",
3091 "iconloader",
3092 "kotlin-annotations",
3093 "kotlin-stdlib",
3094 "kotlin-stdlib-jdk7",
3095 "kotlin-stdlib-jdk8",
3096 "kotlinx-coroutines-android",
3097 "kotlinx-coroutines-android-nodeps",
3098 "kotlinx-coroutines-core",
3099 "kotlinx-coroutines-core-nodeps",
3100 "permissioncontroller-statsd",
3101 "GooglePermissionController",
3102 "PermissionController",
3103 "SettingsLibActionBarShadow",
3104 "SettingsLibAppPreference",
3105 "SettingsLibBarChartPreference",
3106 "SettingsLibLayoutPreference",
3107 "SettingsLibProgressBar",
3108 "SettingsLibSearchWidget",
3109 "SettingsLibSettingsTheme",
3110 "SettingsLibRestrictedLockUtils",
3111 "SettingsLibHelpUtils",
3112 }
3113 //
3114 // Module separator
3115 //
3116 m["com.android.runtime"] = []string{
3117 "bionic_libc_platform_headers",
3118 "libarm-optimized-routines-math",
3119 "libc_aeabi",
3120 "libc_bionic",
3121 "libc_bionic_ndk",
3122 "libc_bootstrap",
3123 "libc_common",
3124 "libc_common_shared",
3125 "libc_common_static",
3126 "libc_dns",
3127 "libc_dynamic_dispatch",
3128 "libc_fortify",
3129 "libc_freebsd",
3130 "libc_freebsd_large_stack",
3131 "libc_gdtoa",
3132 "libc_init_dynamic",
3133 "libc_init_static",
3134 "libc_jemalloc_wrapper",
3135 "libc_netbsd",
3136 "libc_nomalloc",
3137 "libc_nopthread",
3138 "libc_openbsd",
3139 "libc_openbsd_large_stack",
3140 "libc_openbsd_ndk",
3141 "libc_pthread",
3142 "libc_static_dispatch",
3143 "libc_syscalls",
3144 "libc_tzcode",
3145 "libc_unwind_static",
3146 "libdebuggerd",
3147 "libdebuggerd_common_headers",
3148 "libdebuggerd_handler_core",
3149 "libdebuggerd_handler_fallback",
3150 "libdl_static",
3151 "libjemalloc5",
3152 "liblinker_main",
3153 "liblinker_malloc",
3154 "liblz4",
3155 "liblzma",
3156 "libprocinfo",
3157 "libpropertyinfoparser",
3158 "libscudo",
3159 "libstdc++",
3160 "libsystemproperties",
3161 "libtombstoned_client_static",
3162 "libunwindstack",
3163 "libz",
3164 "libziparchive",
3165 }
3166 //
3167 // Module separator
3168 //
3169 m["com.android.tethering"] = []string{
3170 "android.hardware.tetheroffload.config-V1.0-java",
3171 "android.hardware.tetheroffload.control-V1.0-java",
3172 "android.hidl.base-V1.0-java",
3173 "libcgrouprc",
3174 "libcgrouprc_format",
3175 "libtetherutilsjni",
3176 "libvndksupport",
3177 "net-utils-framework-common",
3178 "netd_aidl_interface-V3-java",
3179 "netlink-client",
3180 "networkstack-aidl-interfaces-java",
3181 "tethering-aidl-interfaces-java",
3182 "TetheringApiCurrentLib",
3183 }
3184 //
3185 // Module separator
3186 //
3187 m["com.android.wifi"] = []string{
3188 "PlatformProperties",
3189 "android.hardware.wifi-V1.0-java",
3190 "android.hardware.wifi-V1.0-java-constants",
3191 "android.hardware.wifi-V1.1-java",
3192 "android.hardware.wifi-V1.2-java",
3193 "android.hardware.wifi-V1.3-java",
3194 "android.hardware.wifi-V1.4-java",
3195 "android.hardware.wifi.hostapd-V1.0-java",
3196 "android.hardware.wifi.hostapd-V1.1-java",
3197 "android.hardware.wifi.hostapd-V1.2-java",
3198 "android.hardware.wifi.supplicant-V1.0-java",
3199 "android.hardware.wifi.supplicant-V1.1-java",
3200 "android.hardware.wifi.supplicant-V1.2-java",
3201 "android.hardware.wifi.supplicant-V1.3-java",
3202 "android.hidl.base-V1.0-java",
3203 "android.hidl.manager-V1.0-java",
3204 "android.hidl.manager-V1.1-java",
3205 "android.hidl.manager-V1.2-java",
3206 "bouncycastle-unbundled",
3207 "dnsresolver_aidl_interface-V2-java",
3208 "error_prone_annotations",
3209 "framework-wifi-pre-jarjar",
3210 "framework-wifi-util-lib",
3211 "ipmemorystore-aidl-interfaces-V3-java",
3212 "ipmemorystore-aidl-interfaces-java",
3213 "ksoap2",
3214 "libnanohttpd",
3215 "libwifi-jni",
3216 "net-utils-services-common",
3217 "netd_aidl_interface-V2-java",
3218 "netd_aidl_interface-unstable-java",
3219 "netd_event_listener_interface-java",
3220 "netlink-client",
3221 "networkstack-client",
3222 "services.net",
3223 "wifi-lite-protos",
3224 "wifi-nano-protos",
3225 "wifi-service-pre-jarjar",
3226 "wifi-service-resources",
3227 }
3228 //
3229 // Module separator
3230 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003231 m["com.android.os.statsd"] = []string{
3232 "libstatssocket",
3233 }
3234 //
3235 // Module separator
3236 //
3237 m[android.AvailableToAnyApex] = []string{
3238 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3239 "androidx",
3240 "androidx-constraintlayout_constraintlayout",
3241 "androidx-constraintlayout_constraintlayout-nodeps",
3242 "androidx-constraintlayout_constraintlayout-solver",
3243 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3244 "com.google.android.material_material",
3245 "com.google.android.material_material-nodeps",
3246
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003247 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003248 "libprofile-clang-extras",
3249 "libprofile-clang-extras_ndk",
3250 "libprofile-extras",
3251 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003252 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003253 }
3254 return m
3255}
3256
3257func init() {
3258 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3259 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3260}
3261
3262func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3263 rules := make([]android.Rule, 0, len(modules_packages))
3264 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003265 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003266 BootclasspathJar().
3267 With("apex_available", module_name).
3268 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003269 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003270 Because("jars that are part of the " + module_name +
Andrei Onead967aee2022-01-19 15:36:40 +00003271 " module may only use these package prefixes: " + strings.Join(module_packages, ",") +
3272 " with min_sdk < T. Please consider the following alternatives:\n" +
3273 " 1. If the offending code is from a statically linked library, consider " +
3274 "removing that dependency and using an alternative already in the " +
3275 "bootclasspath, or perhaps a shared library." +
3276 " 2. Move the offending code into an allowed package.\n" +
3277 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3278 "health implications of bundling that code, particularly if the offending jar " +
3279 "is part of the bootclasspath.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003280 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003281 }
3282 return rules
3283}
3284
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003285// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on Q/R/S.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003286// Adding code to the bootclasspath in new packages will cause issues on module update.
3287func qModulesPackages() map[string][]string {
3288 return map[string][]string{
3289 "com.android.conscrypt": []string{
3290 "android.net.ssl",
3291 "com.android.org.conscrypt",
3292 },
3293 "com.android.media": []string{
3294 "android.media",
3295 },
3296 }
3297}
3298
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003299// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART on R/S.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003300// Adding code to the bootclasspath in new packages will cause issues on module update.
3301func rModulesPackages() map[string][]string {
3302 return map[string][]string{
3303 "com.android.mediaprovider": []string{
3304 "android.provider",
3305 },
3306 "com.android.permission": []string{
3307 "android.permission",
3308 "android.app.role",
3309 "com.android.permission",
3310 "com.android.role",
3311 },
3312 "com.android.sdkext": []string{
3313 "android.os.ext",
3314 },
3315 "com.android.os.statsd": []string{
3316 "android.app",
3317 "android.os",
3318 "android.util",
3319 "com.android.internal.statsd",
3320 "com.android.server.stats",
3321 },
3322 "com.android.wifi": []string{
3323 "com.android.server.wifi",
3324 "com.android.wifi.x",
3325 "android.hardware.wifi",
3326 "android.net.wifi",
3327 },
3328 "com.android.tethering": []string{
3329 "android.net",
3330 },
3331 }
3332}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003333
3334// For Bazel / bp2build
3335
3336type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003337 Manifest bazel.LabelAttribute
3338 Android_manifest bazel.LabelAttribute
3339 File_contexts bazel.LabelAttribute
3340 Key bazel.LabelAttribute
3341 Certificate bazel.LabelAttribute
3342 Min_sdk_version *string
3343 Updatable bazel.BoolAttribute
3344 Installable bazel.BoolAttribute
3345 Binaries bazel.LabelListAttribute
3346 Prebuilts bazel.LabelListAttribute
3347 Native_shared_libs_32 bazel.LabelListAttribute
3348 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003349 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003350}
3351
3352type convertedNativeSharedLibs struct {
3353 Native_shared_libs_32 bazel.LabelListAttribute
3354 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003355}
3356
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003357// ConvertWithBp2build performs bp2build conversion of an apex
3358func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3359 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003360 if ctx.ModuleType() != "apex" {
3361 return
3362 }
3363
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003364 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003365 if a.properties.Manifest != nil {
3366 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003367 }
3368
3369 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003370 if a.properties.AndroidManifest != nil {
3371 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003372 }
3373
3374 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003375 if a.properties.File_contexts != nil {
3376 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003377 }
3378
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003379 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003380 if a.properties.Min_sdk_version != nil {
3381 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003382 }
3383
3384 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003385 if a.overridableProperties.Key != nil {
3386 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003387 }
3388
3389 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003390 if a.overridableProperties.Certificate != nil {
3391 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003392 }
3393
Yu Liu4ae55d12022-01-05 17:17:23 -08003394 nativeSharedLibs := &convertedNativeSharedLibs{
3395 Native_shared_libs_32: bazel.LabelListAttribute{},
3396 Native_shared_libs_64: bazel.LabelListAttribute{},
3397 }
3398 compileMultilib := "both"
3399 if a.CompileMultilib() != nil {
3400 compileMultilib = *a.CompileMultilib()
3401 }
3402
3403 // properties.Native_shared_libs is treated as "both"
3404 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3405 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3406 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3407 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3408 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003409
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003410 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003411 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3412 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3413
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003414 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003415 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003416
3417 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003418 if a.properties.Updatable != nil {
3419 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003420 }
3421
3422 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003423 if a.properties.Installable != nil {
3424 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003425 }
3426
Wei Lif034cb42022-01-19 15:54:31 -08003427 var compressibleAttribute bazel.BoolAttribute
3428 if a.overridableProperties.Compressible != nil {
3429 compressibleAttribute.Value = a.overridableProperties.Compressible
3430 }
3431
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003432 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003433 Manifest: manifestLabelAttribute,
3434 Android_manifest: androidManifestLabelAttribute,
3435 File_contexts: fileContextsLabelAttribute,
3436 Min_sdk_version: minSdkVersion,
3437 Key: keyLabelAttribute,
3438 Certificate: certificateLabelAttribute,
3439 Updatable: updatableAttribute,
3440 Installable: installableAttribute,
3441 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3442 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3443 Binaries: binariesLabelListAttribute,
3444 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003445 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003446 }
3447
3448 props := bazel.BazelTargetModuleProperties{
3449 Rule_class: "apex",
3450 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3451 }
3452
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003453 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003454}
Yu Liu4ae55d12022-01-05 17:17:23 -08003455
3456// The following conversions are based on this table where the rows are the compile_multilib
3457// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3458// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3459// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3460// should not be compiled.
3461// multib/compile_multilib, 32, 64, both, first
3462// 32, 32/32, none/none, 32/32, none/32
3463// 64, none/none, 64/none, 64/none, 64/none
3464// both, 32/32, 64/none, 32&64/32, 64/32
3465// first, 32/32, 64/none, 64/32, 64/32
3466
3467func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3468 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3469 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3470 switch compileMultilb {
3471 case "both", "32":
3472 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3473 case "first":
3474 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3475 case "64":
3476 // Incompatible, ignore
3477 default:
3478 invalidCompileMultilib(ctx, compileMultilb)
3479 }
3480}
3481
3482func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3483 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3484 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3485 switch compileMultilb {
3486 case "both", "64", "first":
3487 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3488 case "32":
3489 // Incompatible, ignore
3490 default:
3491 invalidCompileMultilib(ctx, compileMultilb)
3492 }
3493}
3494
3495func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3496 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3497 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3498 switch compileMultilb {
3499 case "both":
3500 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3501 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3502 case "first":
3503 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3504 case "32":
3505 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3506 case "64":
3507 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3508 default:
3509 invalidCompileMultilib(ctx, compileMultilb)
3510 }
3511}
3512
3513func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3514 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3515 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3516 switch compileMultilb {
3517 case "both", "first":
3518 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3519 case "32":
3520 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3521 case "64":
3522 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3523 default:
3524 invalidCompileMultilib(ctx, compileMultilb)
3525 }
3526}
3527
3528func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3529 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3530 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3531}
3532
3533func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3534 list := bazel.LabelListAttribute{}
3535 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3536 nativeSharedLibs.Native_shared_libs_32.Append(list)
3537}
3538
3539func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3540 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3541 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3542}
3543
3544func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3545 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3546 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3547}
3548
3549func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3550 labelListAttr *bazel.LabelListAttribute) {
3551 list := bazel.LabelListAttribute{}
3552 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3553 labelListAttr.Append(list)
3554}
3555
3556func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3557 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3558}