blob: 9ef5e4ba08d86102f5191f4c8545d4ff4ca92cef [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.
Jooyung Hana6d36672022-02-24 13:58:07 +0900419 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900420 outputFile android.WritablePath
421
Jooyung Hana6d36672022-02-24 13:58:07 +0900422 // The built uncompressed .apex file.
423 outputApexFile android.WritablePath
424
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900425 // The built APEX file in app bundle format. This file is not directly installed to the
426 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
427 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
428 // system) to be merged into a single app bundle file that Play accepts. See
429 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
430 bundleModuleFile android.WritablePath
431
Colin Cross6340ea52021-11-04 12:01:18 -0700432 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900433 installDir android.InstallPath
434
Colin Cross6340ea52021-11-04 12:01:18 -0700435 // Path where this APEX was installed.
436 installedFile android.InstallPath
437
438 // Installed locations of symlinks for backward compatibility.
439 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900440
441 // Text file having the list of individual files that are included in this APEX. Used for
442 // debugging purpose.
443 installedFilesFile android.WritablePath
444
445 // List of module names that this APEX is including (to be shown via *-deps-info target).
446 // Used for debugging purpose.
447 android.ApexBundleDepsInfo
448
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900449 // Optional list of lint report zip files for apexes that contain java or app modules
450 lintReports android.Paths
451
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900452 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000453
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000454 isCompressed bool
455
sophiezc80a2b32020-11-12 16:39:19 +0000456 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700457 nativeApisUsedByModuleFile android.ModuleOutPath
458 nativeApisBackedByModuleFile android.ModuleOutPath
459 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800460
461 // Collect the module directory for IDE info in java/jdeps.go.
462 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900463}
464
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900465// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900466type apexFileClass int
467
Jooyung Han72bd2f82019-10-23 16:46:38 +0900468const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900469 app apexFileClass = iota
470 appSet
471 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900472 goBinary
473 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900474 nativeExecutable
475 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900476 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900477 pyBinary
478 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900479)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900480
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900481// apexFile represents a file in an APEX bundle. This is created during the first half of
482// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
483// of the function, this is used to create commands that copies the files into a staging directory,
484// where they are packaged into the APEX file. This struct is also used for creating Make modules
485// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900486type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900487 // buildFile is put in the installDir inside the APEX.
488 builtFile android.Path
489 noticeFiles android.Paths
490 installDir string
491 customStem string
492 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900493
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900494 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
495 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
496 // suffix>]
497 androidMkModuleName string // becomes LOCAL_MODULE
498 class apexFileClass // becomes LOCAL_MODULE_CLASS
499 moduleDir string // becomes LOCAL_PATH
500 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
501 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
502 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
503 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900504
505 jacocoReportClassesFile android.Path // only for javalibs and apps
506 lintDepSets java.LintDepSets // only for javalibs and apps
507 certificate java.Certificate // only for apps
508 overriddenPackageName string // only for apps
509
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900510 transitiveDep bool
511 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900512
Jiyong Park57621b22021-01-20 20:33:11 +0900513 multilib string
514
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900515 // TODO(jiyong): remove this
516 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900517}
518
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900519// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900520func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
521 ret := apexFile{
522 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900524 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900525 class: class,
526 module: module,
527 }
528 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900529 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900530 ret.moduleDir = ctx.OtherModuleDir(module)
531 ret.requiredModuleNames = module.RequiredModuleNames()
532 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
533 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900534 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900535 }
536 return ret
537}
538
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900539func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900540 return af.builtFile != nil && af.builtFile.String() != ""
541}
542
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900543// apexRelativePath returns the relative path of the given path from the install directory of this
544// apexFile.
545// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900546func (af *apexFile) apexRelativePath(path string) string {
547 return filepath.Join(af.installDir, path)
548}
549
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900550// path returns path of this apex file relative to the APEX root
551func (af *apexFile) path() string {
552 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900553}
554
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900555// stem returns the base filename of this apex file
556func (af *apexFile) stem() string {
557 if af.customStem != "" {
558 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900559 }
560 return af.builtFile.Base()
561}
562
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900563// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
564func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900565 var ret []string
566 for _, symlink := range af.symlinks {
567 ret = append(ret, af.apexRelativePath(symlink))
568 }
569 return ret
570}
571
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900572// availableToPlatform tests whether this apexFile is from a module that can be installed to the
573// platform.
574func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900575 if af.module == nil {
576 return false
577 }
578 if am, ok := af.module.(android.ApexModule); ok {
579 return am.AvailableFor(android.AvailableToPlatform)
580 }
581 return false
582}
583
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900584////////////////////////////////////////////////////////////////////////////////////////////////////
585// Mutators
586//
587// Brief description about mutators for APEX. The following three mutators are the most important
588// ones.
589//
590// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
591// to the (direct) dependencies of this APEX bundle.
592//
Paul Duffin949abc02020-12-08 10:34:30 +0000593// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900594// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
595// modules are marked as being included in the APEX via BuildForApex().
596//
Paul Duffin949abc02020-12-08 10:34:30 +0000597// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
598// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900599
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900600type dependencyTag struct {
601 blueprint.BaseDependencyTag
602 name string
603
604 // Determines if the dependent will be part of the APEX payload. Can be false for the
605 // dependencies to the signing key module, etc.
606 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000607
608 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
609 // replacement. This is needed because some prebuilt modules do not provide all the information
610 // needed by the apex.
611 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900612}
613
Paul Duffin8c535da2021-03-17 14:51:03 +0000614func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
615 return !d.sourceOnly
616}
617
618var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
619
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900620var (
Paul Duffin0b817782021-03-17 15:02:19 +0000621 androidAppTag = dependencyTag{name: "androidApp", payload: true}
622 bpfTag = dependencyTag{name: "bpf", payload: true}
623 certificateTag = dependencyTag{name: "certificate"}
624 executableTag = dependencyTag{name: "executable", payload: true}
625 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100626 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100627 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000628 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000629 javaLibTag = dependencyTag{name: "javaLib", payload: true}
630 jniLibTag = dependencyTag{name: "jniLib", payload: true}
631 keyTag = dependencyTag{name: "key"}
632 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
633 rroTag = dependencyTag{name: "rro", payload: true}
634 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
635 testForTag = dependencyTag{name: "test for"}
636 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000637 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900638)
639
640// TODO(jiyong): shorten this function signature
641func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900642 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900643 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900644 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900645
646 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900647 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900648 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
649 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900650 }
651
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900652 // Use *FarVariation* to be able to depend on modules having conflicting variations with
653 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
654 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900655 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900656 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900657 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
658 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900659 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900660 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900661}
662
663func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900664 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900665 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
666 } else {
667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
668 if ctx.Os().Bionic() {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
670 } else {
671 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
672 }
673 }
674}
675
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900676// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
677// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
678func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
679 deviceConfig := ctx.DeviceConfig()
680 if a.vndkApex {
681 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900682 }
683
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900684 var prefix string
685 var vndkVersion string
686 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000687 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900688 prefix = cc.VendorVariationPrefix
689 vndkVersion = deviceConfig.VndkVersion()
690 } else if a.ProductSpecific() {
691 prefix = cc.ProductVariationPrefix
692 vndkVersion = deviceConfig.ProductVndkVersion()
693 }
694 }
695 if vndkVersion == "current" {
696 vndkVersion = deviceConfig.PlatformVndkVersion()
697 }
698 if vndkVersion != "" {
699 return prefix + vndkVersion
700 }
701
702 return android.CoreVariation // The usual case
703}
704
705func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900706 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
707 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
708 // each target os/architectures, appropriate dependencies are selected by their
709 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900710 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900711 imageVariation := a.getImageVariation(ctx)
712
713 a.combineProperties(ctx)
714
715 has32BitTarget := false
716 for _, target := range targets {
717 if target.Arch.ArchType.Multilib == "lib32" {
718 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000719 }
720 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900721 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900722 // Don't include artifacts for the host cross targets because there is no way for us
723 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900724 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900725 continue
726 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000727
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900728 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000729
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 // Add native modules targeting both ABIs. When multilib.* is omitted for
731 // native_shared_libs/jni_libs/tests, it implies multilib.both
732 depsList = append(depsList, a.properties.Multilib.Both)
733 depsList = append(depsList, ApexNativeDependencies{
734 Native_shared_libs: a.properties.Native_shared_libs,
735 Tests: a.properties.Tests,
736 Jni_libs: a.properties.Jni_libs,
737 Binaries: nil,
738 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900739
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900740 // Add native modules targeting the first ABI When multilib.* is omitted for
741 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900742 isPrimaryAbi := i == 0
743 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900744 depsList = append(depsList, a.properties.Multilib.First)
745 depsList = append(depsList, ApexNativeDependencies{
746 Native_shared_libs: nil,
747 Tests: nil,
748 Jni_libs: nil,
749 Binaries: a.properties.Binaries,
750 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900751 }
752
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900753 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900754 switch target.Arch.ArchType.Multilib {
755 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900756 depsList = append(depsList, a.properties.Multilib.Lib32)
757 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900758 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900759 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900762 }
763 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900764
Jiyong Park59140302020-12-14 18:44:04 +0900765 // Add native modules targeting a specific arch variant
766 switch target.Arch.ArchType {
767 case android.Arm:
768 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
769 case android.Arm64:
770 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
771 case android.X86:
772 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
773 case android.X86_64:
774 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
775 default:
776 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
777 }
778
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900779 for _, d := range depsList {
780 addDependenciesForNativeModules(ctx, d, target, imageVariation)
781 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000782 ctx.AddFarVariationDependencies([]blueprint.Variation{
783 {Mutator: "os", Variation: target.OsVariation()},
784 {Mutator: "arch", Variation: target.ArchVariation()},
785 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900786 }
787
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900788 // Common-arch dependencies come next
789 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Paul Duffin94f19632021-04-20 12:40:07 +0100790 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
satayev333a1732021-05-17 21:35:26 +0100791 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900792 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900793 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000794 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900795
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900796 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
797 // This field currently isn't used.
798 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900799 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
800 if len(a.properties.Uses_sdks) > 0 {
801 sdkRefs := []android.SdkRef{}
802 for _, str := range a.properties.Uses_sdks {
803 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
804 sdkRefs = append(sdkRefs, parsed)
805 }
806 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100807 }
808}
809
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900810// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900811func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
812 if a.overridableProperties.Allowed_files != nil {
813 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100814 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900815
816 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
817 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800818 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900819 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700820 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
821 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
822 // regardless of the TARGET_PREFER_* setting. See b/144532908
823 arches := ctx.DeviceConfig().Arches()
824 if len(arches) != 0 {
825 archForPrebuiltEtc := arches[0]
826 for _, arch := range arches {
827 // Prefer 64-bit arch if there is any
828 if arch.ArchType.Multilib == "lib64" {
829 archForPrebuiltEtc = arch
830 break
831 }
832 }
833 ctx.AddFarVariationDependencies([]blueprint.Variation{
834 {Mutator: "os", Variation: ctx.Os().String()},
835 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
836 }, prebuiltTag, prebuilts...)
837 }
838 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700839
840 // Dependencies for signing
841 if String(a.overridableProperties.Key) == "" {
842 ctx.PropertyErrorf("key", "missing")
843 return
844 }
845 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
846
847 cert := android.SrcIsModule(a.getCertString(ctx))
848 if cert != "" {
849 ctx.AddDependency(ctx.Module(), certificateTag, cert)
850 // empty cert is not an error. Cert and private keys will be directly found under
851 // PRODUCT_DEFAULT_DEV_CERTIFICATE
852 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100853}
854
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900855type ApexBundleInfo struct {
856 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100857}
858
Paul Duffin949abc02020-12-08 10:34:30 +0000859var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900860
Paul Duffina7d6a892020-12-07 17:39:59 +0000861var _ ApexInfoMutator = (*apexBundle)(nil)
862
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100863func (a *apexBundle) ApexVariationName() string {
864 return a.properties.ApexVariationName
865}
866
Paul Duffina7d6a892020-12-07 17:39:59 +0000867// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900868// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
869// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
870// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
871// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000872//
873// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
874// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
875// The apexMutator uses that list to create module variants for the apexes to which it belongs.
876// The relationship between module variants and apexes is not one-to-one as variants will be
877// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000878func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900879
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900880 // The VNDK APEX is special. For the APEX, the membership is described in a very different
881 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
882 // libraries are self-identified by their vndk.enabled properties. There is no need to run
883 // this mutator for the APEX as nothing will be collected. So, let's return fast.
884 if a.vndkApex {
885 return
886 }
887
888 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
889 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
890 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
891 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
892 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900893 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
894 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900895 if proptools.Bool(a.properties.Use_vndk_as_stable) {
896 if !useVndk {
897 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
898 }
899 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
900 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
901 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
902 }
903 })
904 if mctx.Failed() {
905 return
906 }
Jooyung Handf78e212020-07-22 15:54:47 +0900907 }
908
Colin Cross56a83212020-09-15 18:30:11 -0700909 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900910 am, ok := child.(android.ApexModule)
911 if !ok || !am.CanHaveApexVariants() {
912 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900913 }
Paul Duffin573989d2021-03-17 13:25:29 +0000914 depTag := mctx.OtherModuleDependencyTag(child)
915
916 // Check to see if the tag always requires that the child module has an apex variant for every
917 // apex variant of the parent module. If it does not then it is still possible for something
918 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
919 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
920 return true
921 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000922 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900923 return false
924 }
Jooyung Handf78e212020-07-22 15:54:47 +0900925 if excludeVndkLibs {
926 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
927 return false
928 }
929 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900930 // By default, all the transitive dependencies are collected, unless filtered out
931 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700932 return true
933 }
934
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900935 // Records whether a certain module is included in this apexBundle via direct dependency or
936 // inndirect dependency.
937 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700938 mctx.WalkDeps(func(child, parent android.Module) bool {
939 if !continueApexDepsWalk(child, parent) {
940 return false
941 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900942 // If the parent is apexBundle, this child is directly depended.
943 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900944 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700945 contents[depName] = contents[depName].Add(directDep)
946 return true
947 })
948
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900949 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900950 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700951 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
952 Contents: apexContents,
953 })
954
Jooyung Haned124c32021-01-26 11:43:46 +0900955 minSdkVersion := a.minSdkVersion(mctx)
956 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
957 if minSdkVersion.IsNone() {
958 minSdkVersion = android.FutureApiLevel
959 }
960
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900961 // This is the main part of this mutator. Mark the collected dependencies that they need to
962 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900963
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100964 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
965 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700966 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100967 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900968 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700969 RequiredSdks: a.RequiredSdks(),
970 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900971 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100972 InApexVariants: []string{apexVariationName},
973 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700974 ApexContents: []*android.ApexContents{apexContents},
975 }
Colin Cross56a83212020-09-15 18:30:11 -0700976 mctx.WalkDeps(func(child, parent android.Module) bool {
977 if !continueApexDepsWalk(child, parent) {
978 return false
979 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900980 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900981 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900982 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900983}
984
Paul Duffina7d6a892020-12-07 17:39:59 +0000985type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100986 // ApexVariationName returns the name of the APEX variation to use in the apex
987 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
988 ApexVariationName() string
989
Paul Duffina7d6a892020-12-07 17:39:59 +0000990 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
991 // depended upon by an apex and which require an apex specific variant.
992 ApexInfoMutator(android.TopDownMutatorContext)
993}
994
995// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
996// specific variant to modules that support the ApexInfoMutator.
997func apexInfoMutator(mctx android.TopDownMutatorContext) {
998 if !mctx.Module().Enabled() {
999 return
1000 }
1001
1002 if a, ok := mctx.Module().(ApexInfoMutator); ok {
1003 a.ApexInfoMutator(mctx)
1004 return
1005 }
1006}
1007
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001008// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1009// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1010// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001011func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1012 if !mctx.Module().Enabled() {
1013 return
1014 }
1015 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001016 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1017 }
1018}
1019
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001020// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1021// the apex in order to retrieve its contents later.
1022// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001023func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1024 if !mctx.Module().Enabled() {
1025 return
1026 }
Colin Cross56a83212020-09-15 18:30:11 -07001027 if am, ok := mctx.Module().(android.ApexModule); ok {
1028 if testFor := am.TestFor(); len(testFor) > 0 {
1029 mctx.AddFarVariationDependencies([]blueprint.Variation{
1030 {Mutator: "os", Variation: am.Target().OsVariation()},
1031 {"arch", "common"},
1032 }, testForTag, testFor...)
1033 }
1034 }
1035}
1036
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001037// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001038func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1039 if !mctx.Module().Enabled() {
1040 return
1041 }
Colin Cross56a83212020-09-15 18:30:11 -07001042 if _, ok := mctx.Module().(android.ApexModule); ok {
1043 var contents []*android.ApexContents
1044 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1045 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1046 contents = append(contents, abInfo.Contents)
1047 }
1048 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1049 ApexContents: contents,
1050 })
Colin Crossaede88c2020-08-11 12:17:01 -07001051 }
1052}
1053
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001054// markPlatformAvailability marks whether or not a module can be available to platform. A module
1055// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1056// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1057// be) available to platform
1058// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001059func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1060 // Host and recovery are not considered as platform
1061 if mctx.Host() || mctx.Module().InstallInRecovery() {
1062 return
1063 }
1064
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001065 am, ok := mctx.Module().(android.ApexModule)
1066 if !ok {
1067 return
1068 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001069
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001070 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001071
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001072 // If any of the dep is not available to platform, this module is also considered as being
1073 // not available to platform even if it has "//apex_available:platform"
1074 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001075 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001076 // if the dependency crosses apex boundary, don't consider it
1077 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001078 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001079 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1080 availableToPlatform = false
1081 // TODO(b/154889534) trigger an error when 'am' has
1082 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001083 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001084 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001085
Paul Duffinb5769c12021-05-12 16:16:51 +01001086 // Exception 1: check to see if the module always requires it.
1087 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001088 availableToPlatform = true
1089 }
1090
1091 // Exception 2: bootstrap bionic libraries are also always available to platform
1092 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1093 availableToPlatform = true
1094 }
1095
1096 if !availableToPlatform {
1097 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001098 }
1099}
1100
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001101// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001102// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001103func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001104 if !mctx.Module().Enabled() {
1105 return
1106 }
Colin Cross56a83212020-09-15 18:30:11 -07001107
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001108 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001109 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001110 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001111 return
1112 }
1113
1114 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001115 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1116 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001117 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001118 if strings.HasPrefix(apexBundleName, "com.android.art") {
1119 // Create an alias from the platform variant. This is done to make
1120 // test_for dependencies work for modules that are split by the APEX
1121 // mutator, since test_for dependencies always go to the platform variant.
1122 // This doesn't happen for normal APEXes that are disjunct, so only do
1123 // this for the overlapping ART APEXes.
1124 // TODO(b/183882457): Remove this if the test_for functionality is
1125 // refactored to depend on the proper APEX variants instead of platform.
1126 mctx.CreateAliasVariation("", apexBundleName)
1127 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001128 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1129 apexBundleName := o.GetOverriddenModuleName()
1130 if apexBundleName == "" {
1131 mctx.ModuleErrorf("base property is not set")
1132 return
1133 }
1134 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001135 if strings.HasPrefix(apexBundleName, "com.android.art") {
1136 // TODO(b/183882457): See note for CreateAliasVariation above.
1137 mctx.CreateAliasVariation("", apexBundleName)
1138 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001139 }
1140}
Sundong Ahne9b55722019-09-06 17:37:42 +09001141
Paul Duffin6717d882021-06-15 19:09:41 +01001142// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1143// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001144func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001145 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001146 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001147 return !a.vndkApex
1148 }
1149
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001150 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001151}
1152
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001153// See android.UpdateDirectlyInAnyApex
1154// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001155func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1156 if !mctx.Module().Enabled() {
1157 return
1158 }
1159 if am, ok := mctx.Module().(android.ApexModule); ok {
1160 android.UpdateDirectlyInAnyApex(mctx, am)
1161 }
1162}
1163
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001164// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001165type apexPackaging int
1166
1167const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001168 // imageApex is a packaging method where contents are included in a filesystem image which
1169 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001170 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001171
1172 // zipApex is a packaging method where contents are directly included in the zip container.
1173 // This is used for host-side testing - because the contents are easily accessible by
1174 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001175 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001176
1177 // flattendApex is a packaging method where contents are not included in the APEX file, but
1178 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1179 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001180 flattenedApex
1181)
1182
1183const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001184 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001185 imageApexSuffix = ".apex"
1186 imageCapexSuffix = ".capex"
1187 zipApexSuffix = ".zipapex"
1188 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001189
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001190 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001191 imageApexType = "image"
1192 zipApexType = "zip"
1193 flattenedApexType = "flattened"
1194
Dan Willemsen47e1a752021-10-16 18:36:13 -07001195 ext4FsType = "ext4"
1196 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001197 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001198)
1199
1200// The suffix for the output "file", not the module
1201func (a apexPackaging) suffix() string {
1202 switch a {
1203 case imageApex:
1204 return imageApexSuffix
1205 case zipApex:
1206 return zipApexSuffix
1207 default:
1208 panic(fmt.Errorf("unknown APEX type %d", a))
1209 }
1210}
1211
1212func (a apexPackaging) name() string {
1213 switch a {
1214 case imageApex:
1215 return imageApexType
1216 case zipApex:
1217 return zipApexType
1218 default:
1219 panic(fmt.Errorf("unknown APEX type %d", a))
1220 }
1221}
1222
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001223// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1224// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001225func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001226 if !mctx.Module().Enabled() {
1227 return
1228 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001229 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001230 var variants []string
1231 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1232 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001233 // This is the normal case. Note that both image and flattend APEXes are
1234 // created. The image type is installed to the system partition, while the
1235 // flattened APEX is (optionally) installed to the system_ext partition.
1236 // This is mostly for GSI which has to support wide range of devices. If GSI
1237 // is installed on a newer (APEX-capable) device, the image APEX in the
1238 // system will be used. However, if the same GSI is installed on an old
1239 // device which can't support image APEX, the flattened APEX in the
1240 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001241 variants = append(variants, imageApexType, flattenedApexType)
1242 case "zip":
1243 variants = append(variants, zipApexType)
1244 case "both":
1245 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1246 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001247 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001248 return
1249 }
1250
1251 modules := mctx.CreateLocalVariations(variants...)
1252
1253 for i, v := range variants {
1254 switch v {
1255 case imageApexType:
1256 modules[i].(*apexBundle).properties.ApexType = imageApex
1257 case zipApexType:
1258 modules[i].(*apexBundle).properties.ApexType = zipApex
1259 case flattenedApexType:
1260 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001261 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001262 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001263 modules[i].(*apexBundle).MakeAsSystemExt()
1264 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001265 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001266 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001267 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001268 // payload_type is forcibly overridden to "image"
1269 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001270 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001271 }
1272}
1273
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001274var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001275
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001276// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001277func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1278 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001279 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001280 return true
1281}
1282
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001283var _ android.OutputFileProducer = (*apexBundle)(nil)
1284
1285// Implements android.OutputFileProducer
1286func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1287 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001288 case "", android.DefaultDistTag:
1289 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001290 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001291 case imageApexSuffix:
1292 // uncompressed one
1293 if a.outputApexFile != nil {
1294 return android.Paths{a.outputApexFile}, nil
1295 }
1296 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001297 default:
1298 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1299 }
1300}
1301
1302var _ cc.Coverage = (*apexBundle)(nil)
1303
1304// Implements cc.Coverage
1305func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1306 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1307}
1308
1309// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001310func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001311 a.properties.PreventInstall = true
1312}
1313
1314// Implements cc.Coverage
1315func (a *apexBundle) HideFromMake() {
1316 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001317 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1318 // TODO(ccross): untangle these
1319 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001320}
1321
1322// Implements cc.Coverage
1323func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1324 a.properties.IsCoverageVariant = coverage
1325}
1326
1327// Implements cc.Coverage
1328func (a *apexBundle) EnableCoverageIfNeeded() {}
1329
1330var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1331
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001332// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001333func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001334 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001335}
1336
Jiyong Parkf4020582021-11-29 12:37:10 +09001337func (a *apexBundle) FutureUpdatable() bool {
1338 return proptools.BoolDefault(a.properties.Future_updatable, false)
1339}
1340
Jiyong Park1bc84122021-06-22 20:23:05 +09001341func (a *apexBundle) UsePlatformApis() bool {
1342 return proptools.BoolDefault(a.properties.Platform_apis, false)
1343}
1344
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001345// getCertString returns the name of the cert that should be used to sign this APEX. This is
1346// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001347func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001348 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001349 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1350 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1351 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001352 if a.vndkApex {
1353 moduleName = vndkApexName
1354 }
1355 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001356 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001357 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001358 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001359 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001360}
1361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001362// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001363func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001364 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001365}
1366
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001367// See the generate_hashtree property
1368func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001369 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001370}
1371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001372// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001373func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1374 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1375}
1376
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001377// See the test_only_force_compression property
1378func (a *apexBundle) testOnlyShouldForceCompression() bool {
1379 return proptools.Bool(a.properties.Test_only_force_compression)
1380}
1381
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001382// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1383// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1384// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001385
Jiyong Parkf97782b2019-02-13 20:28:58 +09001386func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1387 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1388 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1389 }
1390}
1391
Jiyong Park388ef3f2019-01-28 19:47:32 +09001392func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001393 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1394 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001395 }
1396
1397 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001398 globalSanitizerNames := []string{}
1399 if a.Host() {
1400 globalSanitizerNames = ctx.Config().SanitizeHost()
1401 } else {
1402 arches := ctx.Config().SanitizeDeviceArch()
1403 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1404 globalSanitizerNames = ctx.Config().SanitizeDevice()
1405 }
1406 }
1407 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001408}
1409
Jooyung Han8ce8db92020-05-15 19:05:05 +09001410func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001411 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1412 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001413 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001414 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001415 for _, target := range ctx.MultiTargets() {
1416 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001417 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1418 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1419 Tests: nil,
1420 Jni_libs: nil,
1421 Binaries: nil,
1422 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001423 break
1424 }
1425 }
1426 }
1427}
1428
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001429// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1430// returned apexFile saves information about the Soong module that will be used for creating the
1431// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001432func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001433 // Decide the APEX-local directory by the multilib of the library In the future, we may
1434 // query this to the module.
1435 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001436 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001437 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001438 case "lib32":
1439 dirInApex = "lib"
1440 case "lib64":
1441 dirInApex = "lib64"
1442 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001443 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001444 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001445 }
Jooyung Han35155c42020-02-06 17:33:20 +09001446 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001447 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001448 // Special case for Bionic libs and other libs installed with them. This is to
1449 // prevent those libs from being included in the search path
1450 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1451 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1452 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1453 // will be loaded into the default linker namespace (aka "platform" namespace). If
1454 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1455 // be loaded again into the runtime linker namespace, which will result in double
1456 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001457 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001458 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001459
Jiyong Parkf653b052019-11-18 15:39:01 +09001460 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001461 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1462 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001463}
1464
Jiyong Park1833cef2019-12-13 13:28:36 +09001465func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001466 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001467 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001468 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001469 }
Jooyung Han35155c42020-02-06 17:33:20 +09001470 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001471 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001472 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1473 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001474 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001475 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001476 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001477}
1478
Jiyong Park99644e92020-11-17 22:21:02 +09001479func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1480 dirInApex := "bin"
1481 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1482 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1483 }
1484 fileToCopy := rustm.OutputFile().Path()
1485 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1486 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1487 return af
1488}
1489
1490func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1491 // Decide the APEX-local directory by the multilib of the library
1492 // In the future, we may query this to the module.
1493 var dirInApex string
1494 switch rustm.Arch().ArchType.Multilib {
1495 case "lib32":
1496 dirInApex = "lib"
1497 case "lib64":
1498 dirInApex = "lib64"
1499 }
1500 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1501 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1502 }
1503 fileToCopy := rustm.OutputFile().Path()
1504 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1505 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1506}
1507
Jiyong Park1833cef2019-12-13 13:28:36 +09001508func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001509 dirInApex := "bin"
1510 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001511 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001512}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001513
Jiyong Park1833cef2019-12-13 13:28:36 +09001514func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001515 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001516 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001517 // NB: Since go binaries are static we don't need the module for anything here, which is
1518 // good since the go tool is a blueprint.Module not an android.Module like we would
1519 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001520 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001521}
1522
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001523func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001524 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001525 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1526 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1527 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001528 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001529 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001530 af.symlinks = sh.Symlinks()
1531 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001532}
1533
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001534func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001535 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001536 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001537 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001538}
1539
atrost6e126252020-01-27 17:01:16 +00001540func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1541 dirInApex := filepath.Join("etc", config.SubDir())
1542 fileToCopy := config.CompatConfig()
1543 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1544}
1545
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001546// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1547// way.
1548type javaModule interface {
1549 android.Module
1550 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001551 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001552 JacocoReportClassesFile() android.Path
1553 LintDepSets() java.LintDepSets
1554 Stem() string
1555}
1556
1557var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001558var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001559var _ javaModule = (*java.SdkLibrary)(nil)
1560var _ javaModule = (*java.DexImport)(nil)
1561var _ javaModule = (*java.SdkLibraryImport)(nil)
1562
Paul Duffin190fdef2021-04-26 10:33:59 +01001563// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001564func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001565 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001566}
1567
1568// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1569func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001570 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001571 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001572 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1573 af.lintDepSets = module.LintDepSets()
1574 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001575 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1576 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1577 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1578 }
1579 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001580 return af
1581}
1582
1583// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1584// the same way.
1585type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001586 android.Module
1587 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001588 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001589 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001590 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001591 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001592 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001593 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001594}
1595
1596var _ androidApp = (*java.AndroidApp)(nil)
1597var _ androidApp = (*java.AndroidAppImport)(nil)
1598
1599func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001600 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001601 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001602 appDir = "priv-app"
1603 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001604 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001605 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001606 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001607 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001608 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001609 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001610
1611 if app, ok := aapp.(interface {
1612 OverriddenManifestPackageName() string
1613 }); ok {
1614 af.overriddenPackageName = app.OverriddenManifestPackageName()
1615 }
Jiyong Park618922e2020-01-08 13:35:43 +09001616 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001617}
1618
Jiyong Park69aeba92020-04-24 21:16:36 +09001619func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1620 rroDir := "overlay"
1621 dirInApex := filepath.Join(rroDir, rro.Theme())
1622 fileToCopy := rro.OutputFile()
1623 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1624 af.certificate = rro.Certificate()
1625
1626 if a, ok := rro.(interface {
1627 OverriddenManifestPackageName() string
1628 }); ok {
1629 af.overriddenPackageName = a.OverriddenManifestPackageName()
1630 }
1631 return af
1632}
1633
Ken Chenfad7f9d2021-11-10 22:02:57 +08001634func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1635 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001636 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1637}
1638
Jiyong Park12a719c2021-01-07 15:31:24 +09001639func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1640 dirInApex := filepath.Join("etc", "fs")
1641 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1642}
1643
Paul Duffin064b70c2020-11-02 17:32:38 +00001644// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001645// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1646// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1647// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001648func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001649 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001650 am, ok := child.(android.ApexModule)
1651 if !ok || !am.CanHaveApexVariants() {
1652 return false
1653 }
1654
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001655 // Filter-out unwanted depedendencies
1656 depTag := ctx.OtherModuleDependencyTag(child)
1657 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1658 return false
1659 }
1660 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001661 return false
1662 }
1663
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001664 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001665 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001666
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001667 // Visit actually
1668 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001669 })
1670}
1671
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001672// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1673type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001674
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001675const (
1676 ext4 fsType = iota
1677 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001678 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001679)
Artur Satayev849f8442020-04-28 14:57:42 +01001680
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001681func (f fsType) string() string {
1682 switch f {
1683 case ext4:
1684 return ext4FsType
1685 case f2fs:
1686 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001687 case erofs:
1688 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001689 default:
1690 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001691 }
1692}
1693
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001694// Creates build rules for an APEX. It consists of the following major steps:
1695//
1696// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1697// 2) traverse the dependency tree to collect apexFile structs from them.
1698// 3) some fields in apexBundle struct are configured
1699// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001700func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001701 ////////////////////////////////////////////////////////////////////////////////////////////
1702 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001703 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001704 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001705 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001706 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001707 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001708 if len(a.properties.Tests) > 0 && !a.testApex {
1709 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1710 return
1711 }
Jiyong Park678c8812020-02-07 17:25:49 +09001712
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001713 ////////////////////////////////////////////////////////////////////////////////////////////
1714 // 2) traverse the dependency tree to collect apexFile structs from them.
1715
1716 // all the files that will be included in this APEX
1717 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001718
Jooyung Hane1633032019-08-01 17:41:43 +09001719 // native lib dependencies
1720 var provideNativeLibs []string
1721 var requireNativeLibs []string
1722
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001723 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1724
braleeb0c1f0c2021-06-07 22:49:13 +08001725 // Collect the module directory for IDE info in java/jdeps.go.
1726 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1727
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001728 // TODO(jiyong): do this using WalkPayloadDeps
1729 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001730 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001731 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001732 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1733 return false
1734 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001735 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1736 return false
1737 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001738 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001739 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001740 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001741 case sharedLibTag, jniLibTag:
1742 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001743 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001744 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1745 fi.isJniLib = isJniLib
1746 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001747 // Collect the list of stub-providing libs except:
1748 // - VNDK libs are only for vendors
1749 // - bootstrap bionic libs are treated as provided by system
1750 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001751 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001752 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001753 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001754 } else if r, ok := child.(*rust.Module); ok {
1755 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001756 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001757 filesInfo = append(filesInfo, fi)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001758 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001759 propertyName := "native_shared_libs"
1760 if isJniLib {
1761 propertyName = "jni_libs"
1762 }
1763 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001764 }
1765 case executableTag:
1766 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001767 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001768 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001769 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001770 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001771 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001772 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001773 } else if rust, ok := child.(*rust.Module); ok {
1774 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1775 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001776 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001777 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1778 }
1779 case shBinaryTag:
1780 if sh, ok := child.(*sh.ShBinary); ok {
1781 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1782 } else {
1783 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001784 }
Paul Duffin94f19632021-04-20 12:40:07 +01001785 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001786 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001787 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1788 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001789 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001790 return false
1791 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001792
Paul Duffincc33ec82021-04-25 23:14:55 +01001793 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1794 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001795 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1796 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1797 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001798 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001799 }
satayev333a1732021-05-17 21:35:26 +01001800 case sscpfTag:
1801 {
1802 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1803 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1804 return false
1805 }
satayevb98371c2021-06-15 16:49:50 +01001806 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1807 filesInfo = append(filesInfo, *af)
1808 }
satayev333a1732021-05-17 21:35:26 +01001809 return true
1810 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001811 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001812 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001813 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001814 af := apexFileForJavaModule(ctx, child.(javaModule))
1815 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001816 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1817 return false
1818 }
1819 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001820 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001821 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001822 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001823 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001824 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001825 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001826 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001827 return true // track transitive dependencies
1828 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001829 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001830 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001831 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001832 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1833 appDir := "app"
1834 if ap.Privileged() {
1835 appDir = "priv-app"
1836 }
Yo Chiange8128052020-07-23 20:09:18 +08001837 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001838 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1839 af.certificate = java.PresignedCertificate
1840 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001841 } else {
1842 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1843 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001844 case rroTag:
1845 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1846 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1847 } else {
1848 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1849 }
markchien2f59ec92020-09-02 16:23:38 +08001850 case bpfTag:
1851 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1852 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001853 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001854 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001855 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001856 }
1857 } else {
1858 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1859 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001860 case fsTag:
1861 if fs, ok := child.(filesystem.Filesystem); ok {
1862 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1863 } else {
1864 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1865 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001866 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001867 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001868 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001869 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001870 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001871 }
Paul Duffin0b817782021-03-17 15:02:19 +00001872 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001873 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1874 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1875 } else {
1876 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1877 }
Roland Levillain630846d2019-06-26 12:48:34 +01001878 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001879 if ccTest, ok := child.(*cc.Module); ok {
1880 if ccTest.IsTestPerSrcAllTestsVariation() {
1881 // Multiple-output test module (where `test_per_src: true`).
1882 //
1883 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1884 // We do not add this variation to `filesInfo`, as it has no output;
1885 // however, we do add the other variations of this module as indirect
1886 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001887 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001888 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001889 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001890 af.class = nativeTest
1891 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001892 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001893 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001894 } else {
1895 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1896 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001897 case keyTag:
1898 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001899 a.privateKeyFile = key.privateKeyFile
1900 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001901 } else {
1902 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001903 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001904 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001905 case certificateTag:
1906 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001907 a.containerCertificateFile = dep.Certificate.Pem
1908 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001909 } else {
1910 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1911 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001912 case android.PrebuiltDepTag:
1913 // If the prebuilt is force disabled, remember to delete the prebuilt file
1914 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001915 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001916 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1917 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001918 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001919 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001920 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001921 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001922 // We cannot use a switch statement on `depTag` here as the checked
1923 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001924 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001925 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001926 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001927 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001928 return false
1929 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001930 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1931 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001932
1933 // Always track transitive dependencies for host.
1934 if a.Host() {
1935 filesInfo = append(filesInfo, af)
1936 return true
1937 }
1938
Colin Cross56a83212020-09-15 18:30:11 -07001939 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001940 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001941 // If the dependency is a stubs lib, don't include it in this APEX,
1942 // but make sure that the lib is installed on the device.
1943 // In case no APEX is having the lib, the lib is installed to the system
1944 // partition.
1945 //
1946 // Always include if we are a host-apex however since those won't have any
1947 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001948 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001949 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00001950 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001951 if !android.InList(name, a.requiredDeps) {
1952 a.requiredDeps = append(a.requiredDeps, name)
1953 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001954 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001955 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001956 // Don't track further
1957 return false
1958 }
Jiyong Parke3867542020-12-03 17:28:25 +09001959
1960 // If the dep is not considered to be in the same
1961 // apex, don't add it to filesInfo so that it is not
1962 // included in this APEX.
1963 // TODO(jiyong): move this to at the top of the
1964 // else-if clause for the indirect dependencies.
1965 // Currently, that's impossible because we would
1966 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00001967 // DepIsInSameAPex is false. We also shouldn't do
1968 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001969 //
1970 // TODO(jiyong): explain why the same module is passed in twice.
1971 // Switching the first am to parent breaks lots of tests.
1972 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09001973 return false
1974 }
1975
Jiyong Parkf653b052019-11-18 15:39:01 +09001976 filesInfo = append(filesInfo, af)
1977 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001978 } else if rm, ok := child.(*rust.Module); ok {
1979 af := apexFileForRustLibrary(ctx, rm)
1980 af.transitiveDep = true
1981 filesInfo = append(filesInfo, af)
1982 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001983 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001984 } else if cc.IsTestPerSrcDepTag(depTag) {
1985 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001986 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001987 // Handle modules created as `test_per_src` variations of a single test module:
1988 // use the name of the generated test binary (`fileToCopy`) instead of the name
1989 // of the original test module (`depName`, shared by all `test_per_src`
1990 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001991 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001992 // these are not considered transitive dep
1993 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001994 filesInfo = append(filesInfo, af)
1995 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001996 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09001997 } else if cc.IsHeaderDepTag(depTag) {
1998 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09001999 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002000 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2001 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002002 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002003 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002004 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2005 }
Jiyong Park99644e92020-11-17 22:21:02 +09002006 } else if rust.IsDylibDepTag(depTag) {
2007 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2008 af := apexFileForRustLibrary(ctx, rustm)
2009 af.transitiveDep = true
2010 filesInfo = append(filesInfo, af)
2011 return true // track transitive dependencies
2012 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002013 } else if rust.IsRlibDepTag(depTag) {
2014 // Rlib is statically linked, but it might have shared lib
2015 // dependencies. Track them.
2016 return true
Paul Duffin65898052021-04-20 22:47:03 +01002017 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002018 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002019 switch child.(type) {
2020 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002021 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002022 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002023 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002024 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002025 return false
2026 }
2027 filesInfo = append(filesInfo, af)
2028 return true // track transitive dependencies
2029 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002030 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 +00002031 }
satayev333a1732021-05-17 21:35:26 +01002032 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2033 // Add the contents of the systemserverclasspath fragment to the apex.
2034 switch child.(type) {
2035 case *java.Library, *java.SdkLibrary:
2036 af := apexFileForJavaModule(ctx, child.(javaModule))
2037 filesInfo = append(filesInfo, af)
2038 return true // track transitive dependencies
2039 default:
2040 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2041 }
Colin Cross56a83212020-09-15 18:30:11 -07002042 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2043 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002044 } else if depTag == android.DarwinUniversalVariantTag {
2045 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002046 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002047 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002048 }
2049 }
2050 }
2051 return false
2052 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002053 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002054 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002055 return
2056 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002057
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002058 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002059 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002060 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002061 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002062 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002063 if e, ok := encountered[dest]; !ok {
2064 encountered[dest] = f
2065 } else {
2066 // If a module is directly included and also transitively depended on
2067 // consider it as directly included.
2068 e.transitiveDep = e.transitiveDep && f.transitiveDep
2069 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002070 }
2071 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002072 var result []apexFile
2073 for _, v := range encountered {
2074 result = append(result, v)
2075 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002076 return result
2077 }
2078 filesInfo = removeDup(filesInfo)
2079
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002080 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002081 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002082 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2083 // changes.
2084 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002085 })
2086
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002087 ////////////////////////////////////////////////////////////////////////////////////////////
2088 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002089 a.installDir = android.PathForModuleInstall(ctx, "apex")
2090 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002091
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002092 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002093 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002094 switch a.properties.ApexType {
2095 case imageApex:
2096 if buildFlattenedAsDefault {
2097 a.suffix = imageApexSuffix
2098 } else {
2099 a.suffix = ""
2100 a.primaryApexType = true
2101
2102 if ctx.Config().InstallExtraFlattenedApexes() {
2103 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2104 }
2105 }
2106 case zipApex:
2107 if proptools.String(a.properties.Payload_type) == "zip" {
2108 a.suffix = ""
2109 a.primaryApexType = true
2110 } else {
2111 a.suffix = zipApexSuffix
2112 }
2113 case flattenedApex:
2114 if buildFlattenedAsDefault {
2115 a.suffix = ""
2116 a.primaryApexType = true
2117 } else {
2118 a.suffix = flattenedSuffix
2119 }
2120 }
2121
Theotime Combes4ba38c12020-06-12 12:46:59 +00002122 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2123 case ext4FsType:
2124 a.payloadFsType = ext4
2125 case f2fsFsType:
2126 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002127 case erofsFsType:
2128 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002129 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002130 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 +00002131 }
2132
Jiyong Park7cd10e32020-01-14 09:22:18 +09002133 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2134 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2135 // the same library in the system partition, thus effectively sharing the same libraries
2136 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2137 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002138 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002139
Jooyung Han85d61762020-06-24 23:50:26 +09002140 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2141 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002142 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002143 a.linkToSystemLib = false
2144 }
2145
Jiyong Park4da07972021-01-05 21:01:11 +09002146 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002147 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002148
Jiyong Park9d677202020-02-19 16:29:35 +09002149 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002150 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002151 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002152 a.linkToSystemLib = false
2153 }
2154
Jiyong Park638d30e2020-02-26 18:27:19 +09002155 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2156 if ctx.Host() {
2157 a.linkToSystemLib = false
2158 }
2159
Colin Cross6340ea52021-11-04 12:01:18 -07002160 if a.properties.ApexType != zipApex {
2161 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2162 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002163
2164 ////////////////////////////////////////////////////////////////////////////////////////////
2165 // 4) generate the build rules to create the APEX. This is done in builder.go.
2166 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002167 if a.properties.ApexType == flattenedApex {
2168 a.buildFlattenedApex(ctx)
2169 } else {
2170 a.buildUnflattenedApex(ctx)
2171 }
Jiyong Park956305c2020-01-09 12:32:06 +09002172 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002173 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002174
2175 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2176 if a.installable() {
2177 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2178 // along with other ordinary files. (Note that this is done by apexer for
2179 // non-flattened APEXes)
2180 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2181
2182 // Place the public key as apex_pubkey. This is also done by apexer for
2183 // non-flattened APEXes case.
2184 // TODO(jiyong): Why do we need this CP rule?
2185 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2186 ctx.Build(pctx, android.BuildParams{
2187 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002188 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002189 Output: copiedPubkey,
2190 })
2191 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2192 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002193}
2194
Paul Duffincc33ec82021-04-25 23:14:55 +01002195// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2196// the bootclasspath_fragment contributes to the apex.
2197func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2198 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2199 var filesToAdd []apexFile
2200
2201 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002202 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2203 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2204 dirInApex := filepath.Join("javalib", arch.String())
2205 for _, f := range files {
2206 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2207 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2208 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2209 filesToAdd = append(filesToAdd, af)
2210 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002211 }
2212 }
2213
satayev3db35472021-05-06 23:59:58 +01002214 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002215 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2216 filesToAdd = append(filesToAdd, *af)
2217 }
satayev3db35472021-05-06 23:59:58 +01002218
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002219 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2220 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2221 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2222
2223 if pathOnHost != nil {
2224 // We need to copy the profile to a temporary path with the right filename because the apexer
2225 // will take the filename as is.
2226 ctx.Build(pctx, android.BuildParams{
2227 Rule: android.Cp,
2228 Input: pathOnHost,
2229 Output: tempPath,
2230 })
2231 } else {
2232 // At this point, the boot image profile cannot be generated. It is probably because the boot
2233 // image profile source file does not exist on the branch, or it is not available for the
2234 // current build target.
2235 // However, we cannot enforce the boot image profile to be generated because some build
2236 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2237 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2238 // only if the APEX is being built.
2239 ctx.Build(pctx, android.BuildParams{
2240 Rule: android.ErrorRule,
2241 Output: tempPath,
2242 Args: map[string]string{
2243 "error": "Boot image profile cannot be generated",
2244 },
2245 })
2246 }
2247
2248 androidMkModuleName := filepath.Base(pathInApex)
2249 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2250 filesToAdd = append(filesToAdd, af)
2251 }
2252
Paul Duffincc33ec82021-04-25 23:14:55 +01002253 return filesToAdd
2254}
2255
satayevb98371c2021-06-15 16:49:50 +01002256// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2257// the module contributes to the apex; or nil if the proto config was not generated.
2258func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2259 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2260 if !info.ClasspathFragmentProtoGenerated {
2261 return nil
2262 }
2263 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2264 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2265 return &af
satayev14e49132021-05-17 21:03:07 +01002266}
2267
Paul Duffincc33ec82021-04-25 23:14:55 +01002268// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2269// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002270func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2271 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2272
2273 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2274 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002275 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2276 if err != nil {
2277 ctx.ModuleErrorf("%s", err)
2278 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002279
2280 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2281 // bootclasspath_fragment.
2282 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2283 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002284}
2285
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002286///////////////////////////////////////////////////////////////////////////////////////////////////
2287// Factory functions
2288//
2289
2290func newApexBundle() *apexBundle {
2291 module := &apexBundle{}
2292
2293 module.AddProperties(&module.properties)
2294 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002295 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002296 module.AddProperties(&module.overridableProperties)
2297
2298 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2299 android.InitDefaultableModule(module)
2300 android.InitSdkAwareModule(module)
2301 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002302 android.InitBazelModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002303 return module
2304}
2305
Paul Duffineb8051d2021-10-18 17:49:39 +01002306func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002307 bundle := newApexBundle()
2308 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002309 return bundle
2310}
2311
2312// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2313// certain compatibility checks such as apex_available are not done for apex_test.
2314func testApexBundleFactory() android.Module {
2315 bundle := newApexBundle()
2316 bundle.testApex = true
2317 return bundle
2318}
2319
2320// apex packages other modules into an APEX file which is a packaging format for system-level
2321// components like binaries, shared libraries, etc.
2322func BundleFactory() android.Module {
2323 return newApexBundle()
2324}
2325
2326type Defaults struct {
2327 android.ModuleBase
2328 android.DefaultsModuleBase
2329}
2330
2331// apex_defaults provides defaultable properties to other apex modules.
2332func defaultsFactory() android.Module {
2333 return DefaultsFactory()
2334}
2335
2336func DefaultsFactory(props ...interface{}) android.Module {
2337 module := &Defaults{}
2338
2339 module.AddProperties(props...)
2340 module.AddProperties(
2341 &apexBundleProperties{},
2342 &apexTargetBundleProperties{},
2343 &overridableProperties{},
2344 )
2345
2346 android.InitDefaultsModule(module)
2347 return module
2348}
2349
2350type OverrideApex struct {
2351 android.ModuleBase
2352 android.OverrideModuleBase
2353}
2354
2355func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2356 // All the overrides happen in the base module.
2357}
2358
2359// override_apex is used to create an apex module based on another apex module by overriding some of
2360// its properties.
2361func overrideApexFactory() android.Module {
2362 m := &OverrideApex{}
2363
2364 m.AddProperties(&overridableProperties{})
2365
2366 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2367 android.InitOverrideModule(m)
2368 return m
2369}
2370
2371///////////////////////////////////////////////////////////////////////////////////////////////////
2372// Vality check routines
2373//
2374// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2375// certain conditions are not met.
2376//
2377// TODO(jiyong): move these checks to a separate go file.
2378
satayevad991492021-12-03 18:58:32 +00002379var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2380
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002381// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2382// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002383func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002384 if a.testApex || a.vndkApex {
2385 return
2386 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002387 // apexBundle::minSdkVersion reports its own errors.
2388 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002389 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002390}
2391
satayevad991492021-12-03 18:58:32 +00002392func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2393 return android.SdkSpec{
2394 Kind: android.SdkNone,
2395 ApiLevel: a.minSdkVersion(ctx),
2396 Raw: String(a.properties.Min_sdk_version),
2397 }
2398}
2399
2400func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002401 ver := proptools.String(a.properties.Min_sdk_version)
2402 if ver == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002403 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002404 }
2405 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
2406 if err != nil {
2407 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2408 return android.NoneApiLevel
2409 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002410 return apiLevel
2411}
2412
2413// Ensures that a lib providing stub isn't statically linked
2414func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2415 // Practically, we only care about regular APEXes on the device.
2416 if ctx.Host() || a.testApex || a.vndkApex {
2417 return
2418 }
2419
2420 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2421
2422 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2423 if ccm, ok := to.(*cc.Module); ok {
2424 apexName := ctx.ModuleName()
2425 fromName := ctx.OtherModuleName(from)
2426 toName := ctx.OtherModuleName(to)
2427
2428 // If `to` is not actually in the same APEX as `from` then it does not need
2429 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002430 //
2431 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002432 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2433 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2434 return false
2435 }
2436
2437 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2438 // exception to this rule. It can't make the static dependencies dynamic
2439 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002440 // Same rule should be applied to linkerconfig, because it should be executed
2441 // only with static linked libraries before linker is available with ld.config.txt
2442 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002443 return false
2444 }
2445
2446 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2447 if isStubLibraryFromOtherApex && !externalDep {
2448 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2449 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2450 }
2451
2452 }
2453 return true
2454 })
2455}
2456
satayevb98371c2021-06-15 16:49:50 +01002457// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002458func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2459 if a.Updatable() {
2460 if String(a.properties.Min_sdk_version) == "" {
2461 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2462 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002463 if a.UsePlatformApis() {
2464 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2465 }
Daniel Norman69109112021-12-02 12:52:42 -08002466 if a.SocSpecific() || a.DeviceSpecific() {
2467 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2468 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002469 if a.FutureUpdatable() {
2470 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2471 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002472 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002473 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002474 }
2475}
2476
satayevb98371c2021-06-15 16:49:50 +01002477// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2478func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2479 ctx.VisitDirectDeps(func(module android.Module) {
2480 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2481 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2482 if !info.ClasspathFragmentProtoGenerated {
2483 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2484 }
2485 }
2486 })
2487}
2488
2489// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002490func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002491 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2492 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002493 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2494 tag := ctx.OtherModuleDependencyTag(module)
2495 switch tag {
2496 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002497 if m, ok := module.(interface {
2498 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2499 }); ok {
2500 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002501 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2502 }
2503 }
2504 }
2505 })
2506}
2507
satayevb98371c2021-06-15 16:49:50 +01002508// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002509func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2510 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2511 if ctx.Host() || a.testApex || a.vndkApex {
2512 return
2513 }
2514
2515 // Because APEXes targeting other than system/system_ext partitions can't set
2516 // apex_available, we skip checks for these APEXes
2517 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2518 return
2519 }
2520
2521 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2522 // Requiring them and their transitive depencies with apex_available is not right
2523 // because they just add noise.
2524 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2525 return
2526 }
2527
2528 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2529 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2530 if externalDep {
2531 return false
2532 }
2533
2534 apexName := ctx.ModuleName()
2535 fromName := ctx.OtherModuleName(from)
2536 toName := ctx.OtherModuleName(to)
2537
2538 // If `to` is not actually in the same APEX as `from` then it does not need
2539 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002540 //
2541 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002542 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2543 // As soon as the dependency graph crosses the APEX boundary, don't go
2544 // further.
2545 return false
2546 }
2547
2548 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2549 return true
2550 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002551 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2552 "\n\nDependency path:%s\n\n"+
2553 "Consider adding %q to 'apex_available' property of %q",
2554 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002555 // Visit this module's dependencies to check and report any issues with their availability.
2556 return true
2557 })
2558}
2559
Jiyong Park192600a2021-08-03 07:52:17 +00002560// checkStaticExecutable ensures that executables in an APEX are not static.
2561func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002562 // No need to run this for host APEXes
2563 if ctx.Host() {
2564 return
2565 }
2566
Jiyong Park192600a2021-08-03 07:52:17 +00002567 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2568 if ctx.OtherModuleDependencyTag(module) != executableTag {
2569 return
2570 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002571
2572 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002573 apex := a.ApexVariationName()
2574 exec := ctx.OtherModuleName(module)
2575 if isStaticExecutableAllowed(apex, exec) {
2576 return
2577 }
2578 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2579 }
2580 })
2581}
2582
2583// A small list of exceptions where static executables are allowed in APEXes.
2584func isStaticExecutableAllowed(apex string, exec string) bool {
2585 m := map[string][]string{
2586 "com.android.runtime": []string{
2587 "linker",
2588 "linkerconfig",
2589 },
2590 }
2591 execNames, ok := m[apex]
2592 return ok && android.InList(exec, execNames)
2593}
2594
braleeb0c1f0c2021-06-07 22:49:13 +08002595// Collect information for opening IDE project files in java/jdeps.go.
2596func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
2597 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2598 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2599 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
2600 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2601}
2602
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002603var (
2604 apexAvailBaseline = makeApexAvailableBaseline()
2605 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2606)
2607
Colin Cross440e0d02020-06-11 11:32:11 -07002608func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002609 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002610 moduleName = normalizeModuleName(moduleName)
2611
Colin Cross440e0d02020-06-11 11:32:11 -07002612 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002613 return true
2614 }
2615
2616 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002617 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002618 return true
2619 }
2620
2621 return false
2622}
2623
2624func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002625 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2626 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002627 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002628 if strings.HasPrefix(moduleName, "libclang_rt.") {
2629 // This module has many arch variants that depend on the product being built.
2630 // We don't want to list them all
2631 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002632 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002633 if strings.HasPrefix(moduleName, "androidx.") {
2634 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2635 moduleName = "androidx"
2636 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002637 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002638}
2639
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002640// Transform the map of apex -> modules to module -> apexes.
2641func invertApexBaseline(m map[string][]string) map[string][]string {
2642 r := make(map[string][]string)
2643 for apex, modules := range m {
2644 for _, module := range modules {
2645 r[module] = append(r[module], apex)
2646 }
2647 }
2648 return r
2649}
2650
2651// Retrieve the baseline of apexes to which the supplied module belongs.
2652func BaselineApexAvailable(moduleName string) []string {
2653 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2654}
2655
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002656// This is a map from apex to modules, which overrides the apex_available setting for that
2657// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002658// TODO(b/147364041): remove this
2659func makeApexAvailableBaseline() map[string][]string {
2660 // The "Module separator"s below are employed to minimize merge conflicts.
2661 m := make(map[string][]string)
2662 //
2663 // Module separator
2664 //
2665 m["com.android.appsearch"] = []string{
2666 "icing-java-proto-lite",
2667 "libprotobuf-java-lite",
2668 }
2669 //
2670 // Module separator
2671 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002672 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002673 "android.hardware.audio.common@5.0",
2674 "android.hardware.bluetooth.a2dp@1.0",
2675 "android.hardware.bluetooth.audio@2.0",
2676 "android.hardware.bluetooth@1.0",
2677 "android.hardware.bluetooth@1.1",
2678 "android.hardware.graphics.bufferqueue@1.0",
2679 "android.hardware.graphics.bufferqueue@2.0",
2680 "android.hardware.graphics.common@1.0",
2681 "android.hardware.graphics.common@1.1",
2682 "android.hardware.graphics.common@1.2",
2683 "android.hardware.media@1.0",
2684 "android.hidl.safe_union@1.0",
2685 "android.hidl.token@1.0",
2686 "android.hidl.token@1.0-utils",
2687 "avrcp-target-service",
2688 "avrcp_headers",
2689 "bluetooth-protos-lite",
2690 "bluetooth.mapsapi",
2691 "com.android.vcard",
2692 "dnsresolver_aidl_interface-V2-java",
2693 "ipmemorystore-aidl-interfaces-V5-java",
2694 "ipmemorystore-aidl-interfaces-java",
2695 "internal_include_headers",
2696 "lib-bt-packets",
2697 "lib-bt-packets-avrcp",
2698 "lib-bt-packets-base",
2699 "libFraunhoferAAC",
2700 "libaudio-a2dp-hw-utils",
2701 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002702 "libbluetooth",
2703 "libbluetooth-types",
2704 "libbluetooth-types-header",
2705 "libbluetooth_gd",
2706 "libbluetooth_headers",
2707 "libbluetooth_jni",
2708 "libbt-audio-hal-interface",
2709 "libbt-bta",
2710 "libbt-common",
2711 "libbt-hci",
2712 "libbt-platform-protos-lite",
2713 "libbt-protos-lite",
2714 "libbt-sbc-decoder",
2715 "libbt-sbc-encoder",
2716 "libbt-stack",
2717 "libbt-utils",
2718 "libbtcore",
2719 "libbtdevice",
2720 "libbte",
2721 "libbtif",
2722 "libchrome",
2723 "libevent",
2724 "libfmq",
2725 "libg722codec",
2726 "libgui_headers",
2727 "libmedia_headers",
2728 "libmodpb64",
2729 "libosi",
2730 "libstagefright_foundation_headers",
2731 "libstagefright_headers",
2732 "libstatslog",
2733 "libstatssocket",
2734 "libtinyxml2",
2735 "libudrv-uipc",
2736 "libz",
2737 "media_plugin_headers",
2738 "net-utils-services-common",
2739 "netd_aidl_interface-unstable-java",
2740 "netd_event_listener_interface-java",
2741 "netlink-client",
2742 "networkstack-client",
2743 "sap-api-java-static",
2744 "services.net",
2745 }
2746 //
2747 // Module separator
2748 //
2749 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2750 //
2751 // Module separator
2752 //
2753 m["com.android.extservices"] = []string{
2754 "error_prone_annotations",
2755 "ExtServices-core",
2756 "ExtServices",
2757 "libtextclassifier-java",
2758 "libz_current",
2759 "textclassifier-statsd",
2760 "TextClassifierNotificationLibNoManifest",
2761 "TextClassifierServiceLibNoManifest",
2762 }
2763 //
2764 // Module separator
2765 //
2766 m["com.android.neuralnetworks"] = []string{
2767 "android.hardware.neuralnetworks@1.0",
2768 "android.hardware.neuralnetworks@1.1",
2769 "android.hardware.neuralnetworks@1.2",
2770 "android.hardware.neuralnetworks@1.3",
2771 "android.hidl.allocator@1.0",
2772 "android.hidl.memory.token@1.0",
2773 "android.hidl.memory@1.0",
2774 "android.hidl.safe_union@1.0",
2775 "libarect",
2776 "libbuildversion",
2777 "libmath",
2778 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002779 }
2780 //
2781 // Module separator
2782 //
2783 m["com.android.media"] = []string{
2784 "android.frameworks.bufferhub@1.0",
2785 "android.hardware.cas.native@1.0",
2786 "android.hardware.cas@1.0",
2787 "android.hardware.configstore-utils",
2788 "android.hardware.configstore@1.0",
2789 "android.hardware.configstore@1.1",
2790 "android.hardware.graphics.allocator@2.0",
2791 "android.hardware.graphics.allocator@3.0",
2792 "android.hardware.graphics.bufferqueue@1.0",
2793 "android.hardware.graphics.bufferqueue@2.0",
2794 "android.hardware.graphics.common@1.0",
2795 "android.hardware.graphics.common@1.1",
2796 "android.hardware.graphics.common@1.2",
2797 "android.hardware.graphics.mapper@2.0",
2798 "android.hardware.graphics.mapper@2.1",
2799 "android.hardware.graphics.mapper@3.0",
2800 "android.hardware.media.omx@1.0",
2801 "android.hardware.media@1.0",
2802 "android.hidl.allocator@1.0",
2803 "android.hidl.memory.token@1.0",
2804 "android.hidl.memory@1.0",
2805 "android.hidl.token@1.0",
2806 "android.hidl.token@1.0-utils",
2807 "bionic_libc_platform_headers",
2808 "exoplayer2-extractor",
2809 "exoplayer2-extractor-annotation-stubs",
2810 "gl_headers",
2811 "jsr305",
2812 "libEGL",
2813 "libEGL_blobCache",
2814 "libEGL_getProcAddress",
2815 "libFLAC",
2816 "libFLAC-config",
2817 "libFLAC-headers",
2818 "libGLESv2",
2819 "libaacextractor",
2820 "libamrextractor",
2821 "libarect",
2822 "libaudio_system_headers",
2823 "libaudioclient",
2824 "libaudioclient_headers",
2825 "libaudiofoundation",
2826 "libaudiofoundation_headers",
2827 "libaudiomanager",
2828 "libaudiopolicy",
2829 "libaudioutils",
2830 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002831 "libbluetooth-types-header",
2832 "libbufferhub",
2833 "libbufferhub_headers",
2834 "libbufferhubqueue",
2835 "libc_malloc_debug_backtrace",
2836 "libcamera_client",
2837 "libcamera_metadata",
2838 "libdvr_headers",
2839 "libexpat",
2840 "libfifo",
2841 "libflacextractor",
2842 "libgrallocusage",
2843 "libgraphicsenv",
2844 "libgui",
2845 "libgui_headers",
2846 "libhardware_headers",
2847 "libinput",
2848 "liblzma",
2849 "libmath",
2850 "libmedia",
2851 "libmedia_codeclist",
2852 "libmedia_headers",
2853 "libmedia_helper",
2854 "libmedia_helper_headers",
2855 "libmedia_midiiowrapper",
2856 "libmedia_omx",
2857 "libmediautils",
2858 "libmidiextractor",
2859 "libmkvextractor",
2860 "libmp3extractor",
2861 "libmp4extractor",
2862 "libmpeg2extractor",
2863 "libnativebase_headers",
2864 "libnativewindow_headers",
2865 "libnblog",
2866 "liboggextractor",
2867 "libpackagelistparser",
2868 "libpdx",
2869 "libpdx_default_transport",
2870 "libpdx_headers",
2871 "libpdx_uds",
2872 "libprocinfo",
2873 "libspeexresampler",
2874 "libspeexresampler",
2875 "libstagefright_esds",
2876 "libstagefright_flacdec",
2877 "libstagefright_flacdec",
2878 "libstagefright_foundation",
2879 "libstagefright_foundation_headers",
2880 "libstagefright_foundation_without_imemory",
2881 "libstagefright_headers",
2882 "libstagefright_id3",
2883 "libstagefright_metadatautils",
2884 "libstagefright_mpeg2extractor",
2885 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002886 "libui",
2887 "libui_headers",
2888 "libunwindstack",
2889 "libvibrator",
2890 "libvorbisidec",
2891 "libwavextractor",
2892 "libwebm",
2893 "media_ndk_headers",
2894 "media_plugin_headers",
2895 "updatable-media",
2896 }
2897 //
2898 // Module separator
2899 //
2900 m["com.android.media.swcodec"] = []string{
2901 "android.frameworks.bufferhub@1.0",
2902 "android.hardware.common-ndk_platform",
2903 "android.hardware.configstore-utils",
2904 "android.hardware.configstore@1.0",
2905 "android.hardware.configstore@1.1",
2906 "android.hardware.graphics.allocator@2.0",
2907 "android.hardware.graphics.allocator@3.0",
2908 "android.hardware.graphics.allocator@4.0",
2909 "android.hardware.graphics.bufferqueue@1.0",
2910 "android.hardware.graphics.bufferqueue@2.0",
2911 "android.hardware.graphics.common-ndk_platform",
2912 "android.hardware.graphics.common@1.0",
2913 "android.hardware.graphics.common@1.1",
2914 "android.hardware.graphics.common@1.2",
2915 "android.hardware.graphics.mapper@2.0",
2916 "android.hardware.graphics.mapper@2.1",
2917 "android.hardware.graphics.mapper@3.0",
2918 "android.hardware.graphics.mapper@4.0",
2919 "android.hardware.media.bufferpool@2.0",
2920 "android.hardware.media.c2@1.0",
2921 "android.hardware.media.c2@1.1",
2922 "android.hardware.media.omx@1.0",
2923 "android.hardware.media@1.0",
2924 "android.hardware.media@1.0",
2925 "android.hidl.memory.token@1.0",
2926 "android.hidl.memory@1.0",
2927 "android.hidl.safe_union@1.0",
2928 "android.hidl.token@1.0",
2929 "android.hidl.token@1.0-utils",
2930 "libEGL",
2931 "libFLAC",
2932 "libFLAC-config",
2933 "libFLAC-headers",
2934 "libFraunhoferAAC",
2935 "libLibGuiProperties",
2936 "libarect",
2937 "libaudio_system_headers",
2938 "libaudioutils",
2939 "libaudioutils",
2940 "libaudioutils_fixedfft",
2941 "libavcdec",
2942 "libavcenc",
2943 "libavservices_minijail",
2944 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002945 "libbinderthreadstateutils",
2946 "libbluetooth-types-header",
2947 "libbufferhub_headers",
2948 "libcodec2",
2949 "libcodec2_headers",
2950 "libcodec2_hidl@1.0",
2951 "libcodec2_hidl@1.1",
2952 "libcodec2_internal",
2953 "libcodec2_soft_aacdec",
2954 "libcodec2_soft_aacenc",
2955 "libcodec2_soft_amrnbdec",
2956 "libcodec2_soft_amrnbenc",
2957 "libcodec2_soft_amrwbdec",
2958 "libcodec2_soft_amrwbenc",
2959 "libcodec2_soft_av1dec_gav1",
2960 "libcodec2_soft_avcdec",
2961 "libcodec2_soft_avcenc",
2962 "libcodec2_soft_common",
2963 "libcodec2_soft_flacdec",
2964 "libcodec2_soft_flacenc",
2965 "libcodec2_soft_g711alawdec",
2966 "libcodec2_soft_g711mlawdec",
2967 "libcodec2_soft_gsmdec",
2968 "libcodec2_soft_h263dec",
2969 "libcodec2_soft_h263enc",
2970 "libcodec2_soft_hevcdec",
2971 "libcodec2_soft_hevcenc",
2972 "libcodec2_soft_mp3dec",
2973 "libcodec2_soft_mpeg2dec",
2974 "libcodec2_soft_mpeg4dec",
2975 "libcodec2_soft_mpeg4enc",
2976 "libcodec2_soft_opusdec",
2977 "libcodec2_soft_opusenc",
2978 "libcodec2_soft_rawdec",
2979 "libcodec2_soft_vorbisdec",
2980 "libcodec2_soft_vp8dec",
2981 "libcodec2_soft_vp8enc",
2982 "libcodec2_soft_vp9dec",
2983 "libcodec2_soft_vp9enc",
2984 "libcodec2_vndk",
2985 "libdvr_headers",
2986 "libfmq",
2987 "libfmq",
2988 "libgav1",
2989 "libgralloctypes",
2990 "libgrallocusage",
2991 "libgraphicsenv",
2992 "libgsm",
2993 "libgui_bufferqueue_static",
2994 "libgui_headers",
2995 "libhardware",
2996 "libhardware_headers",
2997 "libhevcdec",
2998 "libhevcenc",
2999 "libion",
3000 "libjpeg",
3001 "liblzma",
3002 "libmath",
3003 "libmedia_codecserviceregistrant",
3004 "libmedia_headers",
3005 "libmpeg2dec",
3006 "libnativebase_headers",
3007 "libnativewindow_headers",
3008 "libpdx_headers",
3009 "libscudo_wrapper",
3010 "libsfplugin_ccodec_utils",
3011 "libspeexresampler",
3012 "libstagefright_amrnb_common",
3013 "libstagefright_amrnbdec",
3014 "libstagefright_amrnbenc",
3015 "libstagefright_amrwbdec",
3016 "libstagefright_amrwbenc",
3017 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003018 "libstagefright_enc_common",
3019 "libstagefright_flacdec",
3020 "libstagefright_foundation",
3021 "libstagefright_foundation_headers",
3022 "libstagefright_headers",
3023 "libstagefright_m4vh263dec",
3024 "libstagefright_m4vh263enc",
3025 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003026 "libui",
3027 "libui_headers",
3028 "libunwindstack",
3029 "libvorbisidec",
3030 "libvpx",
3031 "libyuv",
3032 "libyuv_static",
3033 "media_ndk_headers",
3034 "media_plugin_headers",
3035 "mediaswcodec",
3036 }
3037 //
3038 // Module separator
3039 //
3040 m["com.android.mediaprovider"] = []string{
3041 "MediaProvider",
3042 "MediaProviderGoogle",
3043 "fmtlib_ndk",
3044 "libbase_ndk",
3045 "libfuse",
3046 "libfuse_jni",
3047 }
3048 //
3049 // Module separator
3050 //
3051 m["com.android.permission"] = []string{
3052 "car-ui-lib",
3053 "iconloader",
3054 "kotlin-annotations",
3055 "kotlin-stdlib",
3056 "kotlin-stdlib-jdk7",
3057 "kotlin-stdlib-jdk8",
3058 "kotlinx-coroutines-android",
3059 "kotlinx-coroutines-android-nodeps",
3060 "kotlinx-coroutines-core",
3061 "kotlinx-coroutines-core-nodeps",
3062 "permissioncontroller-statsd",
3063 "GooglePermissionController",
3064 "PermissionController",
3065 "SettingsLibActionBarShadow",
3066 "SettingsLibAppPreference",
3067 "SettingsLibBarChartPreference",
3068 "SettingsLibLayoutPreference",
3069 "SettingsLibProgressBar",
3070 "SettingsLibSearchWidget",
3071 "SettingsLibSettingsTheme",
3072 "SettingsLibRestrictedLockUtils",
3073 "SettingsLibHelpUtils",
3074 }
3075 //
3076 // Module separator
3077 //
3078 m["com.android.runtime"] = []string{
3079 "bionic_libc_platform_headers",
3080 "libarm-optimized-routines-math",
3081 "libc_aeabi",
3082 "libc_bionic",
3083 "libc_bionic_ndk",
3084 "libc_bootstrap",
3085 "libc_common",
3086 "libc_common_shared",
3087 "libc_common_static",
3088 "libc_dns",
3089 "libc_dynamic_dispatch",
3090 "libc_fortify",
3091 "libc_freebsd",
3092 "libc_freebsd_large_stack",
3093 "libc_gdtoa",
3094 "libc_init_dynamic",
3095 "libc_init_static",
3096 "libc_jemalloc_wrapper",
3097 "libc_netbsd",
3098 "libc_nomalloc",
3099 "libc_nopthread",
3100 "libc_openbsd",
3101 "libc_openbsd_large_stack",
3102 "libc_openbsd_ndk",
3103 "libc_pthread",
3104 "libc_static_dispatch",
3105 "libc_syscalls",
3106 "libc_tzcode",
3107 "libc_unwind_static",
3108 "libdebuggerd",
3109 "libdebuggerd_common_headers",
3110 "libdebuggerd_handler_core",
3111 "libdebuggerd_handler_fallback",
3112 "libdl_static",
3113 "libjemalloc5",
3114 "liblinker_main",
3115 "liblinker_malloc",
3116 "liblz4",
3117 "liblzma",
3118 "libprocinfo",
3119 "libpropertyinfoparser",
3120 "libscudo",
3121 "libstdc++",
3122 "libsystemproperties",
3123 "libtombstoned_client_static",
3124 "libunwindstack",
3125 "libz",
3126 "libziparchive",
3127 }
3128 //
3129 // Module separator
3130 //
3131 m["com.android.tethering"] = []string{
3132 "android.hardware.tetheroffload.config-V1.0-java",
3133 "android.hardware.tetheroffload.control-V1.0-java",
3134 "android.hidl.base-V1.0-java",
3135 "libcgrouprc",
3136 "libcgrouprc_format",
3137 "libtetherutilsjni",
3138 "libvndksupport",
3139 "net-utils-framework-common",
3140 "netd_aidl_interface-V3-java",
3141 "netlink-client",
3142 "networkstack-aidl-interfaces-java",
3143 "tethering-aidl-interfaces-java",
3144 "TetheringApiCurrentLib",
3145 }
3146 //
3147 // Module separator
3148 //
3149 m["com.android.wifi"] = []string{
3150 "PlatformProperties",
3151 "android.hardware.wifi-V1.0-java",
3152 "android.hardware.wifi-V1.0-java-constants",
3153 "android.hardware.wifi-V1.1-java",
3154 "android.hardware.wifi-V1.2-java",
3155 "android.hardware.wifi-V1.3-java",
3156 "android.hardware.wifi-V1.4-java",
3157 "android.hardware.wifi.hostapd-V1.0-java",
3158 "android.hardware.wifi.hostapd-V1.1-java",
3159 "android.hardware.wifi.hostapd-V1.2-java",
3160 "android.hardware.wifi.supplicant-V1.0-java",
3161 "android.hardware.wifi.supplicant-V1.1-java",
3162 "android.hardware.wifi.supplicant-V1.2-java",
3163 "android.hardware.wifi.supplicant-V1.3-java",
3164 "android.hidl.base-V1.0-java",
3165 "android.hidl.manager-V1.0-java",
3166 "android.hidl.manager-V1.1-java",
3167 "android.hidl.manager-V1.2-java",
3168 "bouncycastle-unbundled",
3169 "dnsresolver_aidl_interface-V2-java",
3170 "error_prone_annotations",
3171 "framework-wifi-pre-jarjar",
3172 "framework-wifi-util-lib",
3173 "ipmemorystore-aidl-interfaces-V3-java",
3174 "ipmemorystore-aidl-interfaces-java",
3175 "ksoap2",
3176 "libnanohttpd",
3177 "libwifi-jni",
3178 "net-utils-services-common",
3179 "netd_aidl_interface-V2-java",
3180 "netd_aidl_interface-unstable-java",
3181 "netd_event_listener_interface-java",
3182 "netlink-client",
3183 "networkstack-client",
3184 "services.net",
3185 "wifi-lite-protos",
3186 "wifi-nano-protos",
3187 "wifi-service-pre-jarjar",
3188 "wifi-service-resources",
3189 }
3190 //
3191 // Module separator
3192 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003193 m["com.android.os.statsd"] = []string{
3194 "libstatssocket",
3195 }
3196 //
3197 // Module separator
3198 //
3199 m[android.AvailableToAnyApex] = []string{
3200 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3201 "androidx",
3202 "androidx-constraintlayout_constraintlayout",
3203 "androidx-constraintlayout_constraintlayout-nodeps",
3204 "androidx-constraintlayout_constraintlayout-solver",
3205 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3206 "com.google.android.material_material",
3207 "com.google.android.material_material-nodeps",
3208
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003209 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003210 "libprofile-clang-extras",
3211 "libprofile-clang-extras_ndk",
3212 "libprofile-extras",
3213 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003214 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003215 }
3216 return m
3217}
3218
3219func init() {
3220 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
3221 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
3222}
3223
3224func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
3225 rules := make([]android.Rule, 0, len(modules_packages))
3226 for module_name, module_packages := range modules_packages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003227 permittedPackagesRule := android.NeverAllow().
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003228 BootclasspathJar().
3229 With("apex_available", module_name).
3230 WithMatcher("permitted_packages", android.NotInList(module_packages)).
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003231 WithMatcher("min_sdk_version", android.LessThanSdkVersion("Tiramisu")).
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003232 Because("jars that are part of the " + module_name +
Andrei Onead967aee2022-01-19 15:36:40 +00003233 " module may only use these package prefixes: " + strings.Join(module_packages, ",") +
3234 " with min_sdk < T. Please consider the following alternatives:\n" +
3235 " 1. If the offending code is from a statically linked library, consider " +
3236 "removing that dependency and using an alternative already in the " +
3237 "bootclasspath, or perhaps a shared library." +
3238 " 2. Move the offending code into an allowed package.\n" +
3239 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3240 "health implications of bundling that code, particularly if the offending jar " +
3241 "is part of the bootclasspath.")
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003242 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003243 }
3244 return rules
3245}
3246
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003247// 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 +09003248// Adding code to the bootclasspath in new packages will cause issues on module update.
3249func qModulesPackages() map[string][]string {
3250 return map[string][]string{
3251 "com.android.conscrypt": []string{
3252 "android.net.ssl",
3253 "com.android.org.conscrypt",
3254 },
3255 "com.android.media": []string{
3256 "android.media",
3257 },
3258 }
3259}
3260
Remi NGUYEN VAN1fdd6ca2021-12-02 19:39:35 +09003261// 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 +09003262// Adding code to the bootclasspath in new packages will cause issues on module update.
3263func rModulesPackages() map[string][]string {
3264 return map[string][]string{
3265 "com.android.mediaprovider": []string{
3266 "android.provider",
3267 },
3268 "com.android.permission": []string{
3269 "android.permission",
3270 "android.app.role",
3271 "com.android.permission",
3272 "com.android.role",
3273 },
3274 "com.android.sdkext": []string{
3275 "android.os.ext",
3276 },
3277 "com.android.os.statsd": []string{
3278 "android.app",
3279 "android.os",
3280 "android.util",
3281 "com.android.internal.statsd",
3282 "com.android.server.stats",
3283 },
3284 "com.android.wifi": []string{
3285 "com.android.server.wifi",
3286 "com.android.wifi.x",
3287 "android.hardware.wifi",
3288 "android.net.wifi",
3289 },
3290 "com.android.tethering": []string{
3291 "android.net",
3292 },
3293 }
3294}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003295
3296// For Bazel / bp2build
3297
3298type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003299 Manifest bazel.LabelAttribute
3300 Android_manifest bazel.LabelAttribute
3301 File_contexts bazel.LabelAttribute
3302 Key bazel.LabelAttribute
3303 Certificate bazel.LabelAttribute
3304 Min_sdk_version *string
3305 Updatable bazel.BoolAttribute
3306 Installable bazel.BoolAttribute
3307 Binaries bazel.LabelListAttribute
3308 Prebuilts bazel.LabelListAttribute
3309 Native_shared_libs_32 bazel.LabelListAttribute
3310 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003311 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003312}
3313
3314type convertedNativeSharedLibs struct {
3315 Native_shared_libs_32 bazel.LabelListAttribute
3316 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003317}
3318
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003319// ConvertWithBp2build performs bp2build conversion of an apex
3320func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3321 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003322 if ctx.ModuleType() != "apex" {
3323 return
3324 }
3325
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003326 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003327 if a.properties.Manifest != nil {
3328 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003329 }
3330
3331 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003332 if a.properties.AndroidManifest != nil {
3333 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003334 }
3335
3336 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003337 if a.properties.File_contexts != nil {
3338 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003339 }
3340
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003341 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003342 if a.properties.Min_sdk_version != nil {
3343 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003344 }
3345
3346 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003347 if a.overridableProperties.Key != nil {
3348 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003349 }
3350
3351 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003352 if a.overridableProperties.Certificate != nil {
3353 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003354 }
3355
Yu Liu4ae55d12022-01-05 17:17:23 -08003356 nativeSharedLibs := &convertedNativeSharedLibs{
3357 Native_shared_libs_32: bazel.LabelListAttribute{},
3358 Native_shared_libs_64: bazel.LabelListAttribute{},
3359 }
3360 compileMultilib := "both"
3361 if a.CompileMultilib() != nil {
3362 compileMultilib = *a.CompileMultilib()
3363 }
3364
3365 // properties.Native_shared_libs is treated as "both"
3366 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3367 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3368 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3369 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3370 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003371
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003372 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003373 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3374 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3375
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003376 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003377 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003378
3379 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003380 if a.properties.Updatable != nil {
3381 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003382 }
3383
3384 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003385 if a.properties.Installable != nil {
3386 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003387 }
3388
Wei Lif034cb42022-01-19 15:54:31 -08003389 var compressibleAttribute bazel.BoolAttribute
3390 if a.overridableProperties.Compressible != nil {
3391 compressibleAttribute.Value = a.overridableProperties.Compressible
3392 }
3393
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003394 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003395 Manifest: manifestLabelAttribute,
3396 Android_manifest: androidManifestLabelAttribute,
3397 File_contexts: fileContextsLabelAttribute,
3398 Min_sdk_version: minSdkVersion,
3399 Key: keyLabelAttribute,
3400 Certificate: certificateLabelAttribute,
3401 Updatable: updatableAttribute,
3402 Installable: installableAttribute,
3403 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3404 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3405 Binaries: binariesLabelListAttribute,
3406 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003407 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003408 }
3409
3410 props := bazel.BazelTargetModuleProperties{
3411 Rule_class: "apex",
3412 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3413 }
3414
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003415 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003416}
Yu Liu4ae55d12022-01-05 17:17:23 -08003417
3418// The following conversions are based on this table where the rows are the compile_multilib
3419// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3420// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3421// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3422// should not be compiled.
3423// multib/compile_multilib, 32, 64, both, first
3424// 32, 32/32, none/none, 32/32, none/32
3425// 64, none/none, 64/none, 64/none, 64/none
3426// both, 32/32, 64/none, 32&64/32, 64/32
3427// first, 32/32, 64/none, 64/32, 64/32
3428
3429func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3430 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3431 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3432 switch compileMultilb {
3433 case "both", "32":
3434 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3435 case "first":
3436 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3437 case "64":
3438 // Incompatible, ignore
3439 default:
3440 invalidCompileMultilib(ctx, compileMultilb)
3441 }
3442}
3443
3444func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3445 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3446 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3447 switch compileMultilb {
3448 case "both", "64", "first":
3449 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3450 case "32":
3451 // Incompatible, ignore
3452 default:
3453 invalidCompileMultilib(ctx, compileMultilb)
3454 }
3455}
3456
3457func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3458 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3459 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3460 switch compileMultilb {
3461 case "both":
3462 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3463 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3464 case "first":
3465 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3466 case "32":
3467 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3468 case "64":
3469 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3470 default:
3471 invalidCompileMultilib(ctx, compileMultilb)
3472 }
3473}
3474
3475func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3476 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3477 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3478 switch compileMultilb {
3479 case "both", "first":
3480 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3481 case "32":
3482 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3483 case "64":
3484 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3485 default:
3486 invalidCompileMultilib(ctx, compileMultilb)
3487 }
3488}
3489
3490func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3491 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3492 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3493}
3494
3495func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3496 list := bazel.LabelListAttribute{}
3497 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3498 nativeSharedLibs.Native_shared_libs_32.Append(list)
3499}
3500
3501func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3502 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3503 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3504}
3505
3506func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3507 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3508 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3509}
3510
3511func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3512 labelListAttr *bazel.LabelListAttribute) {
3513 list := bazel.LabelListAttribute{}
3514 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3515 labelListAttr.Append(list)
3516}
3517
3518func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3519 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3520}