blob: 6275c4dd96782d668681e80e8f160646b8e290fe [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090034 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/java"
36 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090037 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090039)
40
Jiyong Park8e6d52f2020-11-19 14:37:47 +090041func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000042 registerApexBuildComponents(android.InitRegistrationContext)
43}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044
Paul Duffin667893c2021-03-09 22:34:13 +000045func registerApexBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("apex", BundleFactory)
47 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
48 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
49 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
50 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
51 ctx.RegisterModuleType("override_apex", overrideApexFactory)
52 ctx.RegisterModuleType("apex_set", apexSetFactory)
53
Paul Duffin5dda3e32021-05-05 14:13:27 +010054 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.PreDepsMutators(RegisterPreDepsMutators)
56 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090057}
58
Paul Duffin5dda3e32021-05-05 14:13:27 +010059func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
60 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
61}
62
Jiyong Park8e6d52f2020-11-19 14:37:47 +090063func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
64 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
65 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
66}
67
68func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000069 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090070 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
71 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
72 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010073 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
74 // it should create a platform variant.
75 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090076 ctx.BottomUp("apex", apexMutator).Parallel()
77 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
78 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090079}
80
81type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090082 // Json manifest file describing meta info of this APEX bundle. Refer to
83 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090084 Manifest *string `android:"path"`
85
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090086 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
87 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090088 AndroidManifest *string `android:"path"`
89
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090090 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
91 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090092 Apex_name *string
93
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090094 // Determines the file contexts file for setting the security contexts to files in this APEX
95 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
96 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090097 File_contexts *string `android:"path"`
98
Jiyong Park038e8522021-12-13 23:56:35 +090099 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
100 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
101 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
102 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
103 // capability. If this property is not set, or a file is missing in the file, default config
104 // is used.
105 Canned_fs_config *string `android:"path"`
106
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900107 ApexNativeDependencies
108
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900109 Multilib apexMultilibProperties
110
Paul Duffin4b64ba02021-03-29 11:02:53 +0100111 // List of bootclasspath fragments that are embedded inside this APEX bundle.
112 Bootclasspath_fragments []string
113
satayev333a1732021-05-17 21:35:26 +0100114 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
115 Systemserverclasspath_fragments []string
116
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900117 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900118 Java_libs []string
119
Sundong Ahn80c04892021-11-23 00:57:19 +0000120 // List of sh binaries that are embedded inside this APEX bundle.
121 Sh_binaries []string
122
Paul Duffin3abc1742021-03-15 19:32:23 +0000123 // List of platform_compat_config files that are embedded inside this APEX bundle.
124 Compat_configs []string
125
Jiyong Park12a719c2021-01-07 15:31:24 +0900126 // List of filesystem images that are embedded inside this APEX bundle.
127 Filesystems []string
128
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900129 // The minimum SDK version that this APEX must support at minimum. This is usually set to
130 // the SDK version that the APEX was first introduced.
131 Min_sdk_version *string
132
133 // Whether this APEX is considered updatable or not. When set to true, this will enforce
134 // additional rules for making sure that the APEX is truly updatable. To be updatable,
135 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000136 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900137 Updatable *bool
138
Jiyong Parkf4020582021-11-29 12:37:10 +0900139 // Marks that this APEX is designed to be updatable in the future, although it's not
140 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
141 // updatable APEXes. Currently, this disables the size optimization, so that the size of
142 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
143 // false.
144 Future_updatable *bool
145
Jiyong Park1bc84122021-06-22 20:23:05 +0900146 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
147 // false`. Default is false.
148 Platform_apis *bool
149
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900150 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
151 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900152 Installable *bool
153
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900154 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
155 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
156 Use_vndk_as_stable *bool
157
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000158 // Whether this is multi-installed APEX should skip installing symbol files.
159 // Multi-installed APEXes share the same apex_name and are installed at the same time.
160 // Default is false.
161 //
162 // Should be set to true for all multi-installed APEXes except the singular
163 // default version within the multi-installed group.
164 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
165 // or else conflicting build rules may be created.
166 Multi_install_skip_symbol_files *bool
167
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900168 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
169 // `name#version` or `name` which is an alias for `name#current`. If left empty,
170 // `platform#current` is implied. This value affects all modules included in this APEX. In
171 // other words, they are also built with the SDKs specified here.
172 Uses_sdks []string
173
174 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
175 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
176 // container. When set to zip, contents are stored in a zip container directly. This type is
177 // mostly for host-side debugging. When set to both, the two types are both built. Default
178 // is 'image'.
179 Payload_type *string
180
Huang Jianan13cac632021-08-02 15:02:17 +0800181 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
182 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900183 Payload_fs_type *string
184
185 // For telling the APEX to ignore special handling for system libraries such as bionic.
186 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900187 Ignore_system_library_special_case *bool
188
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100189 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100190 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100191 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900192
193 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
194 // used in tests.
195 Test_only_unsigned_payload *bool
196
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000197 // Whenever apex should be compressed, regardless of product flag used. Should be only
198 // used in tests.
199 Test_only_force_compression *bool
200
Jooyung Han09c11ad2021-10-27 03:45:31 +0900201 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
202 // with the tool to sign payload contents.
203 Custom_sign_tool *string
204
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100205 // Canonical name of this APEX bundle. Used to determine the path to the
206 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
207 // apex mutator variations. For override_apex modules, this is the name of the
208 // overridden base module.
209 ApexVariationName string `blueprint:"mutated"`
210
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900211 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900212
213 // List of sanitizer names that this APEX is enabled for
214 SanitizerNames []string `blueprint:"mutated"`
215
216 PreventInstall bool `blueprint:"mutated"`
217
218 HideFromMake bool `blueprint:"mutated"`
219
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900220 // Internal package method for this APEX. When payload_type is image, this can be either
221 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
222 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900223 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900224}
225
226type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900227 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900228 Native_shared_libs []string
229
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900230 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900231 Jni_libs []string
232
Jiyong Park99644e92020-11-17 22:21:02 +0900233 // List of rust dyn libraries
234 Rust_dyn_libs []string
235
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900236 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900237 Binaries []string
238
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900239 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900240 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900241
242 // List of filesystem images that are embedded inside this APEX bundle.
243 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900244}
245
246type apexMultilibProperties struct {
247 // Native dependencies whose compile_multilib is "first"
248 First ApexNativeDependencies
249
250 // Native dependencies whose compile_multilib is "both"
251 Both ApexNativeDependencies
252
253 // Native dependencies whose compile_multilib is "prefer32"
254 Prefer32 ApexNativeDependencies
255
256 // Native dependencies whose compile_multilib is "32"
257 Lib32 ApexNativeDependencies
258
259 // Native dependencies whose compile_multilib is "64"
260 Lib64 ApexNativeDependencies
261}
262
263type apexTargetBundleProperties struct {
264 Target struct {
265 // Multilib properties only for android.
266 Android struct {
267 Multilib apexMultilibProperties
268 }
269
270 // Multilib properties only for host.
271 Host struct {
272 Multilib apexMultilibProperties
273 }
274
275 // Multilib properties only for host linux_bionic.
276 Linux_bionic struct {
277 Multilib apexMultilibProperties
278 }
279
280 // Multilib properties only for host linux_glibc.
281 Linux_glibc struct {
282 Multilib apexMultilibProperties
283 }
284 }
285}
286
Jiyong Park59140302020-12-14 18:44:04 +0900287type apexArchBundleProperties struct {
288 Arch struct {
289 Arm struct {
290 ApexNativeDependencies
291 }
292 Arm64 struct {
293 ApexNativeDependencies
294 }
295 X86 struct {
296 ApexNativeDependencies
297 }
298 X86_64 struct {
299 ApexNativeDependencies
300 }
301 }
302}
303
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900304// These properties can be used in override_apex to override the corresponding properties in the
305// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900306type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900307 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900308 Apps []string
309
Daniel Norman5a3ce132021-08-26 15:44:43 -0700310 // List of prebuilt files that are embedded inside this APEX bundle.
311 Prebuilts []string
312
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900313 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900314 Rros []string
315
markchien7c803b82021-08-26 22:10:06 +0800316 // List of BPF programs inside this APEX bundle.
317 Bpfs []string
318
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900319 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
320 // Soong). This does not completely prevent installation of the overridden binaries, but if
321 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
322 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900323 Overrides []string
324
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900325 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900326 Logging_parent string
327
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900328 // Apex Container package name. Override value for attribute package:name in
329 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900330 Package_name string
331
332 // A txt file containing list of files that are allowed to be included in this APEX.
333 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700334
335 // Name of the apex_key module that provides the private key to sign this APEX bundle.
336 Key *string
337
338 // Specifies the certificate and the private key to sign the zip container of this APEX. If
339 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
340 // as the certificate and the private key, respectively. If this is ":module", then the
341 // certificate and the private key are provided from the android_app_certificate module
342 // named "module".
343 Certificate *string
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -0400344
345 // Whether this APEX can be compressed or not. Setting this property to false means this
346 // APEX will never be compressed. When set to true, APEX will be compressed if other
347 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
348 // Default: false.
349 Compressible *bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900350}
351
352type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900353 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900354 android.ModuleBase
355 android.DefaultableModuleBase
356 android.OverridableModuleBase
357 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400358 android.BazelModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900359
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900360 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361 properties apexBundleProperties
362 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900363 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900364 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900365 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900366
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900367 ///////////////////////////////////////////////////////////////////////////////////////////
368 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900369
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900370 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800371 publicKeyFile android.Path
372 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900373
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900374 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800375 containerCertificateFile android.Path
376 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900377
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900378 // Flags for special variants of APEX
379 testApex bool
380 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900382 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
383 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900384 primaryApexType bool
385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900386 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900387 suffix string
388
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900389 // File system type of apex_payload.img
390 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900391
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900392 // Whether to create symlink to the system file instead of having a file inside the apex or
393 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900394 linkToSystemLib bool
395
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900396 // List of files to be included in this APEX. This is filled in the first part of
397 // GenerateAndroidBuildActions.
398 filesInfo []apexFile
399
400 // List of other module names that should be installed when this APEX gets installed.
401 requiredDeps []string
402
403 ///////////////////////////////////////////////////////////////////////////////////////////
404 // Outputs (final and intermediates)
405
406 // Processed apex manifest in JSONson format (for Q)
407 manifestJsonOut android.WritablePath
408
409 // Processed apex manifest in PB format (for R+)
410 manifestPbOut android.WritablePath
411
412 // Processed file_contexts files
413 fileContexts android.WritablePath
414
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900415 // Struct holding the merged notice file paths in different formats
416 mergedNotices android.NoticeOutputs
417
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900418 // The built APEX file. This is the main product.
419 outputFile android.WritablePath
420
421 // The built APEX file in app bundle format. This file is not directly installed to the
422 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
423 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
424 // system) to be merged into a single app bundle file that Play accepts. See
425 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
426 bundleModuleFile android.WritablePath
427
Colin Cross6340ea52021-11-04 12:01:18 -0700428 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900429 installDir android.InstallPath
430
Colin Cross6340ea52021-11-04 12:01:18 -0700431 // Path where this APEX was installed.
432 installedFile android.InstallPath
433
434 // Installed locations of symlinks for backward compatibility.
435 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900436
437 // Text file having the list of individual files that are included in this APEX. Used for
438 // debugging purpose.
439 installedFilesFile android.WritablePath
440
441 // List of module names that this APEX is including (to be shown via *-deps-info target).
442 // Used for debugging purpose.
443 android.ApexBundleDepsInfo
444
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900445 // Optional list of lint report zip files for apexes that contain java or app modules
446 lintReports android.Paths
447
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900448 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000449
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000450 isCompressed bool
451
sophiezc80a2b32020-11-12 16:39:19 +0000452 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700453 nativeApisUsedByModuleFile android.ModuleOutPath
454 nativeApisBackedByModuleFile android.ModuleOutPath
455 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800456
457 // Collect the module directory for IDE info in java/jdeps.go.
458 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900459}
460
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900461// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900462type apexFileClass int
463
Jooyung Han72bd2f82019-10-23 16:46:38 +0900464const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900465 app apexFileClass = iota
466 appSet
467 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900468 goBinary
469 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900470 nativeExecutable
471 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900472 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900473 pyBinary
474 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900475)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900476
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900477// apexFile represents a file in an APEX bundle. This is created during the first half of
478// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
479// of the function, this is used to create commands that copies the files into a staging directory,
480// where they are packaged into the APEX file. This struct is also used for creating Make modules
481// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900482type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900483 // buildFile is put in the installDir inside the APEX.
484 builtFile android.Path
485 noticeFiles android.Paths
486 installDir string
487 customStem string
488 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900489
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900490 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
491 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
492 // suffix>]
493 androidMkModuleName string // becomes LOCAL_MODULE
494 class apexFileClass // becomes LOCAL_MODULE_CLASS
495 moduleDir string // becomes LOCAL_PATH
496 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
497 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
498 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
499 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900500
501 jacocoReportClassesFile android.Path // only for javalibs and apps
502 lintDepSets java.LintDepSets // only for javalibs and apps
503 certificate java.Certificate // only for apps
504 overriddenPackageName string // only for apps
505
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900506 transitiveDep bool
507 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900508
Jiyong Park57621b22021-01-20 20:33:11 +0900509 multilib string
510
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900511 // TODO(jiyong): remove this
512 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900513}
514
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900515// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900516func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
517 ret := apexFile{
518 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900519 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900520 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521 class: class,
522 module: module,
523 }
524 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900525 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900526 ret.moduleDir = ctx.OtherModuleDir(module)
527 ret.requiredModuleNames = module.RequiredModuleNames()
528 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
529 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900530 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900531 }
532 return ret
533}
534
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900535func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900536 return af.builtFile != nil && af.builtFile.String() != ""
537}
538
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900539// apexRelativePath returns the relative path of the given path from the install directory of this
540// apexFile.
541// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900542func (af *apexFile) apexRelativePath(path string) string {
543 return filepath.Join(af.installDir, path)
544}
545
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900546// path returns path of this apex file relative to the APEX root
547func (af *apexFile) path() string {
548 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900549}
550
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900551// stem returns the base filename of this apex file
552func (af *apexFile) stem() string {
553 if af.customStem != "" {
554 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900555 }
556 return af.builtFile.Base()
557}
558
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900559// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
560func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900561 var ret []string
562 for _, symlink := range af.symlinks {
563 ret = append(ret, af.apexRelativePath(symlink))
564 }
565 return ret
566}
567
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900568// availableToPlatform tests whether this apexFile is from a module that can be installed to the
569// platform.
570func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900571 if af.module == nil {
572 return false
573 }
574 if am, ok := af.module.(android.ApexModule); ok {
575 return am.AvailableFor(android.AvailableToPlatform)
576 }
577 return false
578}
579
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900580////////////////////////////////////////////////////////////////////////////////////////////////////
581// Mutators
582//
583// Brief description about mutators for APEX. The following three mutators are the most important
584// ones.
585//
586// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
587// to the (direct) dependencies of this APEX bundle.
588//
Paul Duffin949abc02020-12-08 10:34:30 +0000589// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900590// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
591// modules are marked as being included in the APEX via BuildForApex().
592//
Paul Duffin949abc02020-12-08 10:34:30 +0000593// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
594// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900595
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900596type dependencyTag struct {
597 blueprint.BaseDependencyTag
598 name string
599
600 // Determines if the dependent will be part of the APEX payload. Can be false for the
601 // dependencies to the signing key module, etc.
602 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000603
604 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
605 // replacement. This is needed because some prebuilt modules do not provide all the information
606 // needed by the apex.
607 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900608}
609
Paul Duffin8c535da2021-03-17 14:51:03 +0000610func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
611 return !d.sourceOnly
612}
613
614var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
615
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900616var (
Paul Duffin0b817782021-03-17 15:02:19 +0000617 androidAppTag = dependencyTag{name: "androidApp", payload: true}
618 bpfTag = dependencyTag{name: "bpf", payload: true}
619 certificateTag = dependencyTag{name: "certificate"}
620 executableTag = dependencyTag{name: "executable", payload: true}
621 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100622 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100623 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000624 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000625 javaLibTag = dependencyTag{name: "javaLib", payload: true}
626 jniLibTag = dependencyTag{name: "jniLib", payload: true}
627 keyTag = dependencyTag{name: "key"}
628 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
629 rroTag = dependencyTag{name: "rro", payload: true}
630 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
631 testForTag = dependencyTag{name: "test for"}
632 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000633 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900634)
635
636// TODO(jiyong): shorten this function signature
637func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900638 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900639 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900640 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900641
642 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900643 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900644 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
645 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900646 }
647
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900648 // Use *FarVariation* to be able to depend on modules having conflicting variations with
649 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
650 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900651 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900653 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
654 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900655 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900656 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900657}
658
659func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900660 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900661 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
662 } else {
663 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
664 if ctx.Os().Bionic() {
665 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
666 } else {
667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
668 }
669 }
670}
671
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900672// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
673// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
674func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
675 deviceConfig := ctx.DeviceConfig()
676 if a.vndkApex {
677 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900678 }
679
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900680 var prefix string
681 var vndkVersion string
682 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000683 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900684 prefix = cc.VendorVariationPrefix
685 vndkVersion = deviceConfig.VndkVersion()
686 } else if a.ProductSpecific() {
687 prefix = cc.ProductVariationPrefix
688 vndkVersion = deviceConfig.ProductVndkVersion()
689 }
690 }
691 if vndkVersion == "current" {
692 vndkVersion = deviceConfig.PlatformVndkVersion()
693 }
694 if vndkVersion != "" {
695 return prefix + vndkVersion
696 }
697
698 return android.CoreVariation // The usual case
699}
700
701func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900702 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
703 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
704 // each target os/architectures, appropriate dependencies are selected by their
705 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900706 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900707 imageVariation := a.getImageVariation(ctx)
708
709 a.combineProperties(ctx)
710
711 has32BitTarget := false
712 for _, target := range targets {
713 if target.Arch.ArchType.Multilib == "lib32" {
714 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000715 }
716 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900717 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900718 // Don't include artifacts for the host cross targets because there is no way for us
719 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900720 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900721 continue
722 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000723
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900724 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000725
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900726 // Add native modules targeting both ABIs. When multilib.* is omitted for
727 // native_shared_libs/jni_libs/tests, it implies multilib.both
728 depsList = append(depsList, a.properties.Multilib.Both)
729 depsList = append(depsList, ApexNativeDependencies{
730 Native_shared_libs: a.properties.Native_shared_libs,
731 Tests: a.properties.Tests,
732 Jni_libs: a.properties.Jni_libs,
733 Binaries: nil,
734 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900735
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900736 // Add native modules targeting the first ABI When multilib.* is omitted for
737 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900738 isPrimaryAbi := i == 0
739 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900740 depsList = append(depsList, a.properties.Multilib.First)
741 depsList = append(depsList, ApexNativeDependencies{
742 Native_shared_libs: nil,
743 Tests: nil,
744 Jni_libs: nil,
745 Binaries: a.properties.Binaries,
746 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900747 }
748
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900749 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900750 switch target.Arch.ArchType.Multilib {
751 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900752 depsList = append(depsList, a.properties.Multilib.Lib32)
753 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900754 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900755 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900756 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900757 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900758 }
759 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900760
Jiyong Park59140302020-12-14 18:44:04 +0900761 // Add native modules targeting a specific arch variant
762 switch target.Arch.ArchType {
763 case android.Arm:
764 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
765 case android.Arm64:
766 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
767 case android.X86:
768 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
769 case android.X86_64:
770 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
771 default:
772 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
773 }
774
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900775 for _, d := range depsList {
776 addDependenciesForNativeModules(ctx, d, target, imageVariation)
777 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000778 ctx.AddFarVariationDependencies([]blueprint.Variation{
779 {Mutator: "os", Variation: target.OsVariation()},
780 {Mutator: "arch", Variation: target.ArchVariation()},
781 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900782 }
783
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900784 // Common-arch dependencies come next
785 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100786 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100787 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900788 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900789 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000790 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900791
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900792 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
793 // This field currently isn't used.
794 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900795 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
796 if len(a.properties.Uses_sdks) > 0 {
797 sdkRefs := []android.SdkRef{}
798 for _, str := range a.properties.Uses_sdks {
799 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
800 sdkRefs = append(sdkRefs, parsed)
801 }
802 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100803 }
804}
805
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900806// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900807func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
808 if a.overridableProperties.Allowed_files != nil {
809 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100810 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900811
812 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
813 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800814 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900815 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700816 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
817 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
818 // regardless of the TARGET_PREFER_* setting. See b/144532908
819 arches := ctx.DeviceConfig().Arches()
820 if len(arches) != 0 {
821 archForPrebuiltEtc := arches[0]
822 for _, arch := range arches {
823 // Prefer 64-bit arch if there is any
824 if arch.ArchType.Multilib == "lib64" {
825 archForPrebuiltEtc = arch
826 break
827 }
828 }
829 ctx.AddFarVariationDependencies([]blueprint.Variation{
830 {Mutator: "os", Variation: ctx.Os().String()},
831 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
832 }, prebuiltTag, prebuilts...)
833 }
834 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700835
836 // Dependencies for signing
837 if String(a.overridableProperties.Key) == "" {
838 ctx.PropertyErrorf("key", "missing")
839 return
840 }
841 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
842
843 cert := android.SrcIsModule(a.getCertString(ctx))
844 if cert != "" {
845 ctx.AddDependency(ctx.Module(), certificateTag, cert)
846 // empty cert is not an error. Cert and private keys will be directly found under
847 // PRODUCT_DEFAULT_DEV_CERTIFICATE
848 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100849}
850
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900851type ApexBundleInfo struct {
852 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100853}
854
Paul Duffin949abc02020-12-08 10:34:30 +0000855var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900856
Paul Duffina7d6a892020-12-07 17:39:59 +0000857var _ ApexInfoMutator = (*apexBundle)(nil)
858
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100859func (a *apexBundle) ApexVariationName() string {
860 return a.properties.ApexVariationName
861}
862
Paul Duffina7d6a892020-12-07 17:39:59 +0000863// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900864// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
865// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
866// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
867// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000868//
869// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
870// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
871// The apexMutator uses that list to create module variants for the apexes to which it belongs.
872// The relationship between module variants and apexes is not one-to-one as variants will be
873// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000874func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900875
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900876 // The VNDK APEX is special. For the APEX, the membership is described in a very different
877 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
878 // libraries are self-identified by their vndk.enabled properties. There is no need to run
879 // this mutator for the APEX as nothing will be collected. So, let's return fast.
880 if a.vndkApex {
881 return
882 }
883
884 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
885 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
886 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
887 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
888 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900889 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
890 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900891 if proptools.Bool(a.properties.Use_vndk_as_stable) {
892 if !useVndk {
893 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
894 }
895 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
896 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
897 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
898 }
899 })
900 if mctx.Failed() {
901 return
902 }
Jooyung Handf78e212020-07-22 15:54:47 +0900903 }
904
Colin Cross56a83212020-09-15 18:30:11 -0700905 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900906 am, ok := child.(android.ApexModule)
907 if !ok || !am.CanHaveApexVariants() {
908 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900909 }
Paul Duffin573989d2021-03-17 13:25:29 +0000910 depTag := mctx.OtherModuleDependencyTag(child)
911
912 // Check to see if the tag always requires that the child module has an apex variant for every
913 // apex variant of the parent module. If it does not then it is still possible for something
914 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
915 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
916 return true
917 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000918 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900919 return false
920 }
Jooyung Handf78e212020-07-22 15:54:47 +0900921 if excludeVndkLibs {
922 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
923 return false
924 }
925 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900926 // By default, all the transitive dependencies are collected, unless filtered out
927 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700928 return true
929 }
930
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900931 // Records whether a certain module is included in this apexBundle via direct dependency or
932 // inndirect dependency.
933 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700934 mctx.WalkDeps(func(child, parent android.Module) bool {
935 if !continueApexDepsWalk(child, parent) {
936 return false
937 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900938 // If the parent is apexBundle, this child is directly depended.
939 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900940 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700941 contents[depName] = contents[depName].Add(directDep)
942 return true
943 })
944
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900945 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900946 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700947 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
948 Contents: apexContents,
949 })
950
Jooyung Haned124c32021-01-26 11:43:46 +0900951 minSdkVersion := a.minSdkVersion(mctx)
952 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
953 if minSdkVersion.IsNone() {
954 minSdkVersion = android.FutureApiLevel
955 }
956
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900957 // This is the main part of this mutator. Mark the collected dependencies that they need to
958 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900959
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100960 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
961 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700962 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100963 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900964 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700965 RequiredSdks: a.RequiredSdks(),
966 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900967 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100968 InApexVariants: []string{apexVariationName},
969 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700970 ApexContents: []*android.ApexContents{apexContents},
971 }
Colin Cross56a83212020-09-15 18:30:11 -0700972 mctx.WalkDeps(func(child, parent android.Module) bool {
973 if !continueApexDepsWalk(child, parent) {
974 return false
975 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900976 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900977 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900978 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900979}
980
Paul Duffina7d6a892020-12-07 17:39:59 +0000981type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100982 // ApexVariationName returns the name of the APEX variation to use in the apex
983 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
984 ApexVariationName() string
985
Paul Duffina7d6a892020-12-07 17:39:59 +0000986 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
987 // depended upon by an apex and which require an apex specific variant.
988 ApexInfoMutator(android.TopDownMutatorContext)
989}
990
991// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
992// specific variant to modules that support the ApexInfoMutator.
993func apexInfoMutator(mctx android.TopDownMutatorContext) {
994 if !mctx.Module().Enabled() {
995 return
996 }
997
998 if a, ok := mctx.Module().(ApexInfoMutator); ok {
999 a.ApexInfoMutator(mctx)
1000 return
1001 }
1002}
1003
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001004// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1005// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1006// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001007func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1008 if !mctx.Module().Enabled() {
1009 return
1010 }
1011 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001012 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1013 }
1014}
1015
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001016// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1017// the apex in order to retrieve its contents later.
1018// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001019func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1020 if !mctx.Module().Enabled() {
1021 return
1022 }
Colin Cross56a83212020-09-15 18:30:11 -07001023 if am, ok := mctx.Module().(android.ApexModule); ok {
1024 if testFor := am.TestFor(); len(testFor) > 0 {
1025 mctx.AddFarVariationDependencies([]blueprint.Variation{
1026 {Mutator: "os", Variation: am.Target().OsVariation()},
1027 {"arch", "common"},
1028 }, testForTag, testFor...)
1029 }
1030 }
1031}
1032
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001033// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001034func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1035 if !mctx.Module().Enabled() {
1036 return
1037 }
Colin Cross56a83212020-09-15 18:30:11 -07001038 if _, ok := mctx.Module().(android.ApexModule); ok {
1039 var contents []*android.ApexContents
1040 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1041 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1042 contents = append(contents, abInfo.Contents)
1043 }
1044 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1045 ApexContents: contents,
1046 })
Colin Crossaede88c2020-08-11 12:17:01 -07001047 }
1048}
1049
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001050// markPlatformAvailability marks whether or not a module can be available to platform. A module
1051// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1052// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1053// be) available to platform
1054// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001055func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1056 // Host and recovery are not considered as platform
1057 if mctx.Host() || mctx.Module().InstallInRecovery() {
1058 return
1059 }
1060
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001061 am, ok := mctx.Module().(android.ApexModule)
1062 if !ok {
1063 return
1064 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001065
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001066 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001067
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001068 // If any of the dep is not available to platform, this module is also considered as being
1069 // not available to platform even if it has "//apex_available:platform"
1070 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001071 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001072 // if the dependency crosses apex boundary, don't consider it
1073 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001074 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001075 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1076 availableToPlatform = false
1077 // TODO(b/154889534) trigger an error when 'am' has
1078 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001079 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001080 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001081
Paul Duffinb5769c12021-05-12 16:16:51 +01001082 // Exception 1: check to see if the module always requires it.
1083 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001084 availableToPlatform = true
1085 }
1086
1087 // Exception 2: bootstrap bionic libraries are also always available to platform
1088 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1089 availableToPlatform = true
1090 }
1091
1092 if !availableToPlatform {
1093 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001094 }
1095}
1096
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001097// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001098// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001099func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001100 if !mctx.Module().Enabled() {
1101 return
1102 }
Colin Cross56a83212020-09-15 18:30:11 -07001103
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001104 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001105 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001106 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001107 return
1108 }
1109
1110 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001111 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1112 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001113 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001114 if strings.HasPrefix(apexBundleName, "com.android.art") {
1115 // Create an alias from the platform variant. This is done to make
1116 // test_for dependencies work for modules that are split by the APEX
1117 // mutator, since test_for dependencies always go to the platform variant.
1118 // This doesn't happen for normal APEXes that are disjunct, so only do
1119 // this for the overlapping ART APEXes.
1120 // TODO(b/183882457): Remove this if the test_for functionality is
1121 // refactored to depend on the proper APEX variants instead of platform.
1122 mctx.CreateAliasVariation("", apexBundleName)
1123 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001124 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1125 apexBundleName := o.GetOverriddenModuleName()
1126 if apexBundleName == "" {
1127 mctx.ModuleErrorf("base property is not set")
1128 return
1129 }
1130 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001131 if strings.HasPrefix(apexBundleName, "com.android.art") {
1132 // TODO(b/183882457): See note for CreateAliasVariation above.
1133 mctx.CreateAliasVariation("", apexBundleName)
1134 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001135 }
1136}
Sundong Ahne9b55722019-09-06 17:37:42 +09001137
Paul Duffin6717d882021-06-15 19:09:41 +01001138// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1139// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001140func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001141 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001142 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001143 return !a.vndkApex
1144 }
1145
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001146 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001147}
1148
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001149// See android.UpdateDirectlyInAnyApex
1150// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001151func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1152 if !mctx.Module().Enabled() {
1153 return
1154 }
1155 if am, ok := mctx.Module().(android.ApexModule); ok {
1156 android.UpdateDirectlyInAnyApex(mctx, am)
1157 }
1158}
1159
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001160// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001161type apexPackaging int
1162
1163const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001164 // imageApex is a packaging method where contents are included in a filesystem image which
1165 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001166 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001167
1168 // zipApex is a packaging method where contents are directly included in the zip container.
1169 // This is used for host-side testing - because the contents are easily accessible by
1170 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001171 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001172
1173 // flattendApex is a packaging method where contents are not included in the APEX file, but
1174 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1175 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001176 flattenedApex
1177)
1178
1179const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001180 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001181 imageApexSuffix = ".apex"
1182 imageCapexSuffix = ".capex"
1183 zipApexSuffix = ".zipapex"
1184 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001185
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001186 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001187 imageApexType = "image"
1188 zipApexType = "zip"
1189 flattenedApexType = "flattened"
1190
Dan Willemsen47e1a752021-10-16 18:36:13 -07001191 ext4FsType = "ext4"
1192 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001193 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001194)
1195
1196// The suffix for the output "file", not the module
1197func (a apexPackaging) suffix() string {
1198 switch a {
1199 case imageApex:
1200 return imageApexSuffix
1201 case zipApex:
1202 return zipApexSuffix
1203 default:
1204 panic(fmt.Errorf("unknown APEX type %d", a))
1205 }
1206}
1207
1208func (a apexPackaging) name() string {
1209 switch a {
1210 case imageApex:
1211 return imageApexType
1212 case zipApex:
1213 return zipApexType
1214 default:
1215 panic(fmt.Errorf("unknown APEX type %d", a))
1216 }
1217}
1218
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001219// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1220// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001221func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001222 if !mctx.Module().Enabled() {
1223 return
1224 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001225 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001226 var variants []string
1227 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1228 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001229 // This is the normal case. Note that both image and flattend APEXes are
1230 // created. The image type is installed to the system partition, while the
1231 // flattened APEX is (optionally) installed to the system_ext partition.
1232 // This is mostly for GSI which has to support wide range of devices. If GSI
1233 // is installed on a newer (APEX-capable) device, the image APEX in the
1234 // system will be used. However, if the same GSI is installed on an old
1235 // device which can't support image APEX, the flattened APEX in the
1236 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001237 variants = append(variants, imageApexType, flattenedApexType)
1238 case "zip":
1239 variants = append(variants, zipApexType)
1240 case "both":
1241 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1242 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001243 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001244 return
1245 }
1246
1247 modules := mctx.CreateLocalVariations(variants...)
1248
1249 for i, v := range variants {
1250 switch v {
1251 case imageApexType:
1252 modules[i].(*apexBundle).properties.ApexType = imageApex
1253 case zipApexType:
1254 modules[i].(*apexBundle).properties.ApexType = zipApex
1255 case flattenedApexType:
1256 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001257 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001258 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001259 modules[i].(*apexBundle).MakeAsSystemExt()
1260 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001261 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001262 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001263 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001264 // payload_type is forcibly overridden to "image"
1265 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001266 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001267 }
1268}
1269
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001270var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001271
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001272// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001273func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1274 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001275 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001276 return true
1277}
1278
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001279var _ android.OutputFileProducer = (*apexBundle)(nil)
1280
1281// Implements android.OutputFileProducer
1282func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1283 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001284 case "", android.DefaultDistTag:
1285 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001286 return android.Paths{a.outputFile}, nil
1287 default:
1288 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1289 }
1290}
1291
1292var _ cc.Coverage = (*apexBundle)(nil)
1293
1294// Implements cc.Coverage
1295func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1296 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1297}
1298
1299// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001300func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001301 a.properties.PreventInstall = true
1302}
1303
1304// Implements cc.Coverage
1305func (a *apexBundle) HideFromMake() {
1306 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001307 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1308 // TODO(ccross): untangle these
1309 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001310}
1311
1312// Implements cc.Coverage
1313func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1314 a.properties.IsCoverageVariant = coverage
1315}
1316
1317// Implements cc.Coverage
1318func (a *apexBundle) EnableCoverageIfNeeded() {}
1319
1320var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1321
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001322// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001323func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001324 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001325}
1326
Jiyong Parkf4020582021-11-29 12:37:10 +09001327func (a *apexBundle) FutureUpdatable() bool {
1328 return proptools.BoolDefault(a.properties.Future_updatable, false)
1329}
1330
Jiyong Park1bc84122021-06-22 20:23:05 +09001331func (a *apexBundle) UsePlatformApis() bool {
1332 return proptools.BoolDefault(a.properties.Platform_apis, false)
1333}
1334
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001335// getCertString returns the name of the cert that should be used to sign this APEX. This is
1336// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001337func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001338 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001339 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1340 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1341 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001342 if a.vndkApex {
1343 moduleName = vndkApexName
1344 }
1345 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001346 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001347 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001348 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001349 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001350}
1351
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001352// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001353func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001354 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001355}
1356
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001357// See the generate_hashtree property
1358func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001359 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001360}
1361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001362// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001363func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1364 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1365}
1366
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001367// See the test_only_force_compression property
1368func (a *apexBundle) testOnlyShouldForceCompression() bool {
1369 return proptools.Bool(a.properties.Test_only_force_compression)
1370}
1371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001372// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1373// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1374// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001375
Jiyong Parkf97782b2019-02-13 20:28:58 +09001376func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1377 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1378 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1379 }
1380}
1381
Jiyong Park388ef3f2019-01-28 19:47:32 +09001382func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001383 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1384 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001385 }
1386
1387 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001388 globalSanitizerNames := []string{}
1389 if a.Host() {
1390 globalSanitizerNames = ctx.Config().SanitizeHost()
1391 } else {
1392 arches := ctx.Config().SanitizeDeviceArch()
1393 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1394 globalSanitizerNames = ctx.Config().SanitizeDevice()
1395 }
1396 }
1397 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001398}
1399
Jooyung Han8ce8db92020-05-15 19:05:05 +09001400func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001401 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1402 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001403 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001404 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001405 for _, target := range ctx.MultiTargets() {
1406 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001407 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1408 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1409 Tests: nil,
1410 Jni_libs: nil,
1411 Binaries: nil,
1412 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001413 break
1414 }
1415 }
1416 }
1417}
1418
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001419// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1420// returned apexFile saves information about the Soong module that will be used for creating the
1421// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001422func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001423 // Decide the APEX-local directory by the multilib of the library In the future, we may
1424 // query this to the module.
1425 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001426 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001427 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001428 case "lib32":
1429 dirInApex = "lib"
1430 case "lib64":
1431 dirInApex = "lib64"
1432 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001433 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001434 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001435 }
Jooyung Han35155c42020-02-06 17:33:20 +09001436 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001437 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001438 // Special case for Bionic libs and other libs installed with them. This is to
1439 // prevent those libs from being included in the search path
1440 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1441 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1442 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1443 // will be loaded into the default linker namespace (aka "platform" namespace). If
1444 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1445 // be loaded again into the runtime linker namespace, which will result in double
1446 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001447 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001448 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001449
Jiyong Parkf653b052019-11-18 15:39:01 +09001450 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001451 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1452 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001453}
1454
Jiyong Park1833cef2019-12-13 13:28:36 +09001455func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001456 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001457 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001458 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001459 }
Jooyung Han35155c42020-02-06 17:33:20 +09001460 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001461 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001462 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1463 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001464 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001465 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001466 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001467}
1468
Jiyong Park99644e92020-11-17 22:21:02 +09001469func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1470 dirInApex := "bin"
1471 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1472 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1473 }
1474 fileToCopy := rustm.OutputFile().Path()
1475 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1476 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1477 return af
1478}
1479
1480func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1481 // Decide the APEX-local directory by the multilib of the library
1482 // In the future, we may query this to the module.
1483 var dirInApex string
1484 switch rustm.Arch().ArchType.Multilib {
1485 case "lib32":
1486 dirInApex = "lib"
1487 case "lib64":
1488 dirInApex = "lib64"
1489 }
1490 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1491 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1492 }
1493 fileToCopy := rustm.OutputFile().Path()
1494 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1495 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1496}
1497
Jiyong Park1833cef2019-12-13 13:28:36 +09001498func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001499 dirInApex := "bin"
1500 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001501 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001502}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001503
Jiyong Park1833cef2019-12-13 13:28:36 +09001504func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001505 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001506 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001507 // NB: Since go binaries are static we don't need the module for anything here, which is
1508 // good since the go tool is a blueprint.Module not an android.Module like we would
1509 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001510 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001511}
1512
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001513func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001514 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001515 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1516 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1517 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001518 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001519 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001520 af.symlinks = sh.Symlinks()
1521 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001522}
1523
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001524func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001525 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001526 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001527 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001528}
1529
atrost6e126252020-01-27 17:01:16 +00001530func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1531 dirInApex := filepath.Join("etc", config.SubDir())
1532 fileToCopy := config.CompatConfig()
1533 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1534}
1535
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001536// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1537// way.
1538type javaModule interface {
1539 android.Module
1540 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001541 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001542 JacocoReportClassesFile() android.Path
1543 LintDepSets() java.LintDepSets
1544 Stem() string
1545}
1546
1547var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001548var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001549var _ javaModule = (*java.SdkLibrary)(nil)
1550var _ javaModule = (*java.DexImport)(nil)
1551var _ javaModule = (*java.SdkLibraryImport)(nil)
1552
Paul Duffin190fdef2021-04-26 10:33:59 +01001553// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001554func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001555 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001556}
1557
1558// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1559func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001560 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001561 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001562 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1563 af.lintDepSets = module.LintDepSets()
1564 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001565 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1566 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1567 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1568 }
1569 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001570 return af
1571}
1572
1573// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1574// the same way.
1575type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001576 android.Module
1577 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001578 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001579 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001580 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001581 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001582 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001583 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001584}
1585
1586var _ androidApp = (*java.AndroidApp)(nil)
1587var _ androidApp = (*java.AndroidAppImport)(nil)
1588
1589func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001590 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001591 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001592 appDir = "priv-app"
1593 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001594 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001595 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001596 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001597 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001598 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001599 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001600
1601 if app, ok := aapp.(interface {
1602 OverriddenManifestPackageName() string
1603 }); ok {
1604 af.overriddenPackageName = app.OverriddenManifestPackageName()
1605 }
Jiyong Park618922e2020-01-08 13:35:43 +09001606 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001607}
1608
Jiyong Park69aeba92020-04-24 21:16:36 +09001609func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1610 rroDir := "overlay"
1611 dirInApex := filepath.Join(rroDir, rro.Theme())
1612 fileToCopy := rro.OutputFile()
1613 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1614 af.certificate = rro.Certificate()
1615
1616 if a, ok := rro.(interface {
1617 OverriddenManifestPackageName() string
1618 }); ok {
1619 af.overriddenPackageName = a.OverriddenManifestPackageName()
1620 }
1621 return af
1622}
1623
Ken Chenfad7f9d2021-11-10 22:02:57 +08001624func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1625 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001626 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1627}
1628
Jiyong Park12a719c2021-01-07 15:31:24 +09001629func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1630 dirInApex := filepath.Join("etc", "fs")
1631 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1632}
1633
Paul Duffin064b70c2020-11-02 17:32:38 +00001634// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001635// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1636// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1637// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001638func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001639 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001640 am, ok := child.(android.ApexModule)
1641 if !ok || !am.CanHaveApexVariants() {
1642 return false
1643 }
1644
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001645 // Filter-out unwanted depedendencies
1646 depTag := ctx.OtherModuleDependencyTag(child)
1647 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1648 return false
1649 }
1650 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001651 return false
1652 }
1653
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001654 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001655 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001656
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001657 // Visit actually
1658 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001659 })
1660}
1661
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001662// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1663type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001664
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001665const (
1666 ext4 fsType = iota
1667 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001668 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001669)
Artur Satayev849f8442020-04-28 14:57:42 +01001670
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001671func (f fsType) string() string {
1672 switch f {
1673 case ext4:
1674 return ext4FsType
1675 case f2fs:
1676 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001677 case erofs:
1678 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001679 default:
1680 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001681 }
1682}
1683
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001684// Creates build rules for an APEX. It consists of the following major steps:
1685//
1686// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1687// 2) traverse the dependency tree to collect apexFile structs from them.
1688// 3) some fields in apexBundle struct are configured
1689// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001690func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001691 ////////////////////////////////////////////////////////////////////////////////////////////
1692 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001693 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001694 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001695 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001696 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001697 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001698 if len(a.properties.Tests) > 0 && !a.testApex {
1699 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1700 return
1701 }
Jiyong Park678c8812020-02-07 17:25:49 +09001702
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001703 ////////////////////////////////////////////////////////////////////////////////////////////
1704 // 2) traverse the dependency tree to collect apexFile structs from them.
1705
1706 // all the files that will be included in this APEX
1707 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001708
Jooyung Hane1633032019-08-01 17:41:43 +09001709 // native lib dependencies
1710 var provideNativeLibs []string
1711 var requireNativeLibs []string
1712
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001713 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1714
braleeb0c1f0c2021-06-07 22:49:13 +08001715 // Collect the module directory for IDE info in java/jdeps.go.
1716 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1717
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001718 // TODO(jiyong): do this using WalkPayloadDeps
1719 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001720 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001721 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001722 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1723 return false
1724 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001725 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1726 return false
1727 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001728 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001729 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001730 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001731 case sharedLibTag, jniLibTag:
1732 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001733 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001734 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1735 fi.isJniLib = isJniLib
1736 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001737 // Collect the list of stub-providing libs except:
1738 // - VNDK libs are only for vendors
1739 // - bootstrap bionic libs are treated as provided by system
1740 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001741 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001742 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001743 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001744 } else if r, ok := child.(*rust.Module); ok {
1745 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001746 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001747 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001748 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001749 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001750 propertyName := "native_shared_libs"
1751 if isJniLib {
1752 propertyName = "jni_libs"
1753 }
1754 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001755 }
1756 case executableTag:
1757 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001758 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001759 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001760 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001761 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001762 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001763 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001764 } else if rust, ok := child.(*rust.Module); ok {
1765 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1766 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001767 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001768 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1769 }
1770 case shBinaryTag:
1771 if sh, ok := child.(*sh.ShBinary); ok {
1772 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1773 } else {
1774 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001775 }
Paul Duffin94f19632021-04-20 12:40:07 +01001776 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001777 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001778 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1779 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001780 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001781 return false
1782 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001783
Paul Duffincc33ec82021-04-25 23:14:55 +01001784 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1785 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001786 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1787 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1788 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001789 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001790 }
satayev333a1732021-05-17 21:35:26 +01001791 case sscpfTag:
1792 {
1793 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1794 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1795 return false
1796 }
satayevb98371c2021-06-15 16:49:50 +01001797 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1798 filesInfo = append(filesInfo, *af)
1799 }
satayev333a1732021-05-17 21:35:26 +01001800 return true
1801 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001802 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001803 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001804 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001805 af := apexFileForJavaModule(ctx, child.(javaModule))
1806 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001807 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1808 return false
1809 }
1810 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001811 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001812 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001813 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001814 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001815 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001816 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001817 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001818 return true // track transitive dependencies
1819 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001820 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001821 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001822 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001823 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1824 appDir := "app"
1825 if ap.Privileged() {
1826 appDir = "priv-app"
1827 }
Yo Chiange8128052020-07-23 20:09:18 +08001828 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001829 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1830 af.certificate = java.PresignedCertificate
1831 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001832 } else {
1833 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1834 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001835 case rroTag:
1836 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1837 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1838 } else {
1839 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1840 }
markchien2f59ec92020-09-02 16:23:38 +08001841 case bpfTag:
1842 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1843 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001844 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001845 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001846 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001847 }
1848 } else {
1849 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1850 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001851 case fsTag:
1852 if fs, ok := child.(filesystem.Filesystem); ok {
1853 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1854 } else {
1855 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1856 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001857 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001858 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001859 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001860 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001861 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001862 }
Paul Duffin0b817782021-03-17 15:02:19 +00001863 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001864 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1865 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1866 } else {
1867 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1868 }
Roland Levillain630846d2019-06-26 12:48:34 +01001869 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001870 if ccTest, ok := child.(*cc.Module); ok {
1871 if ccTest.IsTestPerSrcAllTestsVariation() {
1872 // Multiple-output test module (where `test_per_src: true`).
1873 //
1874 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1875 // We do not add this variation to `filesInfo`, as it has no output;
1876 // however, we do add the other variations of this module as indirect
1877 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001878 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001879 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001880 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001881 af.class = nativeTest
1882 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001883 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001884 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001885 } else {
1886 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1887 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001888 case keyTag:
1889 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001890 a.privateKeyFile = key.privateKeyFile
1891 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001892 } else {
1893 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001894 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001895 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001896 case certificateTag:
1897 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001898 a.containerCertificateFile = dep.Certificate.Pem
1899 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001900 } else {
1901 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1902 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001903 case android.PrebuiltDepTag:
1904 // If the prebuilt is force disabled, remember to delete the prebuilt file
1905 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001906 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001907 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1908 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001909 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001910 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001911 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001912 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001913 // We cannot use a switch statement on `depTag` here as the checked
1914 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001915 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001916 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001917 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001918 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001919 return false
1920 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001921 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1922 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001923
1924 // Always track transitive dependencies for host.
1925 if a.Host() {
1926 filesInfo = append(filesInfo, af)
1927 return true
1928 }
1929
Colin Cross56a83212020-09-15 18:30:11 -07001930 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001931 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001932 // If the dependency is a stubs lib, don't include it in this APEX,
1933 // but make sure that the lib is installed on the device.
1934 // In case no APEX is having the lib, the lib is installed to the system
1935 // partition.
1936 //
1937 // Always include if we are a host-apex however since those won't have any
1938 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001939 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001940 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001941 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001942 if !android.InList(name, a.requiredDeps) {
1943 a.requiredDeps = append(a.requiredDeps, name)
1944 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001945 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001946 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001947 // Don't track further
1948 return false
1949 }
Jiyong Parke3867542020-12-03 17:28:25 +09001950
1951 // If the dep is not considered to be in the same
1952 // apex, don't add it to filesInfo so that it is not
1953 // included in this APEX.
1954 // TODO(jiyong): move this to at the top of the
1955 // else-if clause for the indirect dependencies.
1956 // Currently, that's impossible because we would
1957 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001958 // DepIsInSameAPex is false. We also shouldn't do
1959 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001960 //
1961 // TODO(jiyong): explain why the same module is passed in twice.
1962 // Switching the first am to parent breaks lots of tests.
1963 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001964 return false
1965 }
1966
Jiyong Parkf653b052019-11-18 15:39:01 +09001967 filesInfo = append(filesInfo, af)
1968 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001969 } else if rm, ok := child.(*rust.Module); ok {
1970 af := apexFileForRustLibrary(ctx, rm)
1971 af.transitiveDep = true
1972 filesInfo = append(filesInfo, af)
1973 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001974 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001975 } else if cc.IsTestPerSrcDepTag(depTag) {
1976 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001977 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001978 // Handle modules created as `test_per_src` variations of a single test module:
1979 // use the name of the generated test binary (`fileToCopy`) instead of the name
1980 // of the original test module (`depName`, shared by all `test_per_src`
1981 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001982 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001983 // these are not considered transitive dep
1984 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001985 filesInfo = append(filesInfo, af)
1986 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001987 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001988 } else if cc.IsHeaderDepTag(depTag) {
1989 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001990 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001991 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1992 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001993 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001994 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001995 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1996 }
Jiyong Park99644e92020-11-17 22:21:02 +09001997 } else if rust.IsDylibDepTag(depTag) {
1998 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1999 af := apexFileForRustLibrary(ctx, rustm)
2000 af.transitiveDep = true
2001 filesInfo = append(filesInfo, af)
2002 return true // track transitive dependencies
2003 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002004 } else if rust.IsRlibDepTag(depTag) {
2005 // Rlib is statically linked, but it might have shared lib
2006 // dependencies. Track them.
2007 return true
Paul Duffin65898052021-04-20 22:47:03 +01002008 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002009 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002010 switch child.(type) {
2011 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002012 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002013 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002014 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002015 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002016 return false
2017 }
2018 filesInfo = append(filesInfo, af)
2019 return true // track transitive dependencies
2020 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002021 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 +00002022 }
satayev333a1732021-05-17 21:35:26 +01002023 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2024 // Add the contents of the systemserverclasspath fragment to the apex.
2025 switch child.(type) {
2026 case *java.Library, *java.SdkLibrary:
2027 af := apexFileForJavaModule(ctx, child.(javaModule))
2028 filesInfo = append(filesInfo, af)
2029 return true // track transitive dependencies
2030 default:
2031 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2032 }
Colin Cross56a83212020-09-15 18:30:11 -07002033 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2034 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002035 } else if depTag == android.DarwinUniversalVariantTag {
2036 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002037 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002038 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002039 }
2040 }
2041 }
2042 return false
2043 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002044 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002045 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002046 return
2047 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002048
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002049 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002050 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002051 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002052 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002053 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002054 if e, ok := encountered[dest]; !ok {
2055 encountered[dest] = f
2056 } else {
2057 // If a module is directly included and also transitively depended on
2058 // consider it as directly included.
2059 e.transitiveDep = e.transitiveDep && f.transitiveDep
2060 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002061 }
2062 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002063 var result []apexFile
2064 for _, v := range encountered {
2065 result = append(result, v)
2066 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002067 return result
2068 }
2069 filesInfo = removeDup(filesInfo)
2070
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002071 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002072 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002073 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2074 // changes.
2075 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002076 })
2077
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002078 ////////////////////////////////////////////////////////////////////////////////////////////
2079 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002080 a.installDir = android.PathForModuleInstall(ctx, "apex")
2081 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002082
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002083 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002084 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002085 switch a.properties.ApexType {
2086 case imageApex:
2087 if buildFlattenedAsDefault {
2088 a.suffix = imageApexSuffix
2089 } else {
2090 a.suffix = ""
2091 a.primaryApexType = true
2092
2093 if ctx.Config().InstallExtraFlattenedApexes() {
2094 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2095 }
2096 }
2097 case zipApex:
2098 if proptools.String(a.properties.Payload_type) == "zip" {
2099 a.suffix = ""
2100 a.primaryApexType = true
2101 } else {
2102 a.suffix = zipApexSuffix
2103 }
2104 case flattenedApex:
2105 if buildFlattenedAsDefault {
2106 a.suffix = ""
2107 a.primaryApexType = true
2108 } else {
2109 a.suffix = flattenedSuffix
2110 }
2111 }
2112
Theotime Combes4ba38c12020-06-12 12:46:59 +00002113 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2114 case ext4FsType:
2115 a.payloadFsType = ext4
2116 case f2fsFsType:
2117 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002118 case erofsFsType:
2119 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002120 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002121 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 +00002122 }
2123
Jiyong Park7cd10e32020-01-14 09:22:18 +09002124 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2125 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2126 // the same library in the system partition, thus effectively sharing the same libraries
2127 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2128 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002129 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002130
Jooyung Han85d61762020-06-24 23:50:26 +09002131 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2132 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002133 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002134 a.linkToSystemLib = false
2135 }
2136
Jiyong Park4da07972021-01-05 21:01:11 +09002137 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002138 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002139
Jiyong Park9d677202020-02-19 16:29:35 +09002140 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002141 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002142 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002143 a.linkToSystemLib = false
2144 }
2145
Jiyong Park638d30e2020-02-26 18:27:19 +09002146 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2147 if ctx.Host() {
2148 a.linkToSystemLib = false
2149 }
2150
Colin Cross6340ea52021-11-04 12:01:18 -07002151 if a.properties.ApexType != zipApex {
2152 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2153 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002154
2155 ////////////////////////////////////////////////////////////////////////////////////////////
2156 // 4) generate the build rules to create the APEX. This is done in builder.go.
2157 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002158 if a.properties.ApexType == flattenedApex {
2159 a.buildFlattenedApex(ctx)
2160 } else {
2161 a.buildUnflattenedApex(ctx)
2162 }
Jiyong Park956305c2020-01-09 12:32:06 +09002163 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002164 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002165
2166 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2167 if a.installable() {
2168 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2169 // along with other ordinary files. (Note that this is done by apexer for
2170 // non-flattened APEXes)
2171 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2172
2173 // Place the public key as apex_pubkey. This is also done by apexer for
2174 // non-flattened APEXes case.
2175 // TODO(jiyong): Why do we need this CP rule?
2176 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2177 ctx.Build(pctx, android.BuildParams{
2178 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002179 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002180 Output: copiedPubkey,
2181 })
2182 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2183 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002184}
2185
Paul Duffincc33ec82021-04-25 23:14:55 +01002186// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2187// the bootclasspath_fragment contributes to the apex.
2188func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2189 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2190 var filesToAdd []apexFile
2191
2192 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002193 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2194 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2195 dirInApex := filepath.Join("javalib", arch.String())
2196 for _, f := range files {
2197 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2198 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2199 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2200 filesToAdd = append(filesToAdd, af)
2201 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002202 }
2203 }
2204
satayev3db35472021-05-06 23:59:58 +01002205 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002206 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2207 filesToAdd = append(filesToAdd, *af)
2208 }
satayev3db35472021-05-06 23:59:58 +01002209
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002210 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2211 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2212 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2213
2214 if pathOnHost != nil {
2215 // We need to copy the profile to a temporary path with the right filename because the apexer
2216 // will take the filename as is.
2217 ctx.Build(pctx, android.BuildParams{
2218 Rule: android.Cp,
2219 Input: pathOnHost,
2220 Output: tempPath,
2221 })
2222 } else {
2223 // At this point, the boot image profile cannot be generated. It is probably because the boot
2224 // image profile source file does not exist on the branch, or it is not available for the
2225 // current build target.
2226 // However, we cannot enforce the boot image profile to be generated because some build
2227 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2228 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2229 // only if the APEX is being built.
2230 ctx.Build(pctx, android.BuildParams{
2231 Rule: android.ErrorRule,
2232 Output: tempPath,
2233 Args: map[string]string{
2234 "error": "Boot image profile cannot be generated",
2235 },
2236 })
2237 }
2238
2239 androidMkModuleName := filepath.Base(pathInApex)
2240 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2241 filesToAdd = append(filesToAdd, af)
2242 }
2243
Paul Duffincc33ec82021-04-25 23:14:55 +01002244 return filesToAdd
2245}
2246
satayevb98371c2021-06-15 16:49:50 +01002247// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2248// the module contributes to the apex; or nil if the proto config was not generated.
2249func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2250 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2251 if !info.ClasspathFragmentProtoGenerated {
2252 return nil
2253 }
2254 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2255 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2256 return &af
satayev14e49132021-05-17 21:03:07 +01002257}
2258
Paul Duffincc33ec82021-04-25 23:14:55 +01002259// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2260// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002261func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2262 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2263
2264 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2265 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002266 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2267 if err != nil {
2268 ctx.ModuleErrorf("%s", err)
2269 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002270
2271 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2272 // bootclasspath_fragment.
2273 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2274 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002275}
2276
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002277///////////////////////////////////////////////////////////////////////////////////////////////////
2278// Factory functions
2279//
2280
2281func newApexBundle() *apexBundle {
2282 module := &apexBundle{}
2283
2284 module.AddProperties(&module.properties)
2285 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002286 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002287 module.AddProperties(&module.overridableProperties)
2288
2289 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2290 android.InitDefaultableModule(module)
2291 android.InitSdkAwareModule(module)
2292 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002293 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002294 return module
2295}
2296
Paul Duffineb8051d2021-10-18 17:49:39 +01002297func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002298 bundle := newApexBundle()
2299 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002300 return bundle
2301}
2302
2303// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2304// certain compatibility checks such as apex_available are not done for apex_test.
2305func testApexBundleFactory() android.Module {
2306 bundle := newApexBundle()
2307 bundle.testApex = true
2308 return bundle
2309}
2310
2311// apex packages other modules into an APEX file which is a packaging format for system-level
2312// components like binaries, shared libraries, etc.
2313func BundleFactory() android.Module {
2314 return newApexBundle()
2315}
2316
2317type Defaults struct {
2318 android.ModuleBase
2319 android.DefaultsModuleBase
2320}
2321
2322// apex_defaults provides defaultable properties to other apex modules.
2323func defaultsFactory() android.Module {
2324 return DefaultsFactory()
2325}
2326
2327func DefaultsFactory(props ...interface{}) android.Module {
2328 module := &Defaults{}
2329
2330 module.AddProperties(props...)
2331 module.AddProperties(
2332 &apexBundleProperties{},
2333 &apexTargetBundleProperties{},
2334 &overridableProperties{},
2335 )
2336
2337 android.InitDefaultsModule(module)
2338 return module
2339}
2340
2341type OverrideApex struct {
2342 android.ModuleBase
2343 android.OverrideModuleBase
2344}
2345
2346func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2347 // All the overrides happen in the base module.
2348}
2349
2350// override_apex is used to create an apex module based on another apex module by overriding some of
2351// its properties.
2352func overrideApexFactory() android.Module {
2353 m := &OverrideApex{}
2354
2355 m.AddProperties(&overridableProperties{})
2356
2357 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2358 android.InitOverrideModule(m)
2359 return m
2360}
2361
2362///////////////////////////////////////////////////////////////////////////////////////////////////
2363// Vality check routines
2364//
2365// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2366// certain conditions are not met.
2367//
2368// TODO(jiyong): move these checks to a separate go file.
2369
satayevad991492021-12-03 18:58:32 +00002370var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002372// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2373// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002374func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002375 if a.testApex || a.vndkApex {
2376 return
2377 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002378 // apexBundle::minSdkVersion reports its own errors.
2379 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002380 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002381}
2382
satayevad991492021-12-03 18:58:32 +00002383func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2384 return android.SdkSpec{
2385 Kind: android.SdkNone,
2386 ApiLevel: a.minSdkVersion(ctx),
2387 Raw: String(a.properties.Min_sdk_version),
2388 }
2389}
2390
2391func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002392 ver := proptools.String(a.properties.Min_sdk_version)
2393 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002394 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002395 }
2396 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2397 if err != nil {
2398 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2399 return android.NoneApiLevel
2400 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002401 return apiLevel
2402}
2403
2404// Ensures that a lib providing stub isn't statically linked
2405func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2406 // Practically, we only care about regular APEXes on the device.
2407 if ctx.Host() || a.testApex || a.vndkApex {
2408 return
2409 }
2410
2411 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2412
2413 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2414 if ccm, ok := to.(*cc.Module); ok {
2415 apexName := ctx.ModuleName()
2416 fromName := ctx.OtherModuleName(from)
2417 toName := ctx.OtherModuleName(to)
2418
2419 // If `to` is not actually in the same APEX as `from` then it does not need
2420 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002421 //
2422 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002423 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2424 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2425 return false
2426 }
2427
2428 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2429 // exception to this rule. It can't make the static dependencies dynamic
2430 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002431 // Same rule should be applied to linkerconfig, because it should be executed
2432 // only with static linked libraries before linker is available with ld.config.txt
2433 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002434 return false
2435 }
2436
2437 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2438 if isStubLibraryFromOtherApex && !externalDep {
2439 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2440 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2441 }
2442
2443 }
2444 return true
2445 })
2446}
2447
satayevb98371c2021-06-15 16:49:50 +01002448// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002449func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2450 if a.Updatable() {
2451 if String(a.properties.Min_sdk_version) == "" {
2452 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2453 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002454 if a.UsePlatformApis() {
2455 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2456 }
Daniel Norman69109112021-12-02 12:52:42 -08002457 if a.SocSpecific() || a.DeviceSpecific() {
2458 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2459 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002460 if a.FutureUpdatable() {
2461 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2462 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002463 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002464 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002465 }
2466}
2467
satayevb98371c2021-06-15 16:49:50 +01002468// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2469func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2470 ctx.VisitDirectDeps(func(module android.Module) {
2471 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2472 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2473 if !info.ClasspathFragmentProtoGenerated {
2474 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2475 }
2476 }
2477 })
2478}
2479
2480// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002481func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002482 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2483 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002484 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2485 tag := ctx.OtherModuleDependencyTag(module)
2486 switch tag {
2487 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002488 if m, ok := module.(interface {
2489 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2490 }); ok {
2491 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002492 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2493 }
2494 }
2495 }
2496 })
2497}
2498
satayevb98371c2021-06-15 16:49:50 +01002499// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002500func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2501 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2502 if ctx.Host() || a.testApex || a.vndkApex {
2503 return
2504 }
2505
2506 // Because APEXes targeting other than system/system_ext partitions can't set
2507 // apex_available, we skip checks for these APEXes
2508 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2509 return
2510 }
2511
2512 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2513 // Requiring them and their transitive depencies with apex_available is not right
2514 // because they just add noise.
2515 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2516 return
2517 }
2518
2519 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2520 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2521 if externalDep {
2522 return false
2523 }
2524
2525 apexName := ctx.ModuleName()
2526 fromName := ctx.OtherModuleName(from)
2527 toName := ctx.OtherModuleName(to)
2528
2529 // If `to` is not actually in the same APEX as `from` then it does not need
2530 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002531 //
2532 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002533 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2534 // As soon as the dependency graph crosses the APEX boundary, don't go
2535 // further.
2536 return false
2537 }
2538
2539 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2540 return true
2541 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002542 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2543 "\n\nDependency path:%s\n\n"+
2544 "Consider adding %q to 'apex_available' property of %q",
2545 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002546 // Visit this module's dependencies to check and report any issues with their availability.
2547 return true
2548 })
2549}
2550
Jiyong Park192600a2021-08-03 07:52:17 +00002551// checkStaticExecutable ensures that executables in an APEX are not static.
2552func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002553 // No need to run this for host APEXes
2554 if ctx.Host() {
2555 return
2556 }
2557
Jiyong Park192600a2021-08-03 07:52:17 +00002558 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2559 if ctx.OtherModuleDependencyTag(module) != executableTag {
2560 return
2561 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002562
2563 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002564 apex := a.ApexVariationName()
2565 exec := ctx.OtherModuleName(module)
2566 if isStaticExecutableAllowed(apex, exec) {
2567 return
2568 }
2569 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2570 }
2571 })
2572}
2573
2574// A small list of exceptions where static executables are allowed in APEXes.
2575func isStaticExecutableAllowed(apex string, exec string) bool {
2576 m := map[string][]string{
2577 "com.android.runtime": []string{
2578 "linker",
2579 "linkerconfig",
2580 },
2581 }
2582 execNames, ok := m[apex]
2583 return ok && android.InList(exec, execNames)
2584}
2585
braleeb0c1f0c2021-06-07 22:49:13 +08002586// Collect information for opening IDE project files in java/jdeps.go.
2587func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2588 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2589 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2590 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2591 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2592}
2593
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002594var (
2595 apexAvailBaseline = makeApexAvailableBaseline()
2596 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2597)
2598
Colin Cross440e0d02020-06-11 11:32:11 -07002599func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002600 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002601 moduleName = normalizeModuleName(moduleName)
2602
Colin Cross440e0d02020-06-11 11:32:11 -07002603 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002604 return true
2605 }
2606
2607 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002608 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002609 return true
2610 }
2611
2612 return false
2613}
2614
2615func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002616 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2617 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002618 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002619 if strings.HasPrefix(moduleName, "libclang_rt.") {
2620 // This module has many arch variants that depend on the product being built.
2621 // We don't want to list them all
2622 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002623 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002624 if strings.HasPrefix(moduleName, "androidx.") {
2625 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2626 moduleName = "androidx"
2627 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002628 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002629}
2630
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002631// Transform the map of apex -> modules to module -> apexes.
2632func invertApexBaseline(m map[string][]string) map[string][]string {
2633 r := make(map[string][]string)
2634 for apex, modules := range m {
2635 for _, module := range modules {
2636 r[module] = append(r[module], apex)
2637 }
2638 }
2639 return r
2640}
2641
2642// Retrieve the baseline of apexes to which the supplied module belongs.
2643func BaselineApexAvailable(moduleName string) []string {
2644 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2645}
2646
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002647// This is a map from apex to modules, which overrides the apex_available setting for that
2648// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002649// TODO(b/147364041): remove this
2650func makeApexAvailableBaseline() map[string][]string {
2651 // The "Module separator"s below are employed to minimize merge conflicts.
2652 m := make(map[string][]string)
2653 //
2654 // Module separator
2655 //
2656 m["com.android.appsearch"] = []string{
2657 "icing-java-proto-lite",
2658 "libprotobuf-java-lite",
2659 }
2660 //
2661 // Module separator
2662 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002663 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002664 "android.hardware.audio.common@5.0",
2665 "android.hardware.bluetooth.a2dp@1.0",
2666 "android.hardware.bluetooth.audio@2.0",
2667 "android.hardware.bluetooth@1.0",
2668 "android.hardware.bluetooth@1.1",
2669 "android.hardware.graphics.bufferqueue@1.0",
2670 "android.hardware.graphics.bufferqueue@2.0",
2671 "android.hardware.graphics.common@1.0",
2672 "android.hardware.graphics.common@1.1",
2673 "android.hardware.graphics.common@1.2",
2674 "android.hardware.media@1.0",
2675 "android.hidl.safe_union@1.0",
2676 "android.hidl.token@1.0",
2677 "android.hidl.token@1.0-utils",
2678 "avrcp-target-service",
2679 "avrcp_headers",
2680 "bluetooth-protos-lite",
2681 "bluetooth.mapsapi",
2682 "com.android.vcard",
2683 "dnsresolver_aidl_interface-V2-java",
2684 "ipmemorystore-aidl-interfaces-V5-java",
2685 "ipmemorystore-aidl-interfaces-java",
2686 "internal_include_headers",
2687 "lib-bt-packets",
2688 "lib-bt-packets-avrcp",
2689 "lib-bt-packets-base",
2690 "libFraunhoferAAC",
2691 "libaudio-a2dp-hw-utils",
2692 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002693 "libbluetooth",
2694 "libbluetooth-types",
2695 "libbluetooth-types-header",
2696 "libbluetooth_gd",
2697 "libbluetooth_headers",
2698 "libbluetooth_jni",
2699 "libbt-audio-hal-interface",
2700 "libbt-bta",
2701 "libbt-common",
2702 "libbt-hci",
2703 "libbt-platform-protos-lite",
2704 "libbt-protos-lite",
2705 "libbt-sbc-decoder",
2706 "libbt-sbc-encoder",
2707 "libbt-stack",
2708 "libbt-utils",
2709 "libbtcore",
2710 "libbtdevice",
2711 "libbte",
2712 "libbtif",
2713 "libchrome",
2714 "libevent",
2715 "libfmq",
2716 "libg722codec",
2717 "libgui_headers",
2718 "libmedia_headers",
2719 "libmodpb64",
2720 "libosi",
2721 "libstagefright_foundation_headers",
2722 "libstagefright_headers",
2723 "libstatslog",
2724 "libstatssocket",
2725 "libtinyxml2",
2726 "libudrv-uipc",
2727 "libz",
2728 "media_plugin_headers",
2729 "net-utils-services-common",
2730 "netd_aidl_interface-unstable-java",
2731 "netd_event_listener_interface-java",
2732 "netlink-client",
2733 "networkstack-client",
2734 "sap-api-java-static",
2735 "services.net",
2736 }
2737 //
2738 // Module separator
2739 //
2740 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2741 //
2742 // Module separator
2743 //
2744 m["com.android.extservices"] = []string{
2745 "error_prone_annotations",
2746 "ExtServices-core",
2747 "ExtServices",
2748 "libtextclassifier-java",
2749 "libz_current",
2750 "textclassifier-statsd",
2751 "TextClassifierNotificationLibNoManifest",
2752 "TextClassifierServiceLibNoManifest",
2753 }
2754 //
2755 // Module separator
2756 //
2757 m["com.android.neuralnetworks"] = []string{
2758 "android.hardware.neuralnetworks@1.0",
2759 "android.hardware.neuralnetworks@1.1",
2760 "android.hardware.neuralnetworks@1.2",
2761 "android.hardware.neuralnetworks@1.3",
2762 "android.hidl.allocator@1.0",
2763 "android.hidl.memory.token@1.0",
2764 "android.hidl.memory@1.0",
2765 "android.hidl.safe_union@1.0",
2766 "libarect",
2767 "libbuildversion",
2768 "libmath",
2769 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002770 }
2771 //
2772 // Module separator
2773 //
2774 m["com.android.media"] = []string{
2775 "android.frameworks.bufferhub@1.0",
2776 "android.hardware.cas.native@1.0",
2777 "android.hardware.cas@1.0",
2778 "android.hardware.configstore-utils",
2779 "android.hardware.configstore@1.0",
2780 "android.hardware.configstore@1.1",
2781 "android.hardware.graphics.allocator@2.0",
2782 "android.hardware.graphics.allocator@3.0",
2783 "android.hardware.graphics.bufferqueue@1.0",
2784 "android.hardware.graphics.bufferqueue@2.0",
2785 "android.hardware.graphics.common@1.0",
2786 "android.hardware.graphics.common@1.1",
2787 "android.hardware.graphics.common@1.2",
2788 "android.hardware.graphics.mapper@2.0",
2789 "android.hardware.graphics.mapper@2.1",
2790 "android.hardware.graphics.mapper@3.0",
2791 "android.hardware.media.omx@1.0",
2792 "android.hardware.media@1.0",
2793 "android.hidl.allocator@1.0",
2794 "android.hidl.memory.token@1.0",
2795 "android.hidl.memory@1.0",
2796 "android.hidl.token@1.0",
2797 "android.hidl.token@1.0-utils",
2798 "bionic_libc_platform_headers",
2799 "exoplayer2-extractor",
2800 "exoplayer2-extractor-annotation-stubs",
2801 "gl_headers",
2802 "jsr305",
2803 "libEGL",
2804 "libEGL_blobCache",
2805 "libEGL_getProcAddress",
2806 "libFLAC",
2807 "libFLAC-config",
2808 "libFLAC-headers",
2809 "libGLESv2",
2810 "libaacextractor",
2811 "libamrextractor",
2812 "libarect",
2813 "libaudio_system_headers",
2814 "libaudioclient",
2815 "libaudioclient_headers",
2816 "libaudiofoundation",
2817 "libaudiofoundation_headers",
2818 "libaudiomanager",
2819 "libaudiopolicy",
2820 "libaudioutils",
2821 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002822 "libbluetooth-types-header",
2823 "libbufferhub",
2824 "libbufferhub_headers",
2825 "libbufferhubqueue",
2826 "libc_malloc_debug_backtrace",
2827 "libcamera_client",
2828 "libcamera_metadata",
2829 "libdvr_headers",
2830 "libexpat",
2831 "libfifo",
2832 "libflacextractor",
2833 "libgrallocusage",
2834 "libgraphicsenv",
2835 "libgui",
2836 "libgui_headers",
2837 "libhardware_headers",
2838 "libinput",
2839 "liblzma",
2840 "libmath",
2841 "libmedia",
2842 "libmedia_codeclist",
2843 "libmedia_headers",
2844 "libmedia_helper",
2845 "libmedia_helper_headers",
2846 "libmedia_midiiowrapper",
2847 "libmedia_omx",
2848 "libmediautils",
2849 "libmidiextractor",
2850 "libmkvextractor",
2851 "libmp3extractor",
2852 "libmp4extractor",
2853 "libmpeg2extractor",
2854 "libnativebase_headers",
2855 "libnativewindow_headers",
2856 "libnblog",
2857 "liboggextractor",
2858 "libpackagelistparser",
2859 "libpdx",
2860 "libpdx_default_transport",
2861 "libpdx_headers",
2862 "libpdx_uds",
2863 "libprocinfo",
2864 "libspeexresampler",
2865 "libspeexresampler",
2866 "libstagefright_esds",
2867 "libstagefright_flacdec",
2868 "libstagefright_flacdec",
2869 "libstagefright_foundation",
2870 "libstagefright_foundation_headers",
2871 "libstagefright_foundation_without_imemory",
2872 "libstagefright_headers",
2873 "libstagefright_id3",
2874 "libstagefright_metadatautils",
2875 "libstagefright_mpeg2extractor",
2876 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002877 "libui",
2878 "libui_headers",
2879 "libunwindstack",
2880 "libvibrator",
2881 "libvorbisidec",
2882 "libwavextractor",
2883 "libwebm",
2884 "media_ndk_headers",
2885 "media_plugin_headers",
2886 "updatable-media",
2887 }
2888 //
2889 // Module separator
2890 //
2891 m["com.android.media.swcodec"] = []string{
2892 "android.frameworks.bufferhub@1.0",
2893 "android.hardware.common-ndk_platform",
2894 "android.hardware.configstore-utils",
2895 "android.hardware.configstore@1.0",
2896 "android.hardware.configstore@1.1",
2897 "android.hardware.graphics.allocator@2.0",
2898 "android.hardware.graphics.allocator@3.0",
2899 "android.hardware.graphics.allocator@4.0",
2900 "android.hardware.graphics.bufferqueue@1.0",
2901 "android.hardware.graphics.bufferqueue@2.0",
2902 "android.hardware.graphics.common-ndk_platform",
2903 "android.hardware.graphics.common@1.0",
2904 "android.hardware.graphics.common@1.1",
2905 "android.hardware.graphics.common@1.2",
2906 "android.hardware.graphics.mapper@2.0",
2907 "android.hardware.graphics.mapper@2.1",
2908 "android.hardware.graphics.mapper@3.0",
2909 "android.hardware.graphics.mapper@4.0",
2910 "android.hardware.media.bufferpool@2.0",
2911 "android.hardware.media.c2@1.0",
2912 "android.hardware.media.c2@1.1",
2913 "android.hardware.media.omx@1.0",
2914 "android.hardware.media@1.0",
2915 "android.hardware.media@1.0",
2916 "android.hidl.memory.token@1.0",
2917 "android.hidl.memory@1.0",
2918 "android.hidl.safe_union@1.0",
2919 "android.hidl.token@1.0",
2920 "android.hidl.token@1.0-utils",
2921 "libEGL",
2922 "libFLAC",
2923 "libFLAC-config",
2924 "libFLAC-headers",
2925 "libFraunhoferAAC",
2926 "libLibGuiProperties",
2927 "libarect",
2928 "libaudio_system_headers",
2929 "libaudioutils",
2930 "libaudioutils",
2931 "libaudioutils_fixedfft",
2932 "libavcdec",
2933 "libavcenc",
2934 "libavservices_minijail",
2935 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002936 "libbinderthreadstateutils",
2937 "libbluetooth-types-header",
2938 "libbufferhub_headers",
2939 "libcodec2",
2940 "libcodec2_headers",
2941 "libcodec2_hidl@1.0",
2942 "libcodec2_hidl@1.1",
2943 "libcodec2_internal",
2944 "libcodec2_soft_aacdec",
2945 "libcodec2_soft_aacenc",
2946 "libcodec2_soft_amrnbdec",
2947 "libcodec2_soft_amrnbenc",
2948 "libcodec2_soft_amrwbdec",
2949 "libcodec2_soft_amrwbenc",
2950 "libcodec2_soft_av1dec_gav1",
2951 "libcodec2_soft_avcdec",
2952 "libcodec2_soft_avcenc",
2953 "libcodec2_soft_common",
2954 "libcodec2_soft_flacdec",
2955 "libcodec2_soft_flacenc",
2956 "libcodec2_soft_g711alawdec",
2957 "libcodec2_soft_g711mlawdec",
2958 "libcodec2_soft_gsmdec",
2959 "libcodec2_soft_h263dec",
2960 "libcodec2_soft_h263enc",
2961 "libcodec2_soft_hevcdec",
2962 "libcodec2_soft_hevcenc",
2963 "libcodec2_soft_mp3dec",
2964 "libcodec2_soft_mpeg2dec",
2965 "libcodec2_soft_mpeg4dec",
2966 "libcodec2_soft_mpeg4enc",
2967 "libcodec2_soft_opusdec",
2968 "libcodec2_soft_opusenc",
2969 "libcodec2_soft_rawdec",
2970 "libcodec2_soft_vorbisdec",
2971 "libcodec2_soft_vp8dec",
2972 "libcodec2_soft_vp8enc",
2973 "libcodec2_soft_vp9dec",
2974 "libcodec2_soft_vp9enc",
2975 "libcodec2_vndk",
2976 "libdvr_headers",
2977 "libfmq",
2978 "libfmq",
2979 "libgav1",
2980 "libgralloctypes",
2981 "libgrallocusage",
2982 "libgraphicsenv",
2983 "libgsm",
2984 "libgui_bufferqueue_static",
2985 "libgui_headers",
2986 "libhardware",
2987 "libhardware_headers",
2988 "libhevcdec",
2989 "libhevcenc",
2990 "libion",
2991 "libjpeg",
2992 "liblzma",
2993 "libmath",
2994 "libmedia_codecserviceregistrant",
2995 "libmedia_headers",
2996 "libmpeg2dec",
2997 "libnativebase_headers",
2998 "libnativewindow_headers",
2999 "libpdx_headers",
3000 "libscudo_wrapper",
3001 "libsfplugin_ccodec_utils",
3002 "libspeexresampler",
3003 "libstagefright_amrnb_common",
3004 "libstagefright_amrnbdec",
3005 "libstagefright_amrnbenc",
3006 "libstagefright_amrwbdec",
3007 "libstagefright_amrwbenc",
3008 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003009 "libstagefright_enc_common",
3010 "libstagefright_flacdec",
3011 "libstagefright_foundation",
3012 "libstagefright_foundation_headers",
3013 "libstagefright_headers",
3014 "libstagefright_m4vh263dec",
3015 "libstagefright_m4vh263enc",
3016 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003017 "libui",
3018 "libui_headers",
3019 "libunwindstack",
3020 "libvorbisidec",
3021 "libvpx",
3022 "libyuv",
3023 "libyuv_static",
3024 "media_ndk_headers",
3025 "media_plugin_headers",
3026 "mediaswcodec",
3027 }
3028 //
3029 // Module separator
3030 //
3031 m["com.android.mediaprovider"] = []string{
3032 "MediaProvider",
3033 "MediaProviderGoogle",
3034 "fmtlib_ndk",
3035 "libbase_ndk",
3036 "libfuse",
3037 "libfuse_jni",
3038 }
3039 //
3040 // Module separator
3041 //
3042 m["com.android.permission"] = []string{
3043 "car-ui-lib",
3044 "iconloader",
3045 "kotlin-annotations",
3046 "kotlin-stdlib",
3047 "kotlin-stdlib-jdk7",
3048 "kotlin-stdlib-jdk8",
3049 "kotlinx-coroutines-android",
3050 "kotlinx-coroutines-android-nodeps",
3051 "kotlinx-coroutines-core",
3052 "kotlinx-coroutines-core-nodeps",
3053 "permissioncontroller-statsd",
3054 "GooglePermissionController",
3055 "PermissionController",
3056 "SettingsLibActionBarShadow",
3057 "SettingsLibAppPreference",
3058 "SettingsLibBarChartPreference",
3059 "SettingsLibLayoutPreference",
3060 "SettingsLibProgressBar",
3061 "SettingsLibSearchWidget",
3062 "SettingsLibSettingsTheme",
3063 "SettingsLibRestrictedLockUtils",
3064 "SettingsLibHelpUtils",
3065 }
3066 //
3067 // Module separator
3068 //
3069 m["com.android.runtime"] = []string{
3070 "bionic_libc_platform_headers",
3071 "libarm-optimized-routines-math",
3072 "libc_aeabi",
3073 "libc_bionic",
3074 "libc_bionic_ndk",
3075 "libc_bootstrap",
3076 "libc_common",
3077 "libc_common_shared",
3078 "libc_common_static",
3079 "libc_dns",
3080 "libc_dynamic_dispatch",
3081 "libc_fortify",
3082 "libc_freebsd",
3083 "libc_freebsd_large_stack",
3084 "libc_gdtoa",
3085 "libc_init_dynamic",
3086 "libc_init_static",
3087 "libc_jemalloc_wrapper",
3088 "libc_netbsd",
3089 "libc_nomalloc",
3090 "libc_nopthread",
3091 "libc_openbsd",
3092 "libc_openbsd_large_stack",
3093 "libc_openbsd_ndk",
3094 "libc_pthread",
3095 "libc_static_dispatch",
3096 "libc_syscalls",
3097 "libc_tzcode",
3098 "libc_unwind_static",
3099 "libdebuggerd",
3100 "libdebuggerd_common_headers",
3101 "libdebuggerd_handler_core",
3102 "libdebuggerd_handler_fallback",
3103 "libdl_static",
3104 "libjemalloc5",
3105 "liblinker_main",
3106 "liblinker_malloc",
3107 "liblz4",
3108 "liblzma",
3109 "libprocinfo",
3110 "libpropertyinfoparser",
3111 "libscudo",
3112 "libstdc++",
3113 "libsystemproperties",
3114 "libtombstoned_client_static",
3115 "libunwindstack",
3116 "libz",
3117 "libziparchive",
3118 }
3119 //
3120 // Module separator
3121 //
3122 m["com.android.tethering"] = []string{
3123 "android.hardware.tetheroffload.config-V1.0-java",
3124 "android.hardware.tetheroffload.control-V1.0-java",
3125 "android.hidl.base-V1.0-java",
3126 "libcgrouprc",
3127 "libcgrouprc_format",
3128 "libtetherutilsjni",
3129 "libvndksupport",
3130 "net-utils-framework-common",
3131 "netd_aidl_interface-V3-java",
3132 "netlink-client",
3133 "networkstack-aidl-interfaces-java",
3134 "tethering-aidl-interfaces-java",
3135 "TetheringApiCurrentLib",
3136 }
3137 //
3138 // Module separator
3139 //
3140 m["com.android.wifi"] = []string{
3141 "PlatformProperties",
3142 "android.hardware.wifi-V1.0-java",
3143 "android.hardware.wifi-V1.0-java-constants",
3144 "android.hardware.wifi-V1.1-java",
3145 "android.hardware.wifi-V1.2-java",
3146 "android.hardware.wifi-V1.3-java",
3147 "android.hardware.wifi-V1.4-java",
3148 "android.hardware.wifi.hostapd-V1.0-java",
3149 "android.hardware.wifi.hostapd-V1.1-java",
3150 "android.hardware.wifi.hostapd-V1.2-java",
3151 "android.hardware.wifi.supplicant-V1.0-java",
3152 "android.hardware.wifi.supplicant-V1.1-java",
3153 "android.hardware.wifi.supplicant-V1.2-java",
3154 "android.hardware.wifi.supplicant-V1.3-java",
3155 "android.hidl.base-V1.0-java",
3156 "android.hidl.manager-V1.0-java",
3157 "android.hidl.manager-V1.1-java",
3158 "android.hidl.manager-V1.2-java",
3159 "bouncycastle-unbundled",
3160 "dnsresolver_aidl_interface-V2-java",
3161 "error_prone_annotations",
3162 "framework-wifi-pre-jarjar",
3163 "framework-wifi-util-lib",
3164 "ipmemorystore-aidl-interfaces-V3-java",
3165 "ipmemorystore-aidl-interfaces-java",
3166 "ksoap2",
3167 "libnanohttpd",
3168 "libwifi-jni",
3169 "net-utils-services-common",
3170 "netd_aidl_interface-V2-java",
3171 "netd_aidl_interface-unstable-java",
3172 "netd_event_listener_interface-java",
3173 "netlink-client",
3174 "networkstack-client",
3175 "services.net",
3176 "wifi-lite-protos",
3177 "wifi-nano-protos",
3178 "wifi-service-pre-jarjar",
3179 "wifi-service-resources",
3180 }
3181 //
3182 // Module separator
3183 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003184 m["com.android.os.statsd"] = []string{
3185 "libstatssocket",
3186 }
3187 //
3188 // Module separator
3189 //
3190 m[android.AvailableToAnyApex] = []string{
3191 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3192 "androidx",
3193 "androidx-constraintlayout_constraintlayout",
3194 "androidx-constraintlayout_constraintlayout-nodeps",
3195 "androidx-constraintlayout_constraintlayout-solver",
3196 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3197 "com.google.android.material_material",
3198 "com.google.android.material_material-nodeps",
3199
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003200 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003201 "libprofile-clang-extras",
3202 "libprofile-clang-extras_ndk",
3203 "libprofile-extras",
3204 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003205 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003206 }
3207 return m
3208}
3209
3210func init() {
3211 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3212 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3213}
3214
3215func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3216 rules := make([]android.Rule, 0, len(modules_packages))
3217 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003218 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003219 BootclasspathJar().
3220 With("apex_available", module_name).
3221 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003222 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003223 Because("jars that are part of the " + module_name +
Andrei Onead967aee2022-01-19 15:36:40 +00003224 " module may only use these package prefixes: " + strings.Join(module_packages, ",") +
3225 " with min_sdk < T. Please consider the following alternatives:\n" +
3226 " 1. If the offending code is from a statically linked library, consider " +
3227 "removing that dependency and using an alternative already in the " +
3228 "bootclasspath, or perhaps a shared library." +
3229 " 2. Move the offending code into an allowed package.\n" +
3230 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3231 "health implications of bundling that code, particularly if the offending jar " +
3232 "is part of the bootclasspath.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003233 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003234 }
3235 return rules
3236}
3237
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003238// 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 +09003239// Adding code to the bootclasspath in new packages will cause issues on module update.
3240func qModulesPackages() map[string][]string {
3241 return map[string][]string{
3242 "com.android.conscrypt": []string{
3243 "android.net.ssl",
3244 "com.android.org.conscrypt",
3245 },
3246 "com.android.media": []string{
3247 "android.media",
3248 },
3249 }
3250}
3251
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003252// 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 +09003253// Adding code to the bootclasspath in new packages will cause issues on module update.
3254func rModulesPackages() map[string][]string {
3255 return map[string][]string{
3256 "com.android.mediaprovider": []string{
3257 "android.provider",
3258 },
3259 "com.android.permission": []string{
3260 "android.permission",
3261 "android.app.role",
3262 "com.android.permission",
3263 "com.android.role",
3264 },
3265 "com.android.sdkext": []string{
3266 "android.os.ext",
3267 },
3268 "com.android.os.statsd": []string{
3269 "android.app",
3270 "android.os",
3271 "android.util",
3272 "com.android.internal.statsd",
3273 "com.android.server.stats",
3274 },
3275 "com.android.wifi": []string{
3276 "com.android.server.wifi",
3277 "com.android.wifi.x",
3278 "android.hardware.wifi",
3279 "android.net.wifi",
3280 },
3281 "com.android.tethering": []string{
3282 "android.net",
3283 },
3284 }
3285}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003286
3287// For Bazel / bp2build
3288
3289type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003290 Manifest bazel.LabelAttribute
3291 Android_manifest bazel.LabelAttribute
3292 File_contexts bazel.LabelAttribute
3293 Key bazel.LabelAttribute
3294 Certificate bazel.LabelAttribute
3295 Min_sdk_version *string
3296 Updatable bazel.BoolAttribute
3297 Installable bazel.BoolAttribute
3298 Binaries bazel.LabelListAttribute
3299 Prebuilts bazel.LabelListAttribute
3300 Native_shared_libs_32 bazel.LabelListAttribute
3301 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003302 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003303}
3304
3305type convertedNativeSharedLibs struct {
3306 Native_shared_libs_32 bazel.LabelListAttribute
3307 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003308}
3309
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003310// ConvertWithBp2build performs bp2build conversion of an apex
3311func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3312 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003313 if ctx.ModuleType() != "apex" {
3314 return
3315 }
3316
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003317 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003318 if a.properties.Manifest != nil {
3319 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003320 }
3321
3322 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003323 if a.properties.AndroidManifest != nil {
3324 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003325 }
3326
3327 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003328 if a.properties.File_contexts != nil {
3329 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003330 }
3331
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003332 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003333 if a.properties.Min_sdk_version != nil {
3334 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003335 }
3336
3337 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003338 if a.overridableProperties.Key != nil {
3339 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003340 }
3341
3342 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003343 if a.overridableProperties.Certificate != nil {
3344 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003345 }
3346
Yu Liu4ae55d12022-01-05 17:17:23 -08003347 nativeSharedLibs := &convertedNativeSharedLibs{
3348 Native_shared_libs_32: bazel.LabelListAttribute{},
3349 Native_shared_libs_64: bazel.LabelListAttribute{},
3350 }
3351 compileMultilib := "both"
3352 if a.CompileMultilib() != nil {
3353 compileMultilib = *a.CompileMultilib()
3354 }
3355
3356 // properties.Native_shared_libs is treated as "both"
3357 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3358 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3359 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3360 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3361 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003362
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003363 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003364 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3365 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3366
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003367 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003368 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003369
3370 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003371 if a.properties.Updatable != nil {
3372 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003373 }
3374
3375 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003376 if a.properties.Installable != nil {
3377 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003378 }
3379
Wei Lif034cb42022-01-19 15:54:31 -08003380 var compressibleAttribute bazel.BoolAttribute
3381 if a.overridableProperties.Compressible != nil {
3382 compressibleAttribute.Value = a.overridableProperties.Compressible
3383 }
3384
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003385 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003386 Manifest: manifestLabelAttribute,
3387 Android_manifest: androidManifestLabelAttribute,
3388 File_contexts: fileContextsLabelAttribute,
3389 Min_sdk_version: minSdkVersion,
3390 Key: keyLabelAttribute,
3391 Certificate: certificateLabelAttribute,
3392 Updatable: updatableAttribute,
3393 Installable: installableAttribute,
3394 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3395 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3396 Binaries: binariesLabelListAttribute,
3397 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003398 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003399 }
3400
3401 props := bazel.BazelTargetModuleProperties{
3402 Rule_class: "apex",
3403 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3404 }
3405
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003406 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003407}
Yu Liu4ae55d12022-01-05 17:17:23 -08003408
3409// The following conversions are based on this table where the rows are the compile_multilib
3410// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3411// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3412// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3413// should not be compiled.
3414// multib/compile_multilib, 32, 64, both, first
3415// 32, 32/32, none/none, 32/32, none/32
3416// 64, none/none, 64/none, 64/none, 64/none
3417// both, 32/32, 64/none, 32&64/32, 64/32
3418// first, 32/32, 64/none, 64/32, 64/32
3419
3420func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3421 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3422 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3423 switch compileMultilb {
3424 case "both", "32":
3425 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3426 case "first":
3427 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3428 case "64":
3429 // Incompatible, ignore
3430 default:
3431 invalidCompileMultilib(ctx, compileMultilb)
3432 }
3433}
3434
3435func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3436 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3437 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3438 switch compileMultilb {
3439 case "both", "64", "first":
3440 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3441 case "32":
3442 // Incompatible, ignore
3443 default:
3444 invalidCompileMultilib(ctx, compileMultilb)
3445 }
3446}
3447
3448func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3449 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3450 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3451 switch compileMultilb {
3452 case "both":
3453 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3454 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3455 case "first":
3456 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3457 case "32":
3458 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3459 case "64":
3460 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3461 default:
3462 invalidCompileMultilib(ctx, compileMultilb)
3463 }
3464}
3465
3466func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3467 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3468 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3469 switch compileMultilb {
3470 case "both", "first":
3471 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3472 case "32":
3473 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3474 case "64":
3475 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3476 default:
3477 invalidCompileMultilib(ctx, compileMultilb)
3478 }
3479}
3480
3481func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3482 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3483 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3484}
3485
3486func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3487 list := bazel.LabelListAttribute{}
3488 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3489 nativeSharedLibs.Native_shared_libs_32.Append(list)
3490}
3491
3492func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3493 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3494 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3495}
3496
3497func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3498 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3499 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3500}
3501
3502func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3503 labelListAttr *bazel.LabelListAttribute) {
3504 list := bazel.LabelListAttribute{}
3505 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3506 labelListAttr.Append(list)
3507}
3508
3509func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3510 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3511}