blob: f16b72d96470c1169d027fedc4c29339705f5bd5 [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"
Inseob Kim5eb7ee92022-04-27 10:30:34 +090036 "android/soong/multitree"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070037 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090038 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070039 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090040)
41
Jiyong Park8e6d52f2020-11-19 14:37:47 +090042func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000043 registerApexBuildComponents(android.InitRegistrationContext)
44}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090045
Paul Duffin667893c2021-03-09 22:34:13 +000046func registerApexBuildComponents(ctx android.RegistrationContext) {
47 ctx.RegisterModuleType("apex", BundleFactory)
48 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
49 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
50 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
51 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
52 ctx.RegisterModuleType("override_apex", overrideApexFactory)
53 ctx.RegisterModuleType("apex_set", apexSetFactory)
54
Paul Duffin5dda3e32021-05-05 14:13:27 +010055 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000056 ctx.PreDepsMutators(RegisterPreDepsMutators)
57 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090058}
59
Paul Duffin5dda3e32021-05-05 14:13:27 +010060func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
61 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
62}
63
Jiyong Park8e6d52f2020-11-19 14:37:47 +090064func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
65 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
66 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
67}
68
69func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000070 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090071 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
72 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
73 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010074 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
75 // it should create a platform variant.
76 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090077 ctx.BottomUp("apex", apexMutator).Parallel()
78 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
79 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
Spandan Das66773252022-01-15 00:23:18 +000080 // Register after apex_info mutator so that it can use ApexVariationName
81 ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090082}
83
84type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090085 // Json manifest file describing meta info of this APEX bundle. Refer to
86 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090087 Manifest *string `android:"path"`
88
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090089 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
90 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090091 AndroidManifest *string `android:"path"`
92
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090093 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
94 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090095 Apex_name *string
96
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090097 // Determines the file contexts file for setting the security contexts to files in this APEX
98 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
99 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900100 File_contexts *string `android:"path"`
101
Jiyong Park038e8522021-12-13 23:56:35 +0900102 // Path to the canned fs config file for customizing file's uid/gid/mod/capabilities. The
103 // format is /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where path_or_glob is a
104 // path or glob pattern for a file or set of files, uid/gid are numerial values of user ID
105 // and group ID, mode is octal value for the file mode, and cap is hexadecimal value for the
106 // capability. If this property is not set, or a file is missing in the file, default config
107 // is used.
108 Canned_fs_config *string `android:"path"`
109
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900110 ApexNativeDependencies
111
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900112 Multilib apexMultilibProperties
113
Sundong Ahn80c04892021-11-23 00:57:19 +0000114 // List of sh binaries that are embedded inside this APEX bundle.
115 Sh_binaries []string
116
Paul Duffin3abc1742021-03-15 19:32:23 +0000117 // List of platform_compat_config files that are embedded inside this APEX bundle.
118 Compat_configs []string
119
Jiyong Park12a719c2021-01-07 15:31:24 +0900120 // List of filesystem images that are embedded inside this APEX bundle.
121 Filesystems []string
122
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900123 // The minimum SDK version that this APEX must support at minimum. This is usually set to
124 // the SDK version that the APEX was first introduced.
125 Min_sdk_version *string
126
127 // Whether this APEX is considered updatable or not. When set to true, this will enforce
128 // additional rules for making sure that the APEX is truly updatable. To be updatable,
129 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000130 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900131 Updatable *bool
132
Jiyong Parkf4020582021-11-29 12:37:10 +0900133 // Marks that this APEX is designed to be updatable in the future, although it's not
134 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
135 // updatable APEXes. Currently, this disables the size optimization, so that the size of
136 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
137 // false.
138 Future_updatable *bool
139
Jiyong Park1bc84122021-06-22 20:23:05 +0900140 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
141 // false`. Default is false.
142 Platform_apis *bool
143
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900144 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
145 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900146 Installable *bool
147
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900148 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
149 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
150 Use_vndk_as_stable *bool
151
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000152 // Whether this is multi-installed APEX should skip installing symbol files.
153 // Multi-installed APEXes share the same apex_name and are installed at the same time.
154 // Default is false.
155 //
156 // Should be set to true for all multi-installed APEXes except the singular
157 // default version within the multi-installed group.
158 // Only the default version can install symbol files in $(PRODUCT_OUT}/apex,
159 // or else conflicting build rules may be created.
160 Multi_install_skip_symbol_files *bool
161
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900162 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
163 // `name#version` or `name` which is an alias for `name#current`. If left empty,
164 // `platform#current` is implied. This value affects all modules included in this APEX. In
165 // other words, they are also built with the SDKs specified here.
166 Uses_sdks []string
167
168 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
169 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
170 // container. When set to zip, contents are stored in a zip container directly. This type is
171 // mostly for host-side debugging. When set to both, the two types are both built. Default
172 // is 'image'.
173 Payload_type *string
174
Huang Jianan13cac632021-08-02 15:02:17 +0800175 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4', 'f2fs'
176 // or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900177 Payload_fs_type *string
178
179 // For telling the APEX to ignore special handling for system libraries such as bionic.
180 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900181 Ignore_system_library_special_case *bool
182
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100183 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100184 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100185 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900186
187 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
188 // used in tests.
189 Test_only_unsigned_payload *bool
190
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000191 // Whenever apex should be compressed, regardless of product flag used. Should be only
192 // used in tests.
193 Test_only_force_compression *bool
194
Jooyung Han09c11ad2021-10-27 03:45:31 +0900195 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
196 // with the tool to sign payload contents.
197 Custom_sign_tool *string
198
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100199 // Canonical name of this APEX bundle. Used to determine the path to the
200 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
201 // apex mutator variations. For override_apex modules, this is the name of the
202 // overridden base module.
203 ApexVariationName string `blueprint:"mutated"`
204
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900205 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900206
207 // List of sanitizer names that this APEX is enabled for
208 SanitizerNames []string `blueprint:"mutated"`
209
210 PreventInstall bool `blueprint:"mutated"`
211
212 HideFromMake bool `blueprint:"mutated"`
213
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900214 // Internal package method for this APEX. When payload_type is image, this can be either
215 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
216 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900217 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900218}
219
220type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900221 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900222 Native_shared_libs []string
223
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900224 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900225 Jni_libs []string
226
Jiyong Park99644e92020-11-17 22:21:02 +0900227 // List of rust dyn libraries
228 Rust_dyn_libs []string
229
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900230 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900231 Binaries []string
232
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900233 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900234 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900235
236 // List of filesystem images that are embedded inside this APEX bundle.
237 Filesystems []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900238}
239
240type apexMultilibProperties struct {
241 // Native dependencies whose compile_multilib is "first"
242 First ApexNativeDependencies
243
244 // Native dependencies whose compile_multilib is "both"
245 Both ApexNativeDependencies
246
247 // Native dependencies whose compile_multilib is "prefer32"
248 Prefer32 ApexNativeDependencies
249
250 // Native dependencies whose compile_multilib is "32"
251 Lib32 ApexNativeDependencies
252
253 // Native dependencies whose compile_multilib is "64"
254 Lib64 ApexNativeDependencies
255}
256
257type apexTargetBundleProperties struct {
258 Target struct {
259 // Multilib properties only for android.
260 Android struct {
261 Multilib apexMultilibProperties
262 }
263
264 // Multilib properties only for host.
265 Host struct {
266 Multilib apexMultilibProperties
267 }
268
269 // Multilib properties only for host linux_bionic.
270 Linux_bionic struct {
271 Multilib apexMultilibProperties
272 }
273
274 // Multilib properties only for host linux_glibc.
275 Linux_glibc struct {
276 Multilib apexMultilibProperties
277 }
278 }
279}
280
Jiyong Park59140302020-12-14 18:44:04 +0900281type apexArchBundleProperties struct {
282 Arch struct {
283 Arm struct {
284 ApexNativeDependencies
285 }
286 Arm64 struct {
287 ApexNativeDependencies
288 }
289 X86 struct {
290 ApexNativeDependencies
291 }
292 X86_64 struct {
293 ApexNativeDependencies
294 }
295 }
296}
297
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900298// These properties can be used in override_apex to override the corresponding properties in the
299// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900300type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900301 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900302 Apps []string
303
Daniel Norman5a3ce132021-08-26 15:44:43 -0700304 // List of prebuilt files that are embedded inside this APEX bundle.
305 Prebuilts []string
306
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900307 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900308 Rros []string
309
markchien7c803b82021-08-26 22:10:06 +0800310 // List of BPF programs inside this APEX bundle.
311 Bpfs []string
312
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900313 // List of bootclasspath fragments that are embedded inside this APEX bundle.
314 Bootclasspath_fragments []string
315
316 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
317 Systemserverclasspath_fragments []string
318
319 // List of java libraries that are embedded inside this APEX bundle.
320 Java_libs []string
321
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900322 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
323 // Soong). This does not completely prevent installation of the overridden binaries, but if
324 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
325 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900326 Overrides []string
327
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900328 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900329 Logging_parent string
330
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900331 // Apex Container package name. Override value for attribute package:name in
332 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900333 Package_name string
334
335 // A txt file containing list of files that are allowed to be included in this APEX.
336 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700337
338 // Name of the apex_key module that provides the private key to sign this APEX bundle.
339 Key *string
340
341 // Specifies the certificate and the private key to sign the zip container of this APEX. If
342 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
343 // as the certificate and the private key, respectively. If this is ":module", then the
344 // certificate and the private key are provided from the android_app_certificate module
345 // named "module".
346 Certificate *string
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -0400347
348 // Whether this APEX can be compressed or not. Setting this property to false means this
349 // APEX will never be compressed. When set to true, APEX will be compressed if other
350 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
351 // Default: false.
352 Compressible *bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900353}
354
355type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900356 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900357 android.ModuleBase
358 android.DefaultableModuleBase
359 android.OverridableModuleBase
360 android.SdkBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400361 android.BazelModuleBase
Inseob Kim5eb7ee92022-04-27 10:30:34 +0900362 multitree.ExportableModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900364 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900365 properties apexBundleProperties
366 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900367 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900368 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900370
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900371 ///////////////////////////////////////////////////////////////////////////////////////////
372 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900373
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900374 // Keys for apex_paylaod.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800375 publicKeyFile android.Path
376 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900377
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900378 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800379 containerCertificateFile android.Path
380 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900382 // Flags for special variants of APEX
383 testApex bool
384 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900386 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
387 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900388 primaryApexType bool
389
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900390 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900391 suffix string
392
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900393 // File system type of apex_payload.img
394 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900395
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900396 // Whether to create symlink to the system file instead of having a file inside the apex or
397 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900398 linkToSystemLib bool
399
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900400 // List of files to be included in this APEX. This is filled in the first part of
401 // GenerateAndroidBuildActions.
402 filesInfo []apexFile
403
404 // List of other module names that should be installed when this APEX gets installed.
405 requiredDeps []string
406
407 ///////////////////////////////////////////////////////////////////////////////////////////
408 // Outputs (final and intermediates)
409
410 // Processed apex manifest in JSONson format (for Q)
411 manifestJsonOut android.WritablePath
412
413 // Processed apex manifest in PB format (for R+)
414 manifestPbOut android.WritablePath
415
416 // Processed file_contexts files
417 fileContexts android.WritablePath
418
Bob Badourde6a0872022-04-01 18:00:00 +0000419 // Path to notice file in html.gz format.
420 htmlGzNotice android.WritablePath
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900421
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900422 // The built APEX file. This is the main product.
Jooyung Hana6d36672022-02-24 13:58:07 +0900423 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900424 outputFile android.WritablePath
425
Jooyung Hana6d36672022-02-24 13:58:07 +0900426 // The built uncompressed .apex file.
427 outputApexFile android.WritablePath
428
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900429 // The built APEX file in app bundle format. This file is not directly installed to the
430 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
431 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
432 // system) to be merged into a single app bundle file that Play accepts. See
433 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
434 bundleModuleFile android.WritablePath
435
Colin Cross6340ea52021-11-04 12:01:18 -0700436 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900437 installDir android.InstallPath
438
Colin Cross6340ea52021-11-04 12:01:18 -0700439 // Path where this APEX was installed.
440 installedFile android.InstallPath
441
442 // Installed locations of symlinks for backward compatibility.
443 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900444
445 // Text file having the list of individual files that are included in this APEX. Used for
446 // debugging purpose.
447 installedFilesFile android.WritablePath
448
449 // List of module names that this APEX is including (to be shown via *-deps-info target).
450 // Used for debugging purpose.
451 android.ApexBundleDepsInfo
452
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900453 // Optional list of lint report zip files for apexes that contain java or app modules
454 lintReports android.Paths
455
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900456 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000457
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000458 isCompressed bool
459
sophiezc80a2b32020-11-12 16:39:19 +0000460 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700461 nativeApisUsedByModuleFile android.ModuleOutPath
462 nativeApisBackedByModuleFile android.ModuleOutPath
463 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800464
465 // Collect the module directory for IDE info in java/jdeps.go.
466 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900467}
468
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900469// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900470type apexFileClass int
471
Jooyung Han72bd2f82019-10-23 16:46:38 +0900472const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900473 app apexFileClass = iota
474 appSet
475 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900476 goBinary
477 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900478 nativeExecutable
479 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900480 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900481 pyBinary
482 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900483)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900484
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900485// apexFile represents a file in an APEX bundle. This is created during the first half of
486// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
487// of the function, this is used to create commands that copies the files into a staging directory,
488// where they are packaged into the APEX file. This struct is also used for creating Make modules
489// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900490type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900491 // buildFile is put in the installDir inside the APEX.
Bob Badourde6a0872022-04-01 18:00:00 +0000492 builtFile android.Path
493 installDir string
494 customStem string
495 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900496
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900497 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
498 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
499 // suffix>]
500 androidMkModuleName string // becomes LOCAL_MODULE
501 class apexFileClass // becomes LOCAL_MODULE_CLASS
502 moduleDir string // becomes LOCAL_PATH
503 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
504 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
505 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
506 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900507
508 jacocoReportClassesFile android.Path // only for javalibs and apps
509 lintDepSets java.LintDepSets // only for javalibs and apps
510 certificate java.Certificate // only for apps
511 overriddenPackageName string // only for apps
512
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900513 transitiveDep bool
514 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900515
Jiyong Park57621b22021-01-20 20:33:11 +0900516 multilib string
517
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900518 // TODO(jiyong): remove this
519 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900520}
521
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900522// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
524 ret := apexFile{
525 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900526 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900527 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900528 class: class,
529 module: module,
530 }
531 if module != nil {
532 ret.moduleDir = ctx.OtherModuleDir(module)
533 ret.requiredModuleNames = module.RequiredModuleNames()
534 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
535 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900536 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900537 }
538 return ret
539}
540
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900541func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900542 return af.builtFile != nil && af.builtFile.String() != ""
543}
544
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900545// apexRelativePath returns the relative path of the given path from the install directory of this
546// apexFile.
547// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900548func (af *apexFile) apexRelativePath(path string) string {
549 return filepath.Join(af.installDir, path)
550}
551
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900552// path returns path of this apex file relative to the APEX root
553func (af *apexFile) path() string {
554 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900555}
556
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900557// stem returns the base filename of this apex file
558func (af *apexFile) stem() string {
559 if af.customStem != "" {
560 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900561 }
562 return af.builtFile.Base()
563}
564
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900565// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
566func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900567 var ret []string
568 for _, symlink := range af.symlinks {
569 ret = append(ret, af.apexRelativePath(symlink))
570 }
571 return ret
572}
573
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900574// availableToPlatform tests whether this apexFile is from a module that can be installed to the
575// platform.
576func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900577 if af.module == nil {
578 return false
579 }
580 if am, ok := af.module.(android.ApexModule); ok {
581 return am.AvailableFor(android.AvailableToPlatform)
582 }
583 return false
584}
585
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900586////////////////////////////////////////////////////////////////////////////////////////////////////
587// Mutators
588//
589// Brief description about mutators for APEX. The following three mutators are the most important
590// ones.
591//
592// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
593// to the (direct) dependencies of this APEX bundle.
594//
Paul Duffin949abc02020-12-08 10:34:30 +0000595// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900596// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
597// modules are marked as being included in the APEX via BuildForApex().
598//
Paul Duffin949abc02020-12-08 10:34:30 +0000599// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
600// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900601
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900602type dependencyTag struct {
603 blueprint.BaseDependencyTag
604 name string
605
606 // Determines if the dependent will be part of the APEX payload. Can be false for the
607 // dependencies to the signing key module, etc.
608 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000609
610 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
611 // replacement. This is needed because some prebuilt modules do not provide all the information
612 // needed by the apex.
613 sourceOnly bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900614}
615
Paul Duffin8c535da2021-03-17 14:51:03 +0000616func (d dependencyTag) ReplaceSourceWithPrebuilt() bool {
617 return !d.sourceOnly
618}
619
620var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
621
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900622var (
Paul Duffin0b817782021-03-17 15:02:19 +0000623 androidAppTag = dependencyTag{name: "androidApp", payload: true}
624 bpfTag = dependencyTag{name: "bpf", payload: true}
625 certificateTag = dependencyTag{name: "certificate"}
626 executableTag = dependencyTag{name: "executable", payload: true}
627 fsTag = dependencyTag{name: "filesystem", payload: true}
Paul Duffin94f19632021-04-20 12:40:07 +0100628 bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true}
satayev333a1732021-05-17 21:35:26 +0100629 sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true}
Paul Duffin1b29e002021-03-16 15:06:54 +0000630 compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true}
Paul Duffin0b817782021-03-17 15:02:19 +0000631 javaLibTag = dependencyTag{name: "javaLib", payload: true}
632 jniLibTag = dependencyTag{name: "jniLib", payload: true}
633 keyTag = dependencyTag{name: "key"}
634 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
635 rroTag = dependencyTag{name: "rro", payload: true}
636 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
637 testForTag = dependencyTag{name: "test for"}
638 testTag = dependencyTag{name: "test", payload: true}
Sundong Ahn80c04892021-11-23 00:57:19 +0000639 shBinaryTag = dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640)
641
642// TODO(jiyong): shorten this function signature
643func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900644 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900645 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900646 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647
648 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900649 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900650 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
651 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900652 }
653
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900654 // Use *FarVariation* to be able to depend on modules having conflicting variations with
655 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
656 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900657 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900658 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900659 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
660 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900661 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park06711462021-02-15 17:54:43 +0900662 ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900663}
664
665func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900666 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900667 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
668 } else {
669 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
670 if ctx.Os().Bionic() {
671 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
672 } else {
673 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
674 }
675 }
676}
677
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900678// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
679// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
680func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
681 deviceConfig := ctx.DeviceConfig()
682 if a.vndkApex {
683 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900684 }
685
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900686 var prefix string
687 var vndkVersion string
688 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000689 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900690 prefix = cc.VendorVariationPrefix
691 vndkVersion = deviceConfig.VndkVersion()
692 } else if a.ProductSpecific() {
693 prefix = cc.ProductVariationPrefix
694 vndkVersion = deviceConfig.ProductVndkVersion()
695 }
696 }
697 if vndkVersion == "current" {
698 vndkVersion = deviceConfig.PlatformVndkVersion()
699 }
700 if vndkVersion != "" {
701 return prefix + vndkVersion
702 }
703
704 return android.CoreVariation // The usual case
705}
706
707func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900708 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
709 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
710 // each target os/architectures, appropriate dependencies are selected by their
711 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900712 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900713 imageVariation := a.getImageVariation(ctx)
714
715 a.combineProperties(ctx)
716
717 has32BitTarget := false
718 for _, target := range targets {
719 if target.Arch.ArchType.Multilib == "lib32" {
720 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000721 }
722 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900723 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900724 // Don't include artifacts for the host cross targets because there is no way for us
725 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900726 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900727 continue
728 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000729
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000731
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900732 // Add native modules targeting both ABIs. When multilib.* is omitted for
733 // native_shared_libs/jni_libs/tests, it implies multilib.both
734 depsList = append(depsList, a.properties.Multilib.Both)
735 depsList = append(depsList, ApexNativeDependencies{
736 Native_shared_libs: a.properties.Native_shared_libs,
737 Tests: a.properties.Tests,
738 Jni_libs: a.properties.Jni_libs,
739 Binaries: nil,
740 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900741
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900742 // Add native modules targeting the first ABI When multilib.* is omitted for
743 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900744 isPrimaryAbi := i == 0
745 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900746 depsList = append(depsList, a.properties.Multilib.First)
747 depsList = append(depsList, ApexNativeDependencies{
748 Native_shared_libs: nil,
749 Tests: nil,
750 Jni_libs: nil,
751 Binaries: a.properties.Binaries,
752 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900753 }
754
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900755 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900756 switch target.Arch.ArchType.Multilib {
757 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900758 depsList = append(depsList, a.properties.Multilib.Lib32)
759 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900760 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900761 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900762 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900763 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900764 }
765 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900766
Jiyong Park59140302020-12-14 18:44:04 +0900767 // Add native modules targeting a specific arch variant
768 switch target.Arch.ArchType {
769 case android.Arm:
770 depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies)
771 case android.Arm64:
772 depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies)
773 case android.X86:
774 depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies)
775 case android.X86_64:
776 depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies)
777 default:
778 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
779 }
780
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900781 for _, d := range depsList {
782 addDependenciesForNativeModules(ctx, d, target, imageVariation)
783 }
Sundong Ahn80c04892021-11-23 00:57:19 +0000784 ctx.AddFarVariationDependencies([]blueprint.Variation{
785 {Mutator: "os", Variation: target.OsVariation()},
786 {Mutator: "arch", Variation: target.ArchVariation()},
787 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900788 }
789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900790 // Common-arch dependencies come next
791 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Jiyong Park12a719c2021-01-07 15:31:24 +0900792 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000793 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900794
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900795 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
796 // This field currently isn't used.
797 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900798 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
799 if len(a.properties.Uses_sdks) > 0 {
800 sdkRefs := []android.SdkRef{}
801 for _, str := range a.properties.Uses_sdks {
802 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
803 sdkRefs = append(sdkRefs, parsed)
804 }
805 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100806 }
807}
808
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900809// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900810func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
811 if a.overridableProperties.Allowed_files != nil {
812 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100813 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900814
815 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
816 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800817 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900818 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Remi NGUYEN VANbe901722022-03-02 21:00:33 +0900819 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.overridableProperties.Bootclasspath_fragments...)
820 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.overridableProperties.Systemserverclasspath_fragments...)
821 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.overridableProperties.Java_libs...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700822 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
823 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
824 // regardless of the TARGET_PREFER_* setting. See b/144532908
825 arches := ctx.DeviceConfig().Arches()
826 if len(arches) != 0 {
827 archForPrebuiltEtc := arches[0]
828 for _, arch := range arches {
829 // Prefer 64-bit arch if there is any
830 if arch.ArchType.Multilib == "lib64" {
831 archForPrebuiltEtc = arch
832 break
833 }
834 }
835 ctx.AddFarVariationDependencies([]blueprint.Variation{
836 {Mutator: "os", Variation: ctx.Os().String()},
837 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
838 }, prebuiltTag, prebuilts...)
839 }
840 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700841
842 // Dependencies for signing
843 if String(a.overridableProperties.Key) == "" {
844 ctx.PropertyErrorf("key", "missing")
845 return
846 }
847 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
848
849 cert := android.SrcIsModule(a.getCertString(ctx))
850 if cert != "" {
851 ctx.AddDependency(ctx.Module(), certificateTag, cert)
852 // empty cert is not an error. Cert and private keys will be directly found under
853 // PRODUCT_DEFAULT_DEV_CERTIFICATE
854 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100855}
856
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900857type ApexBundleInfo struct {
858 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100859}
860
Paul Duffin949abc02020-12-08 10:34:30 +0000861var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862
Paul Duffina7d6a892020-12-07 17:39:59 +0000863var _ ApexInfoMutator = (*apexBundle)(nil)
864
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100865func (a *apexBundle) ApexVariationName() string {
866 return a.properties.ApexVariationName
867}
868
Paul Duffina7d6a892020-12-07 17:39:59 +0000869// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900870// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
871// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
872// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
873// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000874//
875// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
876// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
877// The apexMutator uses that list to create module variants for the apexes to which it belongs.
878// The relationship between module variants and apexes is not one-to-one as variants will be
879// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000880func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900881
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900882 // The VNDK APEX is special. For the APEX, the membership is described in a very different
883 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
884 // libraries are self-identified by their vndk.enabled properties. There is no need to run
885 // this mutator for the APEX as nothing will be collected. So, let's return fast.
886 if a.vndkApex {
887 return
888 }
889
890 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
891 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
892 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
893 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
894 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900895 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
896 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900897 if proptools.Bool(a.properties.Use_vndk_as_stable) {
898 if !useVndk {
899 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
900 }
901 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
902 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
903 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
904 }
905 })
906 if mctx.Failed() {
907 return
908 }
Jooyung Handf78e212020-07-22 15:54:47 +0900909 }
910
Colin Cross56a83212020-09-15 18:30:11 -0700911 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900912 am, ok := child.(android.ApexModule)
913 if !ok || !am.CanHaveApexVariants() {
914 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900915 }
Paul Duffin573989d2021-03-17 13:25:29 +0000916 depTag := mctx.OtherModuleDependencyTag(child)
917
918 // Check to see if the tag always requires that the child module has an apex variant for every
919 // apex variant of the parent module. If it does not then it is still possible for something
920 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
921 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
922 return true
923 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000924 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900925 return false
926 }
Jooyung Handf78e212020-07-22 15:54:47 +0900927 if excludeVndkLibs {
928 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
929 return false
930 }
931 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900932 // By default, all the transitive dependencies are collected, unless filtered out
933 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700934 return true
935 }
936
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900937 // Records whether a certain module is included in this apexBundle via direct dependency or
938 // inndirect dependency.
939 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700940 mctx.WalkDeps(func(child, parent android.Module) bool {
941 if !continueApexDepsWalk(child, parent) {
942 return false
943 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900944 // If the parent is apexBundle, this child is directly depended.
945 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900946 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700947 contents[depName] = contents[depName].Add(directDep)
948 return true
949 })
950
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900951 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900952 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700953 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
954 Contents: apexContents,
955 })
956
Jooyung Haned124c32021-01-26 11:43:46 +0900957 minSdkVersion := a.minSdkVersion(mctx)
958 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
959 if minSdkVersion.IsNone() {
960 minSdkVersion = android.FutureApiLevel
961 }
962
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900963 // This is the main part of this mutator. Mark the collected dependencies that they need to
964 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +0900965
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100966 apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo
967 a.properties.ApexVariationName = apexVariationName
Colin Cross56a83212020-09-15 18:30:11 -0700968 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100969 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +0900970 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -0700971 RequiredSdks: a.RequiredSdks(),
972 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +0900973 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100974 InApexVariants: []string{apexVariationName},
975 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -0700976 ApexContents: []*android.ApexContents{apexContents},
977 }
Colin Cross56a83212020-09-15 18:30:11 -0700978 mctx.WalkDeps(func(child, parent android.Module) bool {
979 if !continueApexDepsWalk(child, parent) {
980 return false
981 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900982 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900983 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900984 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900985}
986
Paul Duffina7d6a892020-12-07 17:39:59 +0000987type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100988 // ApexVariationName returns the name of the APEX variation to use in the apex
989 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
990 ApexVariationName() string
991
Paul Duffina7d6a892020-12-07 17:39:59 +0000992 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
993 // depended upon by an apex and which require an apex specific variant.
994 ApexInfoMutator(android.TopDownMutatorContext)
995}
996
997// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
998// specific variant to modules that support the ApexInfoMutator.
999func apexInfoMutator(mctx android.TopDownMutatorContext) {
1000 if !mctx.Module().Enabled() {
1001 return
1002 }
1003
1004 if a, ok := mctx.Module().(ApexInfoMutator); ok {
1005 a.ApexInfoMutator(mctx)
1006 return
1007 }
1008}
1009
Spandan Das66773252022-01-15 00:23:18 +00001010// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
1011// This check is enforced for updatable modules
1012func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
1013 if !mctx.Module().Enabled() {
1014 return
1015 }
Spandan Das08c911f2022-01-21 22:07:26 +00001016 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +00001017 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001018 // b/208656169 Do not propagate strict updatability linting to libcore/
1019 // These libs are available on the classpath during compilation
1020 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1021 // Only skip libraries defined in libcore root, not subdirectories
1022 if mctx.OtherModuleDir(child) == "libcore" {
1023 // Do not traverse transitive deps of libcore/ libs
1024 return false
1025 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001026 if android.InList(child.Name(), skipLintJavalibAllowlist) {
1027 return false
1028 }
Spandan Das66773252022-01-15 00:23:18 +00001029 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1030 lintable.SetStrictUpdatabilityLinting(true)
1031 }
1032 // visit transitive deps
1033 return true
1034 })
1035 }
1036}
1037
Spandan Das08c911f2022-01-21 22:07:26 +00001038// TODO: b/215736885 Whittle the denylist
1039// Transitive deps of certain mainline modules baseline NewApi errors
1040// Skip these mainline modules for now
1041var (
1042 skipStrictUpdatabilityLintAllowlist = []string{
1043 "com.android.art",
1044 "com.android.art.debug",
1045 "com.android.conscrypt",
1046 "com.android.media",
1047 // test apexes
1048 "test_com.android.art",
1049 "test_com.android.conscrypt",
1050 "test_com.android.media",
1051 "test_jitzygote_com.android.art",
1052 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001053
1054 // TODO: b/215736885 Remove this list
1055 skipLintJavalibAllowlist = []string{
1056 "conscrypt.module.platform.api.stubs",
1057 "conscrypt.module.public.api.stubs",
1058 "conscrypt.module.public.api.stubs.system",
1059 "conscrypt.module.public.api.stubs.module_lib",
1060 "framework-media.stubs",
1061 "framework-media.stubs.system",
1062 "framework-media.stubs.module_lib",
1063 }
Spandan Das08c911f2022-01-21 22:07:26 +00001064)
1065
1066func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1067 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1068}
1069
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001070// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1071// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1072// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001073func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1074 if !mctx.Module().Enabled() {
1075 return
1076 }
1077 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001078 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1079 }
1080}
1081
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001082// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1083// the apex in order to retrieve its contents later.
1084// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001085func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1086 if !mctx.Module().Enabled() {
1087 return
1088 }
Colin Cross56a83212020-09-15 18:30:11 -07001089 if am, ok := mctx.Module().(android.ApexModule); ok {
1090 if testFor := am.TestFor(); len(testFor) > 0 {
1091 mctx.AddFarVariationDependencies([]blueprint.Variation{
1092 {Mutator: "os", Variation: am.Target().OsVariation()},
1093 {"arch", "common"},
1094 }, testForTag, testFor...)
1095 }
1096 }
1097}
1098
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001099// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001100func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1101 if !mctx.Module().Enabled() {
1102 return
1103 }
Colin Cross56a83212020-09-15 18:30:11 -07001104 if _, ok := mctx.Module().(android.ApexModule); ok {
1105 var contents []*android.ApexContents
1106 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1107 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1108 contents = append(contents, abInfo.Contents)
1109 }
1110 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1111 ApexContents: contents,
1112 })
Colin Crossaede88c2020-08-11 12:17:01 -07001113 }
1114}
1115
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001116// markPlatformAvailability marks whether or not a module can be available to platform. A module
1117// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1118// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1119// be) available to platform
1120// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001121func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
1122 // Host and recovery are not considered as platform
1123 if mctx.Host() || mctx.Module().InstallInRecovery() {
1124 return
1125 }
1126
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001127 am, ok := mctx.Module().(android.ApexModule)
1128 if !ok {
1129 return
1130 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001131
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001132 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001133
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001134 // If any of the dep is not available to platform, this module is also considered as being
1135 // not available to platform even if it has "//apex_available:platform"
1136 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001137 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001138 // if the dependency crosses apex boundary, don't consider it
1139 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001140 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001141 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1142 availableToPlatform = false
1143 // TODO(b/154889534) trigger an error when 'am' has
1144 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001145 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001146 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001147
Paul Duffinb5769c12021-05-12 16:16:51 +01001148 // Exception 1: check to see if the module always requires it.
1149 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001150 availableToPlatform = true
1151 }
1152
1153 // Exception 2: bootstrap bionic libraries are also always available to platform
1154 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1155 availableToPlatform = true
1156 }
1157
1158 if !availableToPlatform {
1159 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001160 }
1161}
1162
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001163// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001164// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001165func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001166 if !mctx.Module().Enabled() {
1167 return
1168 }
Colin Cross56a83212020-09-15 18:30:11 -07001169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001170 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001171 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001172 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001173 return
1174 }
1175
1176 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001177 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1178 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001179 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001180 if strings.HasPrefix(apexBundleName, "com.android.art") {
1181 // Create an alias from the platform variant. This is done to make
1182 // test_for dependencies work for modules that are split by the APEX
1183 // mutator, since test_for dependencies always go to the platform variant.
1184 // This doesn't happen for normal APEXes that are disjunct, so only do
1185 // this for the overlapping ART APEXes.
1186 // TODO(b/183882457): Remove this if the test_for functionality is
1187 // refactored to depend on the proper APEX variants instead of platform.
1188 mctx.CreateAliasVariation("", apexBundleName)
1189 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001190 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1191 apexBundleName := o.GetOverriddenModuleName()
1192 if apexBundleName == "" {
1193 mctx.ModuleErrorf("base property is not set")
1194 return
1195 }
1196 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001197 if strings.HasPrefix(apexBundleName, "com.android.art") {
1198 // TODO(b/183882457): See note for CreateAliasVariation above.
1199 mctx.CreateAliasVariation("", apexBundleName)
1200 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001201 }
1202}
Sundong Ahne9b55722019-09-06 17:37:42 +09001203
Paul Duffin6717d882021-06-15 19:09:41 +01001204// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1205// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001206func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001207 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001208 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001209 return !a.vndkApex
1210 }
1211
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001212 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001213}
1214
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001215// See android.UpdateDirectlyInAnyApex
1216// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001217func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1218 if !mctx.Module().Enabled() {
1219 return
1220 }
1221 if am, ok := mctx.Module().(android.ApexModule); ok {
1222 android.UpdateDirectlyInAnyApex(mctx, am)
1223 }
1224}
1225
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001226// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001227type apexPackaging int
1228
1229const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001230 // imageApex is a packaging method where contents are included in a filesystem image which
1231 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001232 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001233
1234 // zipApex is a packaging method where contents are directly included in the zip container.
1235 // This is used for host-side testing - because the contents are easily accessible by
1236 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001237 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001238
1239 // flattendApex is a packaging method where contents are not included in the APEX file, but
1240 // installed to /apex/<apexname> directory on the device. This packaging method is used for
1241 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001242 flattenedApex
1243)
1244
1245const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001247 imageApexSuffix = ".apex"
1248 imageCapexSuffix = ".capex"
1249 zipApexSuffix = ".zipapex"
1250 flattenedSuffix = ".flattened"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001251
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001252 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001253 imageApexType = "image"
1254 zipApexType = "zip"
1255 flattenedApexType = "flattened"
1256
Dan Willemsen47e1a752021-10-16 18:36:13 -07001257 ext4FsType = "ext4"
1258 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001259 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001260)
1261
1262// The suffix for the output "file", not the module
1263func (a apexPackaging) suffix() string {
1264 switch a {
1265 case imageApex:
1266 return imageApexSuffix
1267 case zipApex:
1268 return zipApexSuffix
1269 default:
1270 panic(fmt.Errorf("unknown APEX type %d", a))
1271 }
1272}
1273
1274func (a apexPackaging) name() string {
1275 switch a {
1276 case imageApex:
1277 return imageApexType
1278 case zipApex:
1279 return zipApexType
1280 default:
1281 panic(fmt.Errorf("unknown APEX type %d", a))
1282 }
1283}
1284
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001285// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1286// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001287func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001288 if !mctx.Module().Enabled() {
1289 return
1290 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001291 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001292 var variants []string
1293 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1294 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001295 // This is the normal case. Note that both image and flattend APEXes are
1296 // created. The image type is installed to the system partition, while the
1297 // flattened APEX is (optionally) installed to the system_ext partition.
1298 // This is mostly for GSI which has to support wide range of devices. If GSI
1299 // is installed on a newer (APEX-capable) device, the image APEX in the
1300 // system will be used. However, if the same GSI is installed on an old
1301 // device which can't support image APEX, the flattened APEX in the
1302 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001303 variants = append(variants, imageApexType, flattenedApexType)
1304 case "zip":
1305 variants = append(variants, zipApexType)
1306 case "both":
1307 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1308 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001309 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001310 return
1311 }
1312
1313 modules := mctx.CreateLocalVariations(variants...)
1314
1315 for i, v := range variants {
1316 switch v {
1317 case imageApexType:
1318 modules[i].(*apexBundle).properties.ApexType = imageApex
1319 case zipApexType:
1320 modules[i].(*apexBundle).properties.ApexType = zipApex
1321 case flattenedApexType:
1322 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001323 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001324 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001325 modules[i].(*apexBundle).MakeAsSystemExt()
1326 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001327 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001328 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001329 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001330 // payload_type is forcibly overridden to "image"
1331 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001332 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001333 }
1334}
1335
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001336var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001337
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001338// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001339func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1340 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001341 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001342 return true
1343}
1344
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001345var _ android.OutputFileProducer = (*apexBundle)(nil)
1346
1347// Implements android.OutputFileProducer
1348func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1349 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001350 case "", android.DefaultDistTag:
1351 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001352 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001353 case imageApexSuffix:
1354 // uncompressed one
1355 if a.outputApexFile != nil {
1356 return android.Paths{a.outputApexFile}, nil
1357 }
1358 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001359 default:
1360 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1361 }
1362}
1363
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001364var _ multitree.Exportable = (*apexBundle)(nil)
1365
1366func (a *apexBundle) Exportable() bool {
1367 if a.properties.ApexType == flattenedApex {
1368 return false
1369 }
1370 return true
1371}
1372
1373func (a *apexBundle) TaggedOutputs() map[string]android.Paths {
1374 ret := make(map[string]android.Paths)
1375 ret["apex"] = android.Paths{a.outputFile}
1376 return ret
1377}
1378
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001379var _ cc.Coverage = (*apexBundle)(nil)
1380
1381// Implements cc.Coverage
1382func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1383 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1384}
1385
1386// Implements cc.Coverage
Ivan Lozanod7586b62021-04-01 09:49:36 -04001387func (a *apexBundle) SetPreventInstall() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001388 a.properties.PreventInstall = true
1389}
1390
1391// Implements cc.Coverage
1392func (a *apexBundle) HideFromMake() {
1393 a.properties.HideFromMake = true
Colin Crosse6a83e62020-12-17 18:22:34 -08001394 // This HideFromMake is shadowing the ModuleBase one, call through to it for now.
1395 // TODO(ccross): untangle these
1396 a.ModuleBase.HideFromMake()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397}
1398
1399// Implements cc.Coverage
1400func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1401 a.properties.IsCoverageVariant = coverage
1402}
1403
1404// Implements cc.Coverage
1405func (a *apexBundle) EnableCoverageIfNeeded() {}
1406
1407var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1408
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -04001409// Implements android.ApexBundleDepsInfoIntf
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001410func (a *apexBundle) Updatable() bool {
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001411 return proptools.BoolDefault(a.properties.Updatable, true)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001412}
1413
Jiyong Parkf4020582021-11-29 12:37:10 +09001414func (a *apexBundle) FutureUpdatable() bool {
1415 return proptools.BoolDefault(a.properties.Future_updatable, false)
1416}
1417
Jiyong Park1bc84122021-06-22 20:23:05 +09001418func (a *apexBundle) UsePlatformApis() bool {
1419 return proptools.BoolDefault(a.properties.Platform_apis, false)
1420}
1421
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001422// getCertString returns the name of the cert that should be used to sign this APEX. This is
1423// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001424func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001425 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001426 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1427 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1428 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001429 if a.vndkApex {
1430 moduleName = vndkApexName
1431 }
1432 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001433 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001434 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001435 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07001436 return String(a.overridableProperties.Certificate)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001437}
1438
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001439// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001440func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001441 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001442}
1443
Nikita Ioffeda6dc312021-06-09 19:43:46 +01001444// See the generate_hashtree property
1445func (a *apexBundle) shouldGenerateHashtree() bool {
Nikita Ioffee261ae62021-06-16 18:15:03 +01001446 return proptools.BoolDefault(a.properties.Generate_hashtree, true)
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001447}
1448
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001449// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001450func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1451 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1452}
1453
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +00001454// See the test_only_force_compression property
1455func (a *apexBundle) testOnlyShouldForceCompression() bool {
1456 return proptools.Bool(a.properties.Test_only_force_compression)
1457}
1458
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001459// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1460// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1461// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001462
Jiyong Parkf97782b2019-02-13 20:28:58 +09001463func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1464 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1465 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1466 }
1467}
1468
Jiyong Park388ef3f2019-01-28 19:47:32 +09001469func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001470 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1471 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001472 }
1473
1474 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001475 globalSanitizerNames := []string{}
1476 if a.Host() {
1477 globalSanitizerNames = ctx.Config().SanitizeHost()
1478 } else {
1479 arches := ctx.Config().SanitizeDeviceArch()
1480 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1481 globalSanitizerNames = ctx.Config().SanitizeDevice()
1482 }
1483 }
1484 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001485}
1486
Jooyung Han8ce8db92020-05-15 19:05:05 +09001487func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001488 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1489 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001490 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001491 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001492 for _, target := range ctx.MultiTargets() {
1493 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001494 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Cross4c4c1be2022-02-10 11:41:18 -08001495 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001496 Tests: nil,
1497 Jni_libs: nil,
1498 Binaries: nil,
1499 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001500 break
1501 }
1502 }
1503 }
1504}
1505
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001506// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1507// returned apexFile saves information about the Soong module that will be used for creating the
1508// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001509func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001510 // Decide the APEX-local directory by the multilib of the library In the future, we may
1511 // query this to the module.
1512 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001513 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001514 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001515 case "lib32":
1516 dirInApex = "lib"
1517 case "lib64":
1518 dirInApex = "lib64"
1519 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001520 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001521 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001522 }
Jooyung Han35155c42020-02-06 17:33:20 +09001523 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001524 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001525 // Special case for Bionic libs and other libs installed with them. This is to
1526 // prevent those libs from being included in the search path
1527 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1528 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1529 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1530 // will be loaded into the default linker namespace (aka "platform" namespace). If
1531 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1532 // be loaded again into the runtime linker namespace, which will result in double
1533 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001534 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001535 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001536
Jiyong Parkf653b052019-11-18 15:39:01 +09001537 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001538 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1539 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001540}
1541
Jiyong Park1833cef2019-12-13 13:28:36 +09001542func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001543 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001544 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001545 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001546 }
Jooyung Han35155c42020-02-06 17:33:20 +09001547 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001548 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001549 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1550 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001551 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001552 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001553 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001554}
1555
Jiyong Park99644e92020-11-17 22:21:02 +09001556func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1557 dirInApex := "bin"
1558 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1559 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1560 }
1561 fileToCopy := rustm.OutputFile().Path()
1562 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1563 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1564 return af
1565}
1566
1567func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1568 // Decide the APEX-local directory by the multilib of the library
1569 // In the future, we may query this to the module.
1570 var dirInApex string
1571 switch rustm.Arch().ArchType.Multilib {
1572 case "lib32":
1573 dirInApex = "lib"
1574 case "lib64":
1575 dirInApex = "lib64"
1576 }
1577 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1578 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1579 }
1580 fileToCopy := rustm.OutputFile().Path()
1581 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1582 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1583}
1584
Jiyong Park1833cef2019-12-13 13:28:36 +09001585func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001586 dirInApex := "bin"
1587 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001588 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001589}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001590
Jiyong Park1833cef2019-12-13 13:28:36 +09001591func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001592 dirInApex := "bin"
Colin Crossa44551f2021-10-25 15:36:21 -07001593 fileToCopy := android.PathForGoBinary(ctx, gb)
Jiyong Parkf653b052019-11-18 15:39:01 +09001594 // NB: Since go binaries are static we don't need the module for anything here, which is
1595 // good since the go tool is a blueprint.Module not an android.Module like we would
1596 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001597 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001598}
1599
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001600func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001601 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001602 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1603 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1604 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001605 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001606 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001607 af.symlinks = sh.Symlinks()
1608 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001609}
1610
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001611func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001612 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001613 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001614 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001615}
1616
atrost6e126252020-01-27 17:01:16 +00001617func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1618 dirInApex := filepath.Join("etc", config.SubDir())
1619 fileToCopy := config.CompatConfig()
1620 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1621}
1622
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001623// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1624// way.
1625type javaModule interface {
1626 android.Module
1627 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001628 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001629 JacocoReportClassesFile() android.Path
1630 LintDepSets() java.LintDepSets
1631 Stem() string
1632}
1633
1634var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001635var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001636var _ javaModule = (*java.SdkLibrary)(nil)
1637var _ javaModule = (*java.DexImport)(nil)
1638var _ javaModule = (*java.SdkLibraryImport)(nil)
1639
Paul Duffin190fdef2021-04-26 10:33:59 +01001640// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001641func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001642 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001643}
1644
1645// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1646func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001647 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001648 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001649 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1650 af.lintDepSets = module.LintDepSets()
1651 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001652 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1653 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1654 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1655 }
1656 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001657 return af
1658}
1659
1660// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1661// the same way.
1662type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 android.Module
1664 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001665 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001667 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001668 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001669 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001670 LintDepSets() java.LintDepSets
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001671}
1672
1673var _ androidApp = (*java.AndroidApp)(nil)
1674var _ androidApp = (*java.AndroidAppImport)(nil)
1675
Jingwen Chen6cb124b2022-04-19 13:58:58 +00001676const APEX_VERSION_PLACEHOLDER = "__APEX_VERSION_PLACEHOLDER__"
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001677
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001678func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001679 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001681 appDir = "priv-app"
1682 }
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001683
1684 // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed
1685 // so that PackageManager correctly invalidates the existing installed apk
1686 // in favour of the new APK-in-APEX. See bugs for more information.
Jingwen Chen6cb124b2022-04-19 13:58:58 +00001687 dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+APEX_VERSION_PLACEHOLDER)
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 fileToCopy := aapp.OutputFile()
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001689
Yo Chiange8128052020-07-23 20:09:18 +08001690 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001691 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001692 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001693 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001694
1695 if app, ok := aapp.(interface {
1696 OverriddenManifestPackageName() string
1697 }); ok {
1698 af.overriddenPackageName = app.OverriddenManifestPackageName()
1699 }
Jiyong Park618922e2020-01-08 13:35:43 +09001700 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001701}
1702
Jiyong Park69aeba92020-04-24 21:16:36 +09001703func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1704 rroDir := "overlay"
1705 dirInApex := filepath.Join(rroDir, rro.Theme())
1706 fileToCopy := rro.OutputFile()
1707 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1708 af.certificate = rro.Certificate()
1709
1710 if a, ok := rro.(interface {
1711 OverriddenManifestPackageName() string
1712 }); ok {
1713 af.overriddenPackageName = a.OverriddenManifestPackageName()
1714 }
1715 return af
1716}
1717
Ken Chenfad7f9d2021-11-10 22:02:57 +08001718func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1719 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001720 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1721}
1722
Jiyong Park12a719c2021-01-07 15:31:24 +09001723func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1724 dirInApex := filepath.Join("etc", "fs")
1725 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1726}
1727
Paul Duffin064b70c2020-11-02 17:32:38 +00001728// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001729// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1730// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1731// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001732func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001733 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001734 am, ok := child.(android.ApexModule)
1735 if !ok || !am.CanHaveApexVariants() {
1736 return false
1737 }
1738
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001739 // Filter-out unwanted depedendencies
1740 depTag := ctx.OtherModuleDependencyTag(child)
1741 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1742 return false
1743 }
1744 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001745 return false
1746 }
1747
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001748 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001749 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001750
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001751 // Visit actually
1752 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001753 })
1754}
1755
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001756// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1757type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001758
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001759const (
1760 ext4 fsType = iota
1761 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001762 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001763)
Artur Satayev849f8442020-04-28 14:57:42 +01001764
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001765func (f fsType) string() string {
1766 switch f {
1767 case ext4:
1768 return ext4FsType
1769 case f2fs:
1770 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001771 case erofs:
1772 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001773 default:
1774 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001775 }
1776}
1777
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001778// Creates build rules for an APEX. It consists of the following major steps:
1779//
1780// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1781// 2) traverse the dependency tree to collect apexFile structs from them.
1782// 3) some fields in apexBundle struct are configured
1783// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001784func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001785 ////////////////////////////////////////////////////////////////////////////////////////////
1786 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001787 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001788 a.checkUpdatable(ctx)
satayevb3fd4112021-12-02 13:59:35 +00001789 a.CheckMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001790 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park192600a2021-08-03 07:52:17 +00001791 a.checkStaticExecutables(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001792 if len(a.properties.Tests) > 0 && !a.testApex {
1793 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1794 return
1795 }
Jiyong Park678c8812020-02-07 17:25:49 +09001796
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001797 ////////////////////////////////////////////////////////////////////////////////////////////
1798 // 2) traverse the dependency tree to collect apexFile structs from them.
1799
1800 // all the files that will be included in this APEX
1801 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001802
Jooyung Hane1633032019-08-01 17:41:43 +09001803 // native lib dependencies
1804 var provideNativeLibs []string
1805 var requireNativeLibs []string
1806
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001807 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1808
braleeb0c1f0c2021-06-07 22:49:13 +08001809 // Collect the module directory for IDE info in java/jdeps.go.
1810 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
1811
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001812 // TODO(jiyong): do this using WalkPayloadDeps
1813 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001814 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001815 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001816 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1817 return false
1818 }
Dan Willemsen47e1a752021-10-16 18:36:13 -07001819 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
1820 return false
1821 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001822 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001823 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001824 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001825 case sharedLibTag, jniLibTag:
1826 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001827 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001828 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1829 fi.isJniLib = isJniLib
1830 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001831 // Collect the list of stub-providing libs except:
1832 // - VNDK libs are only for vendors
1833 // - bootstrap bionic libs are treated as provided by system
1834 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001835 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001836 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001837 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001838 } else if r, ok := child.(*rust.Module); ok {
1839 fi := apexFileForRustLibrary(ctx, r)
Benjamin Brittain9edc3752021-11-30 13:38:13 -05001840 fi.isJniLib = isJniLib
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09001841 filesInfo = append(filesInfo, fi)
Jiyong Park34d5c332022-02-24 18:02:44 +09001842 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001843 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001844 propertyName := "native_shared_libs"
1845 if isJniLib {
1846 propertyName = "jni_libs"
1847 }
1848 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001849 }
1850 case executableTag:
1851 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001852 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001853 return true // track transitive dependencies
Alex Light778127a2019-02-27 14:19:50 -08001854 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001855 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001856 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001858 } else if rust, ok := child.(*rust.Module); ok {
1859 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1860 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001861 } else {
Sundong Ahn80c04892021-11-23 00:57:19 +00001862 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
1863 }
1864 case shBinaryTag:
1865 if sh, ok := child.(*sh.ShBinary); ok {
1866 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
1867 } else {
1868 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001869 }
Paul Duffin94f19632021-04-20 12:40:07 +01001870 case bcpfTag:
Paul Duffina1d60252021-01-21 18:13:43 +00001871 {
Jiakai Zhang6decef92022-01-12 17:56:19 +00001872 bcpfModule, ok := child.(*java.BootclasspathFragmentModule)
1873 if !ok {
Paul Duffincc33ec82021-04-25 23:14:55 +01001874 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
Paul Duffina1d60252021-01-21 18:13:43 +00001875 return false
1876 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001877
Paul Duffincc33ec82021-04-25 23:14:55 +01001878 filesToAdd := apexBootclasspathFragmentFiles(ctx, child)
1879 filesInfo = append(filesInfo, filesToAdd...)
Jiakai Zhang6decef92022-01-12 17:56:19 +00001880 for _, makeModuleName := range bcpfModule.BootImageDeviceInstallMakeModules() {
1881 a.requiredDeps = append(a.requiredDeps, makeModuleName)
1882 }
Paul Duffin4d101b62021-03-24 15:42:20 +00001883 return true
Paul Duffina1d60252021-01-21 18:13:43 +00001884 }
satayev333a1732021-05-17 21:35:26 +01001885 case sscpfTag:
1886 {
1887 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
1888 ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName)
1889 return false
1890 }
satayevb98371c2021-06-15 16:49:50 +01001891 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
1892 filesInfo = append(filesInfo, *af)
1893 }
satayev333a1732021-05-17 21:35:26 +01001894 return true
1895 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001896 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001897 switch child.(type) {
Bill Peckhama41a6962021-01-11 10:58:54 -08001898 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001899 af := apexFileForJavaModule(ctx, child.(javaModule))
1900 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001901 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1902 return false
1903 }
1904 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001905 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001906 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001907 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001908 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001909 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001910 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001911 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001912 return true // track transitive dependencies
1913 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001914 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001915 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001916 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001917 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1918 appDir := "app"
1919 if ap.Privileged() {
1920 appDir = "priv-app"
1921 }
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001922 // TODO(b/224589412, b/226559955): Ensure that the dirname is
1923 // suffixed so that PackageManager correctly invalidates the
1924 // existing installed apk in favour of the new APK-in-APEX.
1925 // See bugs for more information.
Jingwen Chen6cb124b2022-04-19 13:58:58 +00001926 appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+APEX_VERSION_PLACEHOLDER)
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001927 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap)
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001928 af.certificate = java.PresignedCertificate
1929 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001930 } else {
1931 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1932 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001933 case rroTag:
1934 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1935 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1936 } else {
1937 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1938 }
markchien2f59ec92020-09-02 16:23:38 +08001939 case bpfTag:
1940 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1941 filesToCopy, _ := bpfProgram.OutputFiles("")
Ken Chenfad7f9d2021-11-10 22:02:57 +08001942 apex_sub_dir := bpfProgram.SubDir()
markchien2f59ec92020-09-02 16:23:38 +08001943 for _, bpfFile := range filesToCopy {
Ken Chenfad7f9d2021-11-10 22:02:57 +08001944 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
markchien2f59ec92020-09-02 16:23:38 +08001945 }
1946 } else {
1947 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1948 }
Jiyong Park12a719c2021-01-07 15:31:24 +09001949 case fsTag:
1950 if fs, ok := child.(filesystem.Filesystem); ok {
1951 filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
1952 } else {
1953 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
1954 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001955 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001956 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001957 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001958 } else {
Paul Duffin1bc21dc2021-03-15 19:43:17 +00001959 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001960 }
Paul Duffin0b817782021-03-17 15:02:19 +00001961 case compatConfigTag:
Paul Duffin3abc1742021-03-15 19:32:23 +00001962 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
1963 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
1964 } else {
1965 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
1966 }
Roland Levillain630846d2019-06-26 12:48:34 +01001967 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001968 if ccTest, ok := child.(*cc.Module); ok {
1969 if ccTest.IsTestPerSrcAllTestsVariation() {
1970 // Multiple-output test module (where `test_per_src: true`).
1971 //
1972 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1973 // We do not add this variation to `filesInfo`, as it has no output;
1974 // however, we do add the other variations of this module as indirect
1975 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001976 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001977 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001978 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001979 af.class = nativeTest
1980 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001981 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001982 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001983 } else {
1984 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1985 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001986 case keyTag:
1987 if key, ok := child.(*apexKey); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001988 a.privateKeyFile = key.privateKeyFile
1989 a.publicKeyFile = key.publicKeyFile
Jiyong Parkff1458f2018-10-12 21:49:38 +09001990 } else {
1991 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001992 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001994 case certificateTag:
1995 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001996 a.containerCertificateFile = dep.Certificate.Pem
1997 a.containerPrivateKeyFile = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001998 } else {
1999 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2000 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002001 case android.PrebuiltDepTag:
2002 // If the prebuilt is force disabled, remember to delete the prebuilt file
2003 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002004 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002005 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2006 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002007 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002008 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002009 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002010 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002011 // We cannot use a switch statement on `depTag` here as the checked
2012 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002013 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002014 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09002015 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002016 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002017 return false
2018 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002019 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2020 af.transitiveDep = true
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002021
2022 // Always track transitive dependencies for host.
2023 if a.Host() {
2024 filesInfo = append(filesInfo, af)
2025 return true
2026 }
2027
Colin Cross56a83212020-09-15 18:30:11 -07002028 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002029 if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002030 // If the dependency is a stubs lib, don't include it in this APEX,
2031 // but make sure that the lib is installed on the device.
2032 // In case no APEX is having the lib, the lib is installed to the system
2033 // partition.
2034 //
2035 // Always include if we are a host-apex however since those won't have any
2036 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002037 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002038 // we need a module name for Make
Steven Moreland2c4000c2021-04-27 02:08:49 +00002039 name := cc.ImplementationModuleNameForMake(ctx) + cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002040 if !android.InList(name, a.requiredDeps) {
2041 a.requiredDeps = append(a.requiredDeps, name)
2042 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002043 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002044 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002045 // Don't track further
2046 return false
2047 }
Jiyong Parke3867542020-12-03 17:28:25 +09002048
2049 // If the dep is not considered to be in the same
2050 // apex, don't add it to filesInfo so that it is not
2051 // included in this APEX.
2052 // TODO(jiyong): move this to at the top of the
2053 // else-if clause for the indirect dependencies.
2054 // Currently, that's impossible because we would
2055 // like to record requiredNativeLibs even when
Martin Stjernholmf2635ec2020-12-16 01:01:59 +00002056 // DepIsInSameAPex is false. We also shouldn't do
2057 // this for host.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002058 //
2059 // TODO(jiyong): explain why the same module is passed in twice.
2060 // Switching the first am to parent breaks lots of tests.
2061 if !android.IsDepInSameApex(ctx, am, am) {
Jiyong Parke3867542020-12-03 17:28:25 +09002062 return false
2063 }
2064
Jiyong Parkf653b052019-11-18 15:39:01 +09002065 filesInfo = append(filesInfo, af)
2066 return true // track transitive dependencies
Jiyong Parkf2cc1b72020-12-09 00:20:45 +09002067 } else if rm, ok := child.(*rust.Module); ok {
2068 af := apexFileForRustLibrary(ctx, rm)
2069 af.transitiveDep = true
2070 filesInfo = append(filesInfo, af)
2071 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002072 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002073 } else if cc.IsTestPerSrcDepTag(depTag) {
2074 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002075 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002076 // Handle modules created as `test_per_src` variations of a single test module:
2077 // use the name of the generated test binary (`fileToCopy`) instead of the name
2078 // of the original test module (`depName`, shared by all `test_per_src`
2079 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002080 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002081 // these are not considered transitive dep
2082 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002083 filesInfo = append(filesInfo, af)
2084 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002085 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002086 } else if cc.IsHeaderDepTag(depTag) {
2087 // nothing
Jiyong Park52cd06f2019-11-11 10:14:32 +09002088 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002089 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2090 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002091 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002092 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002093 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2094 }
Jiyong Park99644e92020-11-17 22:21:02 +09002095 } else if rust.IsDylibDepTag(depTag) {
2096 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2097 af := apexFileForRustLibrary(ctx, rustm)
2098 af.transitiveDep = true
2099 filesInfo = append(filesInfo, af)
2100 return true // track transitive dependencies
2101 }
Jiyong Park94e22fd2021-04-08 18:19:15 +09002102 } else if rust.IsRlibDepTag(depTag) {
2103 // Rlib is statically linked, but it might have shared lib
2104 // dependencies. Track them.
2105 return true
Paul Duffin65898052021-04-20 22:47:03 +01002106 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
Paul Duffin94f19632021-04-20 12:40:07 +01002107 // Add the contents of the bootclasspath fragment to the apex.
Paul Duffin4d101b62021-03-24 15:42:20 +00002108 switch child.(type) {
2109 case *java.Library, *java.SdkLibrary:
Paul Duffincc33ec82021-04-25 23:14:55 +01002110 javaModule := child.(javaModule)
Paul Duffin190fdef2021-04-26 10:33:59 +01002111 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
Paul Duffin4d101b62021-03-24 15:42:20 +00002112 if !af.ok() {
Paul Duffin94f19632021-04-20 12:40:07 +01002113 ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
Paul Duffin4d101b62021-03-24 15:42:20 +00002114 return false
2115 }
2116 filesInfo = append(filesInfo, af)
2117 return true // track transitive dependencies
2118 default:
Paul Duffin94f19632021-04-20 12:40:07 +01002119 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 +00002120 }
satayev333a1732021-05-17 21:35:26 +01002121 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2122 // Add the contents of the systemserverclasspath fragment to the apex.
2123 switch child.(type) {
2124 case *java.Library, *java.SdkLibrary:
2125 af := apexFileForJavaModule(ctx, child.(javaModule))
2126 filesInfo = append(filesInfo, af)
2127 return true // track transitive dependencies
2128 default:
2129 ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2130 }
Colin Cross56a83212020-09-15 18:30:11 -07002131 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2132 // nothing
Dan Willemsen47450072021-10-19 20:24:49 -07002133 } else if depTag == android.DarwinUniversalVariantTag {
2134 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002135 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002136 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002137 }
2138 }
2139 }
2140 return false
2141 })
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002142 if a.privateKeyFile == nil {
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -07002143 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002144 return
2145 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002146
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002147 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09002148 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002149 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002150 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002151 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002152 if e, ok := encountered[dest]; !ok {
2153 encountered[dest] = f
2154 } else {
2155 // If a module is directly included and also transitively depended on
2156 // consider it as directly included.
2157 e.transitiveDep = e.transitiveDep && f.transitiveDep
2158 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002159 }
2160 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002161 var result []apexFile
2162 for _, v := range encountered {
2163 result = append(result, v)
2164 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002165 return result
2166 }
2167 filesInfo = removeDup(filesInfo)
2168
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002169 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09002170 sort.Slice(filesInfo, func(i, j int) bool {
Paul Duffin56060292021-05-15 19:34:05 +01002171 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2172 // changes.
2173 return filesInfo[i].path() < filesInfo[j].path()
Jiyong Park8fd61922018-11-08 02:50:25 +09002174 })
2175
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002176 ////////////////////////////////////////////////////////////////////////////////////////////
2177 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002178 a.installDir = android.PathForModuleInstall(ctx, "apex")
2179 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002180
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002181 // Set suffix and primaryApexType depending on the ApexType
Martin Stjernholmcb3ff1e2021-05-25 00:28:27 +01002182 buildFlattenedAsDefault := ctx.Config().FlattenApex()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002183 switch a.properties.ApexType {
2184 case imageApex:
2185 if buildFlattenedAsDefault {
2186 a.suffix = imageApexSuffix
2187 } else {
2188 a.suffix = ""
2189 a.primaryApexType = true
2190
2191 if ctx.Config().InstallExtraFlattenedApexes() {
2192 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
2193 }
2194 }
2195 case zipApex:
2196 if proptools.String(a.properties.Payload_type) == "zip" {
2197 a.suffix = ""
2198 a.primaryApexType = true
2199 } else {
2200 a.suffix = zipApexSuffix
2201 }
2202 case flattenedApex:
2203 if buildFlattenedAsDefault {
2204 a.suffix = ""
2205 a.primaryApexType = true
2206 } else {
2207 a.suffix = flattenedSuffix
2208 }
2209 }
2210
Theotime Combes4ba38c12020-06-12 12:46:59 +00002211 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2212 case ext4FsType:
2213 a.payloadFsType = ext4
2214 case f2fsFsType:
2215 a.payloadFsType = f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08002216 case erofsFsType:
2217 a.payloadFsType = erofs
Theotime Combes4ba38c12020-06-12 12:46:59 +00002218 default:
Huang Jianan13cac632021-08-02 15:02:17 +08002219 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 +00002220 }
2221
Jiyong Park7cd10e32020-01-14 09:22:18 +09002222 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2223 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2224 // the same library in the system partition, thus effectively sharing the same libraries
2225 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2226 // in the APEX.
Steven Moreland2c4000c2021-04-27 02:08:49 +00002227 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
Jooyung Han54aca7b2019-11-20 02:26:02 +09002228
Jooyung Han85d61762020-06-24 23:50:26 +09002229 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2230 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002231 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002232 a.linkToSystemLib = false
2233 }
2234
Jiyong Park4da07972021-01-05 21:01:11 +09002235 forced := ctx.Config().ForceApexSymlinkOptimization()
Jiyong Parkf4020582021-11-29 12:37:10 +09002236 updatable := a.Updatable() || a.FutureUpdatable()
Jiyong Park4da07972021-01-05 21:01:11 +09002237
Jiyong Park9d677202020-02-19 16:29:35 +09002238 // We don't need the optimization for updatable APEXes, as it might give false signal
Jiyong Park4da07972021-01-05 21:01:11 +09002239 // to the system health when the APEXes are still bundled (b/149805758).
Jiyong Parkf4020582021-11-29 12:37:10 +09002240 if !forced && updatable && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002241 a.linkToSystemLib = false
2242 }
2243
Jiyong Park638d30e2020-02-26 18:27:19 +09002244 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2245 if ctx.Host() {
2246 a.linkToSystemLib = false
2247 }
2248
Colin Cross6340ea52021-11-04 12:01:18 -07002249 if a.properties.ApexType != zipApex {
2250 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx, a.primaryApexType)
2251 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002252
2253 ////////////////////////////////////////////////////////////////////////////////////////////
2254 // 4) generate the build rules to create the APEX. This is done in builder.go.
2255 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002256 if a.properties.ApexType == flattenedApex {
2257 a.buildFlattenedApex(ctx)
2258 } else {
2259 a.buildUnflattenedApex(ctx)
2260 }
Jiyong Park956305c2020-01-09 12:32:06 +09002261 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002262 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09002263
2264 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
2265 if a.installable() {
2266 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
2267 // along with other ordinary files. (Note that this is done by apexer for
2268 // non-flattened APEXes)
2269 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
2270
2271 // Place the public key as apex_pubkey. This is also done by apexer for
2272 // non-flattened APEXes case.
2273 // TODO(jiyong): Why do we need this CP rule?
2274 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
2275 ctx.Build(pctx, android.BuildParams{
2276 Rule: android.Cp,
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002277 Input: a.publicKeyFile,
Jiyong Parkb81b9902020-11-24 19:51:18 +09002278 Output: copiedPubkey,
2279 })
2280 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
2281 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09002282}
2283
Paul Duffincc33ec82021-04-25 23:14:55 +01002284// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2285// the bootclasspath_fragment contributes to the apex.
2286func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2287 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2288 var filesToAdd []apexFile
2289
2290 // Add the boot image files, e.g. .art, .oat and .vdex files.
Jiakai Zhang6decef92022-01-12 17:56:19 +00002291 if bootclasspathFragmentInfo.ShouldInstallBootImageInApex() {
2292 for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() {
2293 dirInApex := filepath.Join("javalib", arch.String())
2294 for _, f := range files {
2295 androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
2296 // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil
2297 af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil)
2298 filesToAdd = append(filesToAdd, af)
2299 }
Paul Duffincc33ec82021-04-25 23:14:55 +01002300 }
2301 }
2302
satayev3db35472021-05-06 23:59:58 +01002303 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002304 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2305 filesToAdd = append(filesToAdd, *af)
2306 }
satayev3db35472021-05-06 23:59:58 +01002307
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002308 if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
2309 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2310 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2311
2312 if pathOnHost != nil {
2313 // We need to copy the profile to a temporary path with the right filename because the apexer
2314 // will take the filename as is.
2315 ctx.Build(pctx, android.BuildParams{
2316 Rule: android.Cp,
2317 Input: pathOnHost,
2318 Output: tempPath,
2319 })
2320 } else {
2321 // At this point, the boot image profile cannot be generated. It is probably because the boot
2322 // image profile source file does not exist on the branch, or it is not available for the
2323 // current build target.
2324 // However, we cannot enforce the boot image profile to be generated because some build
2325 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2326 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2327 // only if the APEX is being built.
2328 ctx.Build(pctx, android.BuildParams{
2329 Rule: android.ErrorRule,
2330 Output: tempPath,
2331 Args: map[string]string{
2332 "error": "Boot image profile cannot be generated",
2333 },
2334 })
2335 }
2336
2337 androidMkModuleName := filepath.Base(pathInApex)
2338 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2339 filesToAdd = append(filesToAdd, af)
2340 }
2341
Paul Duffincc33ec82021-04-25 23:14:55 +01002342 return filesToAdd
2343}
2344
satayevb98371c2021-06-15 16:49:50 +01002345// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2346// the module contributes to the apex; or nil if the proto config was not generated.
2347func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2348 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2349 if !info.ClasspathFragmentProtoGenerated {
2350 return nil
2351 }
2352 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2353 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2354 return &af
satayev14e49132021-05-17 21:03:07 +01002355}
2356
Paul Duffincc33ec82021-04-25 23:14:55 +01002357// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2358// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002359func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2360 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2361
2362 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2363 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002364 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2365 if err != nil {
2366 ctx.ModuleErrorf("%s", err)
2367 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002368
2369 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2370 // bootclasspath_fragment.
2371 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2372 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002373}
2374
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002375///////////////////////////////////////////////////////////////////////////////////////////////////
2376// Factory functions
2377//
2378
2379func newApexBundle() *apexBundle {
2380 module := &apexBundle{}
2381
2382 module.AddProperties(&module.properties)
2383 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002384 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002385 module.AddProperties(&module.overridableProperties)
2386
2387 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
2388 android.InitDefaultableModule(module)
2389 android.InitSdkAwareModule(module)
2390 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002391 android.InitBazelModule(module)
Inseob Kim5eb7ee92022-04-27 10:30:34 +09002392 multitree.InitExportableModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002393 return module
2394}
2395
Paul Duffineb8051d2021-10-18 17:49:39 +01002396func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002397 bundle := newApexBundle()
2398 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002399 return bundle
2400}
2401
2402// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2403// certain compatibility checks such as apex_available are not done for apex_test.
2404func testApexBundleFactory() android.Module {
2405 bundle := newApexBundle()
2406 bundle.testApex = true
2407 return bundle
2408}
2409
2410// apex packages other modules into an APEX file which is a packaging format for system-level
2411// components like binaries, shared libraries, etc.
2412func BundleFactory() android.Module {
2413 return newApexBundle()
2414}
2415
2416type Defaults struct {
2417 android.ModuleBase
2418 android.DefaultsModuleBase
2419}
2420
2421// apex_defaults provides defaultable properties to other apex modules.
2422func defaultsFactory() android.Module {
2423 return DefaultsFactory()
2424}
2425
2426func DefaultsFactory(props ...interface{}) android.Module {
2427 module := &Defaults{}
2428
2429 module.AddProperties(props...)
2430 module.AddProperties(
2431 &apexBundleProperties{},
2432 &apexTargetBundleProperties{},
2433 &overridableProperties{},
2434 )
2435
2436 android.InitDefaultsModule(module)
2437 return module
2438}
2439
2440type OverrideApex struct {
2441 android.ModuleBase
2442 android.OverrideModuleBase
2443}
2444
2445func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2446 // All the overrides happen in the base module.
2447}
2448
2449// override_apex is used to create an apex module based on another apex module by overriding some of
2450// its properties.
2451func overrideApexFactory() android.Module {
2452 m := &OverrideApex{}
2453
2454 m.AddProperties(&overridableProperties{})
2455
2456 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2457 android.InitOverrideModule(m)
2458 return m
2459}
2460
2461///////////////////////////////////////////////////////////////////////////////////////////////////
2462// Vality check routines
2463//
2464// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2465// certain conditions are not met.
2466//
2467// TODO(jiyong): move these checks to a separate go file.
2468
satayevad991492021-12-03 18:58:32 +00002469var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2470
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002471// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
2472// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002473func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002474 if a.testApex || a.vndkApex {
2475 return
2476 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002477 // apexBundle::minSdkVersion reports its own errors.
2478 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002479 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002480}
2481
Albert Martineefabcf2022-03-21 20:11:16 +00002482// Returns apex's min_sdk_version string value, honoring overrides
2483func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
2484 // Only override the minSdkVersion value on Apexes which already specify
2485 // a min_sdk_version (it's optional for non-updatable apexes), and that its
2486 // min_sdk_version value is lower than the one to override with.
2487 overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride()
2488 overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue)
2489 originalMinApiLevel := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
2490 isMinSdkSet := a.properties.Min_sdk_version != nil
2491 isOverrideValueHigher := overrideApiLevel.CompareTo(originalMinApiLevel) > 0
2492 if overrideMinSdkValue != "" && isMinSdkSet && isOverrideValueHigher {
2493 return overrideMinSdkValue
2494 }
2495
2496 return proptools.String(a.properties.Min_sdk_version)
2497}
2498
2499// Returns apex's min_sdk_version SdkSpec, honoring overrides
satayevad991492021-12-03 18:58:32 +00002500func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
2501 return android.SdkSpec{
2502 Kind: android.SdkNone,
2503 ApiLevel: a.minSdkVersion(ctx),
Albert Martineefabcf2022-03-21 20:11:16 +00002504 Raw: a.minSdkVersionValue(ctx),
satayevad991492021-12-03 18:58:32 +00002505 }
2506}
2507
Albert Martineefabcf2022-03-21 20:11:16 +00002508// Returns apex's min_sdk_version ApiLevel, honoring overrides
satayevad991492021-12-03 18:58:32 +00002509func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Albert Martineefabcf2022-03-21 20:11:16 +00002510 return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx))
2511}
2512
2513// Construct ApiLevel object from min_sdk_version string value
2514func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel {
2515 if value == "" {
Jooyung Haned124c32021-01-26 11:43:46 +09002516 return android.NoneApiLevel
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002517 }
Albert Martineefabcf2022-03-21 20:11:16 +00002518 apiLevel, err := android.ApiLevelFromUser(ctx, value)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002519 if err != nil {
2520 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
2521 return android.NoneApiLevel
2522 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002523 return apiLevel
2524}
2525
2526// Ensures that a lib providing stub isn't statically linked
2527func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2528 // Practically, we only care about regular APEXes on the device.
2529 if ctx.Host() || a.testApex || a.vndkApex {
2530 return
2531 }
2532
2533 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2534
2535 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2536 if ccm, ok := to.(*cc.Module); ok {
2537 apexName := ctx.ModuleName()
2538 fromName := ctx.OtherModuleName(from)
2539 toName := ctx.OtherModuleName(to)
2540
2541 // If `to` is not actually in the same APEX as `from` then it does not need
2542 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002543 //
2544 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002545 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2546 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2547 return false
2548 }
2549
2550 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2551 // exception to this rule. It can't make the static dependencies dynamic
2552 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002553 // Same rule should be applied to linkerconfig, because it should be executed
2554 // only with static linked libraries before linker is available with ld.config.txt
2555 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002556 return false
2557 }
2558
2559 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2560 if isStubLibraryFromOtherApex && !externalDep {
2561 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2562 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2563 }
2564
2565 }
2566 return true
2567 })
2568}
2569
satayevb98371c2021-06-15 16:49:50 +01002570// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002571func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2572 if a.Updatable() {
Albert Martineefabcf2022-03-21 20:11:16 +00002573 if a.minSdkVersionValue(ctx) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002574 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2575 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002576 if a.UsePlatformApis() {
2577 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2578 }
Daniel Norman69109112021-12-02 12:52:42 -08002579 if a.SocSpecific() || a.DeviceSpecific() {
2580 ctx.PropertyErrorf("updatable", "vendor APEXes are not updatable")
2581 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002582 if a.FutureUpdatable() {
2583 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2584 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002585 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002586 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002587 }
2588}
2589
satayevb98371c2021-06-15 16:49:50 +01002590// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2591func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2592 ctx.VisitDirectDeps(func(module android.Module) {
2593 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2594 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2595 if !info.ClasspathFragmentProtoGenerated {
2596 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2597 }
2598 }
2599 })
2600}
2601
2602// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002603func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002604 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2605 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002606 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2607 tag := ctx.OtherModuleDependencyTag(module)
2608 switch tag {
2609 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002610 if m, ok := module.(interface {
2611 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2612 }); ok {
2613 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002614 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2615 }
2616 }
2617 }
2618 })
2619}
2620
satayevb98371c2021-06-15 16:49:50 +01002621// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002622func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2623 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2624 if ctx.Host() || a.testApex || a.vndkApex {
2625 return
2626 }
2627
2628 // Because APEXes targeting other than system/system_ext partitions can't set
2629 // apex_available, we skip checks for these APEXes
2630 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2631 return
2632 }
2633
2634 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2635 // Requiring them and their transitive depencies with apex_available is not right
2636 // because they just add noise.
2637 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2638 return
2639 }
2640
2641 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2642 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2643 if externalDep {
2644 return false
2645 }
2646
2647 apexName := ctx.ModuleName()
2648 fromName := ctx.OtherModuleName(from)
2649 toName := ctx.OtherModuleName(to)
2650
2651 // If `to` is not actually in the same APEX as `from` then it does not need
2652 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002653 //
2654 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002655 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2656 // As soon as the dependency graph crosses the APEX boundary, don't go
2657 // further.
2658 return false
2659 }
2660
2661 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2662 return true
2663 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002664 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2665 "\n\nDependency path:%s\n\n"+
2666 "Consider adding %q to 'apex_available' property of %q",
2667 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002668 // Visit this module's dependencies to check and report any issues with their availability.
2669 return true
2670 })
2671}
2672
Jiyong Park192600a2021-08-03 07:52:17 +00002673// checkStaticExecutable ensures that executables in an APEX are not static.
2674func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
Jiyong Parkd12979d2021-08-03 13:36:09 +09002675 // No need to run this for host APEXes
2676 if ctx.Host() {
2677 return
2678 }
2679
Jiyong Park192600a2021-08-03 07:52:17 +00002680 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2681 if ctx.OtherModuleDependencyTag(module) != executableTag {
2682 return
2683 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002684
2685 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002686 apex := a.ApexVariationName()
2687 exec := ctx.OtherModuleName(module)
2688 if isStaticExecutableAllowed(apex, exec) {
2689 return
2690 }
2691 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2692 }
2693 })
2694}
2695
2696// A small list of exceptions where static executables are allowed in APEXes.
2697func isStaticExecutableAllowed(apex string, exec string) bool {
2698 m := map[string][]string{
2699 "com.android.runtime": []string{
2700 "linker",
2701 "linkerconfig",
2702 },
2703 }
2704 execNames, ok := m[apex]
2705 return ok && android.InList(exec, execNames)
2706}
2707
braleeb0c1f0c2021-06-07 22:49:13 +08002708// Collect information for opening IDE project files in java/jdeps.go.
2709func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Remi NGUYEN VANbe901722022-03-02 21:00:33 +09002710 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Java_libs...)
2711 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Bootclasspath_fragments...)
2712 dpInfo.Deps = append(dpInfo.Deps, a.overridableProperties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002713 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2714}
2715
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002716var (
2717 apexAvailBaseline = makeApexAvailableBaseline()
2718 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2719)
2720
Colin Cross440e0d02020-06-11 11:32:11 -07002721func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002722 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002723 moduleName = normalizeModuleName(moduleName)
2724
Colin Cross440e0d02020-06-11 11:32:11 -07002725 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002726 return true
2727 }
2728
2729 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002730 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002731 return true
2732 }
2733
2734 return false
2735}
2736
2737func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002738 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2739 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002740 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002741 if strings.HasPrefix(moduleName, "libclang_rt.") {
2742 // This module has many arch variants that depend on the product being built.
2743 // We don't want to list them all
2744 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002745 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002746 if strings.HasPrefix(moduleName, "androidx.") {
2747 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2748 moduleName = "androidx"
2749 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002750 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002751}
2752
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002753// Transform the map of apex -> modules to module -> apexes.
2754func invertApexBaseline(m map[string][]string) map[string][]string {
2755 r := make(map[string][]string)
2756 for apex, modules := range m {
2757 for _, module := range modules {
2758 r[module] = append(r[module], apex)
2759 }
2760 }
2761 return r
2762}
2763
2764// Retrieve the baseline of apexes to which the supplied module belongs.
2765func BaselineApexAvailable(moduleName string) []string {
2766 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2767}
2768
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002769// This is a map from apex to modules, which overrides the apex_available setting for that
2770// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002771// TODO(b/147364041): remove this
2772func makeApexAvailableBaseline() map[string][]string {
2773 // The "Module separator"s below are employed to minimize merge conflicts.
2774 m := make(map[string][]string)
2775 //
2776 // Module separator
2777 //
2778 m["com.android.appsearch"] = []string{
2779 "icing-java-proto-lite",
2780 "libprotobuf-java-lite",
2781 }
2782 //
2783 // Module separator
2784 //
Etienne Ruffieux16512672021-12-15 15:49:04 +00002785 m["com.android.bluetooth"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002786 "android.hardware.audio.common@5.0",
2787 "android.hardware.bluetooth.a2dp@1.0",
2788 "android.hardware.bluetooth.audio@2.0",
2789 "android.hardware.bluetooth@1.0",
2790 "android.hardware.bluetooth@1.1",
2791 "android.hardware.graphics.bufferqueue@1.0",
2792 "android.hardware.graphics.bufferqueue@2.0",
2793 "android.hardware.graphics.common@1.0",
2794 "android.hardware.graphics.common@1.1",
2795 "android.hardware.graphics.common@1.2",
2796 "android.hardware.media@1.0",
2797 "android.hidl.safe_union@1.0",
2798 "android.hidl.token@1.0",
2799 "android.hidl.token@1.0-utils",
2800 "avrcp-target-service",
2801 "avrcp_headers",
2802 "bluetooth-protos-lite",
2803 "bluetooth.mapsapi",
2804 "com.android.vcard",
2805 "dnsresolver_aidl_interface-V2-java",
2806 "ipmemorystore-aidl-interfaces-V5-java",
2807 "ipmemorystore-aidl-interfaces-java",
2808 "internal_include_headers",
2809 "lib-bt-packets",
2810 "lib-bt-packets-avrcp",
2811 "lib-bt-packets-base",
2812 "libFraunhoferAAC",
2813 "libaudio-a2dp-hw-utils",
2814 "libaudio-hearing-aid-hw-utils",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002815 "libbluetooth",
2816 "libbluetooth-types",
2817 "libbluetooth-types-header",
2818 "libbluetooth_gd",
2819 "libbluetooth_headers",
2820 "libbluetooth_jni",
2821 "libbt-audio-hal-interface",
2822 "libbt-bta",
2823 "libbt-common",
2824 "libbt-hci",
2825 "libbt-platform-protos-lite",
2826 "libbt-protos-lite",
2827 "libbt-sbc-decoder",
2828 "libbt-sbc-encoder",
2829 "libbt-stack",
2830 "libbt-utils",
2831 "libbtcore",
2832 "libbtdevice",
2833 "libbte",
2834 "libbtif",
2835 "libchrome",
2836 "libevent",
2837 "libfmq",
2838 "libg722codec",
2839 "libgui_headers",
2840 "libmedia_headers",
2841 "libmodpb64",
2842 "libosi",
2843 "libstagefright_foundation_headers",
2844 "libstagefright_headers",
2845 "libstatslog",
2846 "libstatssocket",
2847 "libtinyxml2",
2848 "libudrv-uipc",
2849 "libz",
2850 "media_plugin_headers",
2851 "net-utils-services-common",
2852 "netd_aidl_interface-unstable-java",
2853 "netd_event_listener_interface-java",
2854 "netlink-client",
2855 "networkstack-client",
2856 "sap-api-java-static",
2857 "services.net",
2858 }
2859 //
2860 // Module separator
2861 //
2862 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2863 //
2864 // Module separator
2865 //
2866 m["com.android.extservices"] = []string{
2867 "error_prone_annotations",
2868 "ExtServices-core",
2869 "ExtServices",
2870 "libtextclassifier-java",
2871 "libz_current",
2872 "textclassifier-statsd",
2873 "TextClassifierNotificationLibNoManifest",
2874 "TextClassifierServiceLibNoManifest",
2875 }
2876 //
2877 // Module separator
2878 //
2879 m["com.android.neuralnetworks"] = []string{
2880 "android.hardware.neuralnetworks@1.0",
2881 "android.hardware.neuralnetworks@1.1",
2882 "android.hardware.neuralnetworks@1.2",
2883 "android.hardware.neuralnetworks@1.3",
2884 "android.hidl.allocator@1.0",
2885 "android.hidl.memory.token@1.0",
2886 "android.hidl.memory@1.0",
2887 "android.hidl.safe_union@1.0",
2888 "libarect",
2889 "libbuildversion",
2890 "libmath",
2891 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002892 }
2893 //
2894 // Module separator
2895 //
2896 m["com.android.media"] = []string{
2897 "android.frameworks.bufferhub@1.0",
2898 "android.hardware.cas.native@1.0",
2899 "android.hardware.cas@1.0",
2900 "android.hardware.configstore-utils",
2901 "android.hardware.configstore@1.0",
2902 "android.hardware.configstore@1.1",
2903 "android.hardware.graphics.allocator@2.0",
2904 "android.hardware.graphics.allocator@3.0",
2905 "android.hardware.graphics.bufferqueue@1.0",
2906 "android.hardware.graphics.bufferqueue@2.0",
2907 "android.hardware.graphics.common@1.0",
2908 "android.hardware.graphics.common@1.1",
2909 "android.hardware.graphics.common@1.2",
2910 "android.hardware.graphics.mapper@2.0",
2911 "android.hardware.graphics.mapper@2.1",
2912 "android.hardware.graphics.mapper@3.0",
2913 "android.hardware.media.omx@1.0",
2914 "android.hardware.media@1.0",
2915 "android.hidl.allocator@1.0",
2916 "android.hidl.memory.token@1.0",
2917 "android.hidl.memory@1.0",
2918 "android.hidl.token@1.0",
2919 "android.hidl.token@1.0-utils",
2920 "bionic_libc_platform_headers",
2921 "exoplayer2-extractor",
2922 "exoplayer2-extractor-annotation-stubs",
2923 "gl_headers",
2924 "jsr305",
2925 "libEGL",
2926 "libEGL_blobCache",
2927 "libEGL_getProcAddress",
2928 "libFLAC",
2929 "libFLAC-config",
2930 "libFLAC-headers",
2931 "libGLESv2",
2932 "libaacextractor",
2933 "libamrextractor",
2934 "libarect",
2935 "libaudio_system_headers",
2936 "libaudioclient",
2937 "libaudioclient_headers",
2938 "libaudiofoundation",
2939 "libaudiofoundation_headers",
2940 "libaudiomanager",
2941 "libaudiopolicy",
2942 "libaudioutils",
2943 "libaudioutils_fixedfft",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002944 "libbluetooth-types-header",
2945 "libbufferhub",
2946 "libbufferhub_headers",
2947 "libbufferhubqueue",
2948 "libc_malloc_debug_backtrace",
2949 "libcamera_client",
2950 "libcamera_metadata",
2951 "libdvr_headers",
2952 "libexpat",
2953 "libfifo",
2954 "libflacextractor",
2955 "libgrallocusage",
2956 "libgraphicsenv",
2957 "libgui",
2958 "libgui_headers",
2959 "libhardware_headers",
2960 "libinput",
2961 "liblzma",
2962 "libmath",
2963 "libmedia",
2964 "libmedia_codeclist",
2965 "libmedia_headers",
2966 "libmedia_helper",
2967 "libmedia_helper_headers",
2968 "libmedia_midiiowrapper",
2969 "libmedia_omx",
2970 "libmediautils",
2971 "libmidiextractor",
2972 "libmkvextractor",
2973 "libmp3extractor",
2974 "libmp4extractor",
2975 "libmpeg2extractor",
2976 "libnativebase_headers",
2977 "libnativewindow_headers",
2978 "libnblog",
2979 "liboggextractor",
2980 "libpackagelistparser",
2981 "libpdx",
2982 "libpdx_default_transport",
2983 "libpdx_headers",
2984 "libpdx_uds",
2985 "libprocinfo",
2986 "libspeexresampler",
2987 "libspeexresampler",
2988 "libstagefright_esds",
2989 "libstagefright_flacdec",
2990 "libstagefright_flacdec",
2991 "libstagefright_foundation",
2992 "libstagefright_foundation_headers",
2993 "libstagefright_foundation_without_imemory",
2994 "libstagefright_headers",
2995 "libstagefright_id3",
2996 "libstagefright_metadatautils",
2997 "libstagefright_mpeg2extractor",
2998 "libstagefright_mpeg2support",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002999 "libui",
3000 "libui_headers",
3001 "libunwindstack",
3002 "libvibrator",
3003 "libvorbisidec",
3004 "libwavextractor",
3005 "libwebm",
3006 "media_ndk_headers",
3007 "media_plugin_headers",
3008 "updatable-media",
3009 }
3010 //
3011 // Module separator
3012 //
3013 m["com.android.media.swcodec"] = []string{
3014 "android.frameworks.bufferhub@1.0",
3015 "android.hardware.common-ndk_platform",
3016 "android.hardware.configstore-utils",
3017 "android.hardware.configstore@1.0",
3018 "android.hardware.configstore@1.1",
3019 "android.hardware.graphics.allocator@2.0",
3020 "android.hardware.graphics.allocator@3.0",
3021 "android.hardware.graphics.allocator@4.0",
3022 "android.hardware.graphics.bufferqueue@1.0",
3023 "android.hardware.graphics.bufferqueue@2.0",
3024 "android.hardware.graphics.common-ndk_platform",
3025 "android.hardware.graphics.common@1.0",
3026 "android.hardware.graphics.common@1.1",
3027 "android.hardware.graphics.common@1.2",
3028 "android.hardware.graphics.mapper@2.0",
3029 "android.hardware.graphics.mapper@2.1",
3030 "android.hardware.graphics.mapper@3.0",
3031 "android.hardware.graphics.mapper@4.0",
3032 "android.hardware.media.bufferpool@2.0",
3033 "android.hardware.media.c2@1.0",
3034 "android.hardware.media.c2@1.1",
3035 "android.hardware.media.omx@1.0",
3036 "android.hardware.media@1.0",
3037 "android.hardware.media@1.0",
3038 "android.hidl.memory.token@1.0",
3039 "android.hidl.memory@1.0",
3040 "android.hidl.safe_union@1.0",
3041 "android.hidl.token@1.0",
3042 "android.hidl.token@1.0-utils",
3043 "libEGL",
3044 "libFLAC",
3045 "libFLAC-config",
3046 "libFLAC-headers",
3047 "libFraunhoferAAC",
3048 "libLibGuiProperties",
3049 "libarect",
3050 "libaudio_system_headers",
3051 "libaudioutils",
3052 "libaudioutils",
3053 "libaudioutils_fixedfft",
3054 "libavcdec",
3055 "libavcenc",
3056 "libavservices_minijail",
3057 "libavservices_minijail",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003058 "libbinderthreadstateutils",
3059 "libbluetooth-types-header",
3060 "libbufferhub_headers",
3061 "libcodec2",
3062 "libcodec2_headers",
3063 "libcodec2_hidl@1.0",
3064 "libcodec2_hidl@1.1",
3065 "libcodec2_internal",
3066 "libcodec2_soft_aacdec",
3067 "libcodec2_soft_aacenc",
3068 "libcodec2_soft_amrnbdec",
3069 "libcodec2_soft_amrnbenc",
3070 "libcodec2_soft_amrwbdec",
3071 "libcodec2_soft_amrwbenc",
3072 "libcodec2_soft_av1dec_gav1",
3073 "libcodec2_soft_avcdec",
3074 "libcodec2_soft_avcenc",
3075 "libcodec2_soft_common",
3076 "libcodec2_soft_flacdec",
3077 "libcodec2_soft_flacenc",
3078 "libcodec2_soft_g711alawdec",
3079 "libcodec2_soft_g711mlawdec",
3080 "libcodec2_soft_gsmdec",
3081 "libcodec2_soft_h263dec",
3082 "libcodec2_soft_h263enc",
3083 "libcodec2_soft_hevcdec",
3084 "libcodec2_soft_hevcenc",
3085 "libcodec2_soft_mp3dec",
3086 "libcodec2_soft_mpeg2dec",
3087 "libcodec2_soft_mpeg4dec",
3088 "libcodec2_soft_mpeg4enc",
3089 "libcodec2_soft_opusdec",
3090 "libcodec2_soft_opusenc",
3091 "libcodec2_soft_rawdec",
3092 "libcodec2_soft_vorbisdec",
3093 "libcodec2_soft_vp8dec",
3094 "libcodec2_soft_vp8enc",
3095 "libcodec2_soft_vp9dec",
3096 "libcodec2_soft_vp9enc",
3097 "libcodec2_vndk",
3098 "libdvr_headers",
3099 "libfmq",
3100 "libfmq",
3101 "libgav1",
3102 "libgralloctypes",
3103 "libgrallocusage",
3104 "libgraphicsenv",
3105 "libgsm",
3106 "libgui_bufferqueue_static",
3107 "libgui_headers",
3108 "libhardware",
3109 "libhardware_headers",
3110 "libhevcdec",
3111 "libhevcenc",
3112 "libion",
3113 "libjpeg",
3114 "liblzma",
3115 "libmath",
3116 "libmedia_codecserviceregistrant",
3117 "libmedia_headers",
3118 "libmpeg2dec",
3119 "libnativebase_headers",
3120 "libnativewindow_headers",
3121 "libpdx_headers",
3122 "libscudo_wrapper",
3123 "libsfplugin_ccodec_utils",
3124 "libspeexresampler",
3125 "libstagefright_amrnb_common",
3126 "libstagefright_amrnbdec",
3127 "libstagefright_amrnbenc",
3128 "libstagefright_amrwbdec",
3129 "libstagefright_amrwbenc",
3130 "libstagefright_bufferpool@2.0.1",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003131 "libstagefright_enc_common",
3132 "libstagefright_flacdec",
3133 "libstagefright_foundation",
3134 "libstagefright_foundation_headers",
3135 "libstagefright_headers",
3136 "libstagefright_m4vh263dec",
3137 "libstagefright_m4vh263enc",
3138 "libstagefright_mp3dec",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003139 "libui",
3140 "libui_headers",
3141 "libunwindstack",
3142 "libvorbisidec",
3143 "libvpx",
3144 "libyuv",
3145 "libyuv_static",
3146 "media_ndk_headers",
3147 "media_plugin_headers",
3148 "mediaswcodec",
3149 }
3150 //
3151 // Module separator
3152 //
3153 m["com.android.mediaprovider"] = []string{
3154 "MediaProvider",
3155 "MediaProviderGoogle",
3156 "fmtlib_ndk",
3157 "libbase_ndk",
3158 "libfuse",
3159 "libfuse_jni",
3160 }
3161 //
3162 // Module separator
3163 //
3164 m["com.android.permission"] = []string{
3165 "car-ui-lib",
3166 "iconloader",
3167 "kotlin-annotations",
3168 "kotlin-stdlib",
3169 "kotlin-stdlib-jdk7",
3170 "kotlin-stdlib-jdk8",
3171 "kotlinx-coroutines-android",
3172 "kotlinx-coroutines-android-nodeps",
3173 "kotlinx-coroutines-core",
3174 "kotlinx-coroutines-core-nodeps",
3175 "permissioncontroller-statsd",
3176 "GooglePermissionController",
3177 "PermissionController",
3178 "SettingsLibActionBarShadow",
3179 "SettingsLibAppPreference",
3180 "SettingsLibBarChartPreference",
3181 "SettingsLibLayoutPreference",
3182 "SettingsLibProgressBar",
3183 "SettingsLibSearchWidget",
3184 "SettingsLibSettingsTheme",
3185 "SettingsLibRestrictedLockUtils",
3186 "SettingsLibHelpUtils",
3187 }
3188 //
3189 // Module separator
3190 //
3191 m["com.android.runtime"] = []string{
3192 "bionic_libc_platform_headers",
3193 "libarm-optimized-routines-math",
3194 "libc_aeabi",
3195 "libc_bionic",
3196 "libc_bionic_ndk",
3197 "libc_bootstrap",
3198 "libc_common",
3199 "libc_common_shared",
3200 "libc_common_static",
3201 "libc_dns",
3202 "libc_dynamic_dispatch",
3203 "libc_fortify",
3204 "libc_freebsd",
3205 "libc_freebsd_large_stack",
3206 "libc_gdtoa",
3207 "libc_init_dynamic",
3208 "libc_init_static",
3209 "libc_jemalloc_wrapper",
3210 "libc_netbsd",
3211 "libc_nomalloc",
3212 "libc_nopthread",
3213 "libc_openbsd",
3214 "libc_openbsd_large_stack",
3215 "libc_openbsd_ndk",
3216 "libc_pthread",
3217 "libc_static_dispatch",
3218 "libc_syscalls",
3219 "libc_tzcode",
3220 "libc_unwind_static",
3221 "libdebuggerd",
3222 "libdebuggerd_common_headers",
3223 "libdebuggerd_handler_core",
3224 "libdebuggerd_handler_fallback",
3225 "libdl_static",
3226 "libjemalloc5",
3227 "liblinker_main",
3228 "liblinker_malloc",
3229 "liblz4",
3230 "liblzma",
3231 "libprocinfo",
3232 "libpropertyinfoparser",
3233 "libscudo",
3234 "libstdc++",
3235 "libsystemproperties",
3236 "libtombstoned_client_static",
3237 "libunwindstack",
3238 "libz",
3239 "libziparchive",
3240 }
3241 //
3242 // Module separator
3243 //
3244 m["com.android.tethering"] = []string{
3245 "android.hardware.tetheroffload.config-V1.0-java",
3246 "android.hardware.tetheroffload.control-V1.0-java",
3247 "android.hidl.base-V1.0-java",
3248 "libcgrouprc",
3249 "libcgrouprc_format",
3250 "libtetherutilsjni",
3251 "libvndksupport",
3252 "net-utils-framework-common",
3253 "netd_aidl_interface-V3-java",
3254 "netlink-client",
3255 "networkstack-aidl-interfaces-java",
3256 "tethering-aidl-interfaces-java",
3257 "TetheringApiCurrentLib",
3258 }
3259 //
3260 // Module separator
3261 //
3262 m["com.android.wifi"] = []string{
3263 "PlatformProperties",
3264 "android.hardware.wifi-V1.0-java",
3265 "android.hardware.wifi-V1.0-java-constants",
3266 "android.hardware.wifi-V1.1-java",
3267 "android.hardware.wifi-V1.2-java",
3268 "android.hardware.wifi-V1.3-java",
3269 "android.hardware.wifi-V1.4-java",
3270 "android.hardware.wifi.hostapd-V1.0-java",
3271 "android.hardware.wifi.hostapd-V1.1-java",
3272 "android.hardware.wifi.hostapd-V1.2-java",
3273 "android.hardware.wifi.supplicant-V1.0-java",
3274 "android.hardware.wifi.supplicant-V1.1-java",
3275 "android.hardware.wifi.supplicant-V1.2-java",
3276 "android.hardware.wifi.supplicant-V1.3-java",
3277 "android.hidl.base-V1.0-java",
3278 "android.hidl.manager-V1.0-java",
3279 "android.hidl.manager-V1.1-java",
3280 "android.hidl.manager-V1.2-java",
3281 "bouncycastle-unbundled",
3282 "dnsresolver_aidl_interface-V2-java",
3283 "error_prone_annotations",
3284 "framework-wifi-pre-jarjar",
3285 "framework-wifi-util-lib",
3286 "ipmemorystore-aidl-interfaces-V3-java",
3287 "ipmemorystore-aidl-interfaces-java",
3288 "ksoap2",
3289 "libnanohttpd",
3290 "libwifi-jni",
3291 "net-utils-services-common",
3292 "netd_aidl_interface-V2-java",
3293 "netd_aidl_interface-unstable-java",
3294 "netd_event_listener_interface-java",
3295 "netlink-client",
3296 "networkstack-client",
3297 "services.net",
3298 "wifi-lite-protos",
3299 "wifi-nano-protos",
3300 "wifi-service-pre-jarjar",
3301 "wifi-service-resources",
3302 }
3303 //
3304 // Module separator
3305 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003306 m["com.android.os.statsd"] = []string{
3307 "libstatssocket",
3308 }
3309 //
3310 // Module separator
3311 //
3312 m[android.AvailableToAnyApex] = []string{
3313 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
3314 "androidx",
3315 "androidx-constraintlayout_constraintlayout",
3316 "androidx-constraintlayout_constraintlayout-nodeps",
3317 "androidx-constraintlayout_constraintlayout-solver",
3318 "androidx-constraintlayout_constraintlayout-solver-nodeps",
3319 "com.google.android.material_material",
3320 "com.google.android.material_material-nodeps",
3321
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003322 "libclang_rt",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003323 "libprofile-clang-extras",
3324 "libprofile-clang-extras_ndk",
3325 "libprofile-extras",
3326 "libprofile-extras_ndk",
Ryan Prichardb35a85e2021-01-13 19:18:53 -08003327 "libunwind",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003328 }
3329 return m
3330}
3331
3332func init() {
Spandan Dasf14e2542021-11-12 00:01:37 +00003333 android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...)
3334 android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003335}
3336
Spandan Dasf14e2542021-11-12 00:01:37 +00003337func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule {
3338 rules := make([]android.Rule, 0, len(bcpPermittedPackages))
3339 for jar, permittedPackages := range bcpPermittedPackages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003340 permittedPackagesRule := android.NeverAllow().
Spandan Dasf14e2542021-11-12 00:01:37 +00003341 With("name", jar).
3342 WithMatcher("permitted_packages", android.NotInList(permittedPackages)).
3343 Because(jar +
3344 " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") +
Anton Hanssone1b18362021-12-23 15:05:38 +00003345 ". Please consider the following alternatives:\n" +
Andrei Onead967aee2022-01-19 15:36:40 +00003346 " 1. If the offending code is from a statically linked library, consider " +
3347 "removing that dependency and using an alternative already in the " +
3348 "bootclasspath, or perhaps a shared library." +
3349 " 2. Move the offending code into an allowed package.\n" +
3350 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3351 "health implications of bundling that code, particularly if the offending jar " +
3352 "is part of the bootclasspath.")
Spandan Dasf14e2542021-11-12 00:01:37 +00003353
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003354 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003355 }
3356 return rules
3357}
3358
Anton Hanssone1b18362021-12-23 15:05:38 +00003359// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003360// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003361func qBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003362 return map[string][]string{
Spandan Dasf14e2542021-11-12 00:01:37 +00003363 "conscrypt": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003364 "android.net.ssl",
3365 "com.android.org.conscrypt",
3366 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003367 "updatable-media": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003368 "android.media",
3369 },
3370 }
3371}
3372
Anton Hanssone1b18362021-12-23 15:05:38 +00003373// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003374// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003375func rBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003376 return map[string][]string{
Spandan Dasf14e2542021-11-12 00:01:37 +00003377 "framework-mediaprovider": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003378 "android.provider",
3379 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003380 "framework-permission": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003381 "android.permission",
3382 "android.app.role",
3383 "com.android.permission",
3384 "com.android.role",
3385 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003386 "framework-sdkextensions": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003387 "android.os.ext",
3388 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003389 "framework-statsd": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003390 "android.app",
3391 "android.os",
3392 "android.util",
3393 "com.android.internal.statsd",
3394 "com.android.server.stats",
3395 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003396 "framework-wifi": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003397 "com.android.server.wifi",
3398 "com.android.wifi.x",
3399 "android.hardware.wifi",
3400 "android.net.wifi",
3401 },
Spandan Dasf14e2542021-11-12 00:01:37 +00003402 "framework-tethering": []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003403 "android.net",
3404 },
3405 }
3406}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003407
3408// For Bazel / bp2build
3409
3410type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003411 Manifest bazel.LabelAttribute
3412 Android_manifest bazel.LabelAttribute
3413 File_contexts bazel.LabelAttribute
3414 Key bazel.LabelAttribute
3415 Certificate bazel.LabelAttribute
3416 Min_sdk_version *string
3417 Updatable bazel.BoolAttribute
3418 Installable bazel.BoolAttribute
3419 Binaries bazel.LabelListAttribute
3420 Prebuilts bazel.LabelListAttribute
3421 Native_shared_libs_32 bazel.LabelListAttribute
3422 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003423 Compressible bazel.BoolAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003424}
3425
3426type convertedNativeSharedLibs struct {
3427 Native_shared_libs_32 bazel.LabelListAttribute
3428 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003429}
3430
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003431// ConvertWithBp2build performs bp2build conversion of an apex
3432func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
3433 // We do not convert apex_test modules at this time
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003434 if ctx.ModuleType() != "apex" {
3435 return
3436 }
3437
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003438 var manifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003439 if a.properties.Manifest != nil {
3440 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003441 }
3442
3443 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003444 if a.properties.AndroidManifest != nil {
3445 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003446 }
3447
3448 var fileContextsLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003449 if a.properties.File_contexts != nil {
3450 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003451 }
3452
Albert Martineefabcf2022-03-21 20:11:16 +00003453 // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
3454 // given it's coming via config, we probably don't want to put it in here.
Liz Kammer46fb7ab2021-12-01 10:09:34 -05003455 var minSdkVersion *string
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003456 if a.properties.Min_sdk_version != nil {
3457 minSdkVersion = a.properties.Min_sdk_version
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003458 }
3459
3460 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003461 if a.overridableProperties.Key != nil {
3462 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003463 }
3464
3465 var certificateLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003466 if a.overridableProperties.Certificate != nil {
3467 certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Certificate))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003468 }
3469
Yu Liu4ae55d12022-01-05 17:17:23 -08003470 nativeSharedLibs := &convertedNativeSharedLibs{
3471 Native_shared_libs_32: bazel.LabelListAttribute{},
3472 Native_shared_libs_64: bazel.LabelListAttribute{},
3473 }
3474 compileMultilib := "both"
3475 if a.CompileMultilib() != nil {
3476 compileMultilib = *a.CompileMultilib()
3477 }
3478
3479 // properties.Native_shared_libs is treated as "both"
3480 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3481 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3482 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3483 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3484 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003485
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003486 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003487 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3488 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3489
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003490 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003491 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003492
3493 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003494 if a.properties.Updatable != nil {
3495 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003496 }
3497
3498 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003499 if a.properties.Installable != nil {
3500 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003501 }
3502
Wei Lif034cb42022-01-19 15:54:31 -08003503 var compressibleAttribute bazel.BoolAttribute
3504 if a.overridableProperties.Compressible != nil {
3505 compressibleAttribute.Value = a.overridableProperties.Compressible
3506 }
3507
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003508 attrs := &bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003509 Manifest: manifestLabelAttribute,
3510 Android_manifest: androidManifestLabelAttribute,
3511 File_contexts: fileContextsLabelAttribute,
3512 Min_sdk_version: minSdkVersion,
3513 Key: keyLabelAttribute,
3514 Certificate: certificateLabelAttribute,
3515 Updatable: updatableAttribute,
3516 Installable: installableAttribute,
3517 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3518 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3519 Binaries: binariesLabelListAttribute,
3520 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003521 Compressible: compressibleAttribute,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003522 }
3523
3524 props := bazel.BazelTargetModuleProperties{
3525 Rule_class: "apex",
3526 Bzl_load_location: "//build/bazel/rules:apex.bzl",
3527 }
3528
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003529 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003530}
Yu Liu4ae55d12022-01-05 17:17:23 -08003531
3532// The following conversions are based on this table where the rows are the compile_multilib
3533// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3534// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3535// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3536// should not be compiled.
3537// multib/compile_multilib, 32, 64, both, first
3538// 32, 32/32, none/none, 32/32, none/32
3539// 64, none/none, 64/none, 64/none, 64/none
3540// both, 32/32, 64/none, 32&64/32, 64/32
3541// first, 32/32, 64/none, 64/32, 64/32
3542
3543func convert32Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3544 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3545 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3546 switch compileMultilb {
3547 case "both", "32":
3548 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3549 case "first":
3550 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3551 case "64":
3552 // Incompatible, ignore
3553 default:
3554 invalidCompileMultilib(ctx, compileMultilb)
3555 }
3556}
3557
3558func convert64Libs(ctx android.TopDownMutatorContext, compileMultilb string,
3559 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3560 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3561 switch compileMultilb {
3562 case "both", "64", "first":
3563 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3564 case "32":
3565 // Incompatible, ignore
3566 default:
3567 invalidCompileMultilib(ctx, compileMultilb)
3568 }
3569}
3570
3571func convertBothLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3572 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3573 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3574 switch compileMultilb {
3575 case "both":
3576 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3577 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3578 case "first":
3579 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3580 case "32":
3581 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3582 case "64":
3583 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3584 default:
3585 invalidCompileMultilib(ctx, compileMultilb)
3586 }
3587}
3588
3589func convertFirstLibs(ctx android.TopDownMutatorContext, compileMultilb string,
3590 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3591 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3592 switch compileMultilb {
3593 case "both", "first":
3594 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3595 case "32":
3596 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3597 case "64":
3598 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3599 default:
3600 invalidCompileMultilib(ctx, compileMultilb)
3601 }
3602}
3603
3604func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3605 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3606 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3607}
3608
3609func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3610 list := bazel.LabelListAttribute{}
3611 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3612 nativeSharedLibs.Native_shared_libs_32.Append(list)
3613}
3614
3615func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3616 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3617 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3618}
3619
3620func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3621 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3622 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3623}
3624
3625func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3626 labelListAttr *bazel.LabelListAttribute) {
3627 list := bazel.LabelListAttribute{}
3628 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3629 labelListAttr.Append(list)
3630}
3631
3632func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
3633 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3634}