blob: adabdeefd82b92eb7117042c7d8a89b70b5a4f5e [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"
Kiyoung Kimcbe2ba02023-09-07 16:00:04 +090021 "log"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "path/filepath"
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +000023 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090024 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "strings"
26
Yu Liu4c212ce2022-10-14 12:20:20 -070027 "android/soong/bazel/cquery"
28
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029 "github.com/google/blueprint"
30 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070031
32 "android/soong/android"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040033 "android/soong/bazel"
markchien2f59ec92020-09-02 16:23:38 +080034 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070035 "android/soong/cc"
36 prebuilt_etc "android/soong/etc"
Jiyong Park12a719c2021-01-07 15:31:24 +090037 "android/soong/filesystem"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038 "android/soong/java"
Inseob Kim5eb7ee92022-04-27 10:30:34 +090039 "android/soong/multitree"
Jiyong Park99644e92020-11-17 22:21:02 +090040 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070041 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090042)
43
Jiyong Park8e6d52f2020-11-19 14:37:47 +090044func init() {
Paul Duffin667893c2021-03-09 22:34:13 +000045 registerApexBuildComponents(android.InitRegistrationContext)
46}
Jiyong Park8e6d52f2020-11-19 14:37:47 +090047
Paul Duffin667893c2021-03-09 22:34:13 +000048func registerApexBuildComponents(ctx android.RegistrationContext) {
49 ctx.RegisterModuleType("apex", BundleFactory)
Yu Liu4c212ce2022-10-14 12:20:20 -070050 ctx.RegisterModuleType("apex_test", TestApexBundleFactory)
Paul Duffin667893c2021-03-09 22:34:13 +000051 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Cole Faust912bc882023-03-08 12:29:50 -080052 ctx.RegisterModuleType("apex_defaults", DefaultsFactory)
Paul Duffin667893c2021-03-09 22:34:13 +000053 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070054 ctx.RegisterModuleType("override_apex", OverrideApexFactory)
Paul Duffin667893c2021-03-09 22:34:13 +000055 ctx.RegisterModuleType("apex_set", apexSetFactory)
56
Paul Duffin5dda3e32021-05-05 14:13:27 +010057 ctx.PreArchMutators(registerPreArchMutators)
Paul Duffin667893c2021-03-09 22:34:13 +000058 ctx.PreDepsMutators(RegisterPreDepsMutators)
59 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jiyong Park8e6d52f2020-11-19 14:37:47 +090060}
61
Paul Duffin5dda3e32021-05-05 14:13:27 +010062func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
63 ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel()
64}
65
Jiyong Park8e6d52f2020-11-19 14:37:47 +090066func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
67 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
68 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
69}
70
71func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Paul Duffin949abc02020-12-08 10:34:30 +000072 ctx.TopDown("apex_info", apexInfoMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090073 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
74 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
75 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Paul Duffin28bf7ee2021-05-12 16:41:35 +010076 // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
77 // it should create a platform variant.
78 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090079 ctx.BottomUp("apex", apexMutator).Parallel()
80 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
Dennis Shene2ed70c2023-01-11 14:15:43 +000081 ctx.BottomUp("apex_dcla_deps", apexDCLADepsMutator).Parallel()
Spandan Das66773252022-01-15 00:23:18 +000082 // Register after apex_info mutator so that it can use ApexVariationName
83 ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel()
Jiyong Park8e6d52f2020-11-19 14:37:47 +090084}
85
86type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090087 // Json manifest file describing meta info of this APEX bundle. Refer to
88 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090089 Manifest *string `android:"path"`
90
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090091 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
92 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090093 AndroidManifest *string `android:"path"`
94
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090095 // Determines the file contexts file for setting the security contexts to files in this APEX
96 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
97 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090098 File_contexts *string `android:"path"`
99
Jooyung Hanaf730952023-02-28 14:13:38 +0900100 // By default, file_contexts is amended by force-labelling / and /apex_manifest.pb as system_file
101 // to avoid mistakes. When set as true, no force-labelling.
102 Use_file_contexts_as_is *bool
103
Jingwen Chendea7a642023-03-28 11:30:50 +0000104 // Path to the canned fs config file for customizing file's
105 // uid/gid/mod/capabilities. The content of this file is appended to the
106 // default config, so that the custom entries are preferred. The format is
107 // /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where
108 // path_or_glob is a path or glob pattern for a file or set of files,
109 // uid/gid are numerial values of user ID and group ID, mode is octal value
110 // for the file mode, and cap is hexadecimal value for the capability.
Jiyong Park038e8522021-12-13 23:56:35 +0900111 Canned_fs_config *string `android:"path"`
112
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900113 ApexNativeDependencies
114
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900115 Multilib apexMultilibProperties
116
Anton Hansson72e7ffe2023-02-24 11:12:31 +0000117 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
118 Rros []string
119
Anton Hanssone7545852023-02-24 11:06:07 +0000120 // List of bootclasspath fragments that are embedded inside this APEX bundle.
121 Bootclasspath_fragments []string
122
123 // List of systemserverclasspath fragments that are embedded inside this APEX bundle.
124 Systemserverclasspath_fragments []string
125
126 // List of java libraries that are embedded inside this APEX bundle.
127 Java_libs []string
128
Sundong Ahn80c04892021-11-23 00:57:19 +0000129 // List of sh binaries that are embedded inside this APEX bundle.
130 Sh_binaries []string
131
Paul Duffin3abc1742021-03-15 19:32:23 +0000132 // List of platform_compat_config files that are embedded inside this APEX bundle.
133 Compat_configs []string
134
Jiyong Park12a719c2021-01-07 15:31:24 +0900135 // List of filesystem images that are embedded inside this APEX bundle.
136 Filesystems []string
137
Liz Kammerbd58e742023-05-11 15:58:13 +0000138 // The minimum SDK version that this APEX must support at minimum. This is usually set to
139 // the SDK version that the APEX was first introduced.
140 Min_sdk_version *string
141
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900142 // Whether this APEX is considered updatable or not. When set to true, this will enforce
143 // additional rules for making sure that the APEX is truly updatable. To be updatable,
144 // min_sdk_version should be set as well. This will also disable the size optimizations like
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000145 // symlinking to the system libs. Default is true.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900146 Updatable *bool
147
Jiyong Parkf4020582021-11-29 12:37:10 +0900148 // Marks that this APEX is designed to be updatable in the future, although it's not
149 // updatable yet. This is used to mimic some of the build behaviors that are applied only to
150 // updatable APEXes. Currently, this disables the size optimization, so that the size of
151 // APEX will not increase when the APEX is actually marked as truly updatable. Default is
152 // false.
153 Future_updatable *bool
154
Jiyong Park1bc84122021-06-22 20:23:05 +0900155 // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable:
156 // false`. Default is false.
157 Platform_apis *bool
158
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900159 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
160 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900161 Installable *bool
162
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900163 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
164 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
165 Use_vndk_as_stable *bool
166
Jooyung Han06a8a1c2023-08-23 11:11:43 +0900167 // The type of filesystem to use. Either 'ext4', 'f2fs' or 'erofs'. Default 'ext4'.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900168 Payload_fs_type *string
169
170 // For telling the APEX to ignore special handling for system libraries such as bionic.
171 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900172 Ignore_system_library_special_case *bool
173
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100174 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
Nikita Ioffee261ae62021-06-16 18:15:03 +0100175 // Default value is true.
Nikita Ioffeda6dc312021-06-09 19:43:46 +0100176 Generate_hashtree *bool
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900177
178 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
179 // used in tests.
180 Test_only_unsigned_payload *bool
181
Mohammad Samiul Islama8008f92020-12-22 10:47:50 +0000182 // Whenever apex should be compressed, regardless of product flag used. Should be only
183 // used in tests.
184 Test_only_force_compression *bool
185
Jooyung Han09c11ad2021-10-27 03:45:31 +0900186 // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex
187 // with the tool to sign payload contents.
188 Custom_sign_tool *string
189
Dennis Shenaf41bc12022-08-03 16:46:43 +0000190 // Whether this is a dynamic common lib apex, if so the native shared libs will be placed
191 // in a special way that include the digest of the lib file under /lib(64)?
192 Dynamic_common_lib_apex *bool
193
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100194 // Canonical name of this APEX bundle. Used to determine the path to the
195 // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the
196 // apex mutator variations. For override_apex modules, this is the name of the
197 // overridden base module.
198 ApexVariationName string `blueprint:"mutated"`
199
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900200 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900201
202 // List of sanitizer names that this APEX is enabled for
203 SanitizerNames []string `blueprint:"mutated"`
204
205 PreventInstall bool `blueprint:"mutated"`
206
207 HideFromMake bool `blueprint:"mutated"`
208
Sam Delmericoca816532023-06-02 14:09:50 -0400209 // Name that dependencies can specify in their apex_available properties to refer to this module.
Sam Delmericoc3df1132023-06-06 12:14:23 -0400210 // If not specified, this defaults to Soong module name. This must be the name of a Soong module.
Sam Delmericoca816532023-06-02 14:09:50 -0400211 Apex_available_name *string
Sam Delmerico6d65a0f2023-06-05 15:55:57 -0400212
213 // Variant version of the mainline module. Must be an integer between 0-9
214 Variant_version *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900215}
216
217type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900218 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900219 Native_shared_libs []string
220
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900221 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900222 Jni_libs []string
223
Colin Cross70572ed2022-11-02 13:14:20 -0700224 // List of rust dyn libraries that are embedded inside this APEX.
Jiyong Park99644e92020-11-17 22:21:02 +0900225 Rust_dyn_libs []string
226
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900227 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900228 Binaries []string
229
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900230 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900231 Tests []string
Jiyong Park06711462021-02-15 17:54:43 +0900232
233 // List of filesystem images that are embedded inside this APEX bundle.
234 Filesystems []string
Colin Cross70572ed2022-11-02 13:14:20 -0700235
236 // List of native libraries to exclude from this APEX.
237 Exclude_native_shared_libs []string
238
239 // List of JNI libraries to exclude from this APEX.
240 Exclude_jni_libs []string
241
242 // List of rust dyn libraries to exclude from this APEX.
243 Exclude_rust_dyn_libs []string
244
245 // List of native executables to exclude from this APEX.
246 Exclude_binaries []string
247
248 // List of native tests to exclude from this APEX.
249 Exclude_tests []string
250
251 // List of filesystem images to exclude from this APEX bundle.
252 Exclude_filesystems []string
253}
254
255// Merge combines another ApexNativeDependencies into this one
256func (a *ApexNativeDependencies) Merge(b ApexNativeDependencies) {
257 a.Native_shared_libs = append(a.Native_shared_libs, b.Native_shared_libs...)
258 a.Jni_libs = append(a.Jni_libs, b.Jni_libs...)
259 a.Rust_dyn_libs = append(a.Rust_dyn_libs, b.Rust_dyn_libs...)
260 a.Binaries = append(a.Binaries, b.Binaries...)
261 a.Tests = append(a.Tests, b.Tests...)
262 a.Filesystems = append(a.Filesystems, b.Filesystems...)
263
264 a.Exclude_native_shared_libs = append(a.Exclude_native_shared_libs, b.Exclude_native_shared_libs...)
265 a.Exclude_jni_libs = append(a.Exclude_jni_libs, b.Exclude_jni_libs...)
266 a.Exclude_rust_dyn_libs = append(a.Exclude_rust_dyn_libs, b.Exclude_rust_dyn_libs...)
267 a.Exclude_binaries = append(a.Exclude_binaries, b.Exclude_binaries...)
268 a.Exclude_tests = append(a.Exclude_tests, b.Exclude_tests...)
269 a.Exclude_filesystems = append(a.Exclude_filesystems, b.Exclude_filesystems...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900270}
271
272type apexMultilibProperties struct {
273 // Native dependencies whose compile_multilib is "first"
274 First ApexNativeDependencies
275
276 // Native dependencies whose compile_multilib is "both"
277 Both ApexNativeDependencies
278
279 // Native dependencies whose compile_multilib is "prefer32"
280 Prefer32 ApexNativeDependencies
281
282 // Native dependencies whose compile_multilib is "32"
283 Lib32 ApexNativeDependencies
284
285 // Native dependencies whose compile_multilib is "64"
286 Lib64 ApexNativeDependencies
287}
288
289type apexTargetBundleProperties struct {
290 Target struct {
291 // Multilib properties only for android.
292 Android struct {
293 Multilib apexMultilibProperties
294 }
295
296 // Multilib properties only for host.
297 Host struct {
298 Multilib apexMultilibProperties
299 }
300
301 // Multilib properties only for host linux_bionic.
302 Linux_bionic struct {
303 Multilib apexMultilibProperties
304 }
305
306 // Multilib properties only for host linux_glibc.
307 Linux_glibc struct {
308 Multilib apexMultilibProperties
309 }
310 }
311}
312
Jiyong Park59140302020-12-14 18:44:04 +0900313type apexArchBundleProperties struct {
314 Arch struct {
315 Arm struct {
316 ApexNativeDependencies
317 }
318 Arm64 struct {
319 ApexNativeDependencies
320 }
Colin Crossa2aaa2f2022-10-03 12:41:50 -0700321 Riscv64 struct {
322 ApexNativeDependencies
323 }
Jiyong Park59140302020-12-14 18:44:04 +0900324 X86 struct {
325 ApexNativeDependencies
326 }
327 X86_64 struct {
328 ApexNativeDependencies
329 }
330 }
331}
332
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900333// These properties can be used in override_apex to override the corresponding properties in the
334// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900335type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900336 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900337 Apps []string
338
Daniel Norman5a3ce132021-08-26 15:44:43 -0700339 // List of prebuilt files that are embedded inside this APEX bundle.
340 Prebuilts []string
341
markchien7c803b82021-08-26 22:10:06 +0800342 // List of BPF programs inside this APEX bundle.
343 Bpfs []string
344
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900345 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
346 // Soong). This does not completely prevent installation of the overridden binaries, but if
347 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
348 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900349 Overrides []string
350
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900351 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352 Logging_parent string
353
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900354 // Apex Container package name. Override value for attribute package:name in
355 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356 Package_name string
357
358 // A txt file containing list of files that are allowed to be included in this APEX.
359 Allowed_files *string `android:"path"`
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700360
361 // Name of the apex_key module that provides the private key to sign this APEX bundle.
362 Key *string
363
364 // Specifies the certificate and the private key to sign the zip container of this APEX. If
365 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
366 // as the certificate and the private key, respectively. If this is ":module", then the
367 // certificate and the private key are provided from the android_app_certificate module
368 // named "module".
369 Certificate *string
Oriol Prieto Gascoa07099d2021-10-14 15:33:41 -0400370
371 // Whether this APEX can be compressed or not. Setting this property to false means this
372 // APEX will never be compressed. When set to true, APEX will be compressed if other
373 // conditions, e.g., target device needs to support APEX compression, are also fulfilled.
374 // Default: false.
375 Compressible *bool
Dennis Shene2ed70c2023-01-11 14:15:43 +0000376
377 // Trim against a specific Dynamic Common Lib APEX
378 Trim_against *string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900379}
380
381type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900382 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383 android.ModuleBase
384 android.DefaultableModuleBase
385 android.OverridableModuleBase
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400386 android.BazelModuleBase
Inseob Kim5eb7ee92022-04-27 10:30:34 +0900387 multitree.ExportableModuleBase
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900388
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900389 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900390 properties apexBundleProperties
391 targetProperties apexTargetBundleProperties
Jiyong Park59140302020-12-14 18:44:04 +0900392 archProperties apexArchBundleProperties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900393 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900394 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900395
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900396 ///////////////////////////////////////////////////////////////////////////////////////////
397 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900398
Nicolas Geoffray036ff9a2023-05-15 10:46:38 +0100399 // Keys for apex_payload.img
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800400 publicKeyFile android.Path
401 privateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900402
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900403 // Cert/priv-key for the zip container
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800404 containerCertificateFile android.Path
405 containerPrivateKeyFile android.Path
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900406
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900407 // Flags for special variants of APEX
408 testApex bool
409 vndkApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900410
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900411 // File system type of apex_payload.img
412 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900413
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900414 // Whether to create symlink to the system file instead of having a file inside the apex or
415 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900416 linkToSystemLib bool
417
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900418 // List of files to be included in this APEX. This is filled in the first part of
419 // GenerateAndroidBuildActions.
420 filesInfo []apexFile
421
Jingwen Chen29743c82023-01-25 17:49:46 +0000422 // List of other module names that should be installed when this APEX gets installed (LOCAL_REQUIRED_MODULES).
423 makeModulesToInstall []string
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900424
425 ///////////////////////////////////////////////////////////////////////////////////////////
426 // Outputs (final and intermediates)
427
428 // Processed apex manifest in JSONson format (for Q)
429 manifestJsonOut android.WritablePath
430
431 // Processed apex manifest in PB format (for R+)
432 manifestPbOut android.WritablePath
433
434 // Processed file_contexts files
435 fileContexts android.WritablePath
436
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900437 // The built APEX file. This is the main product.
Jooyung Hana6d36672022-02-24 13:58:07 +0900438 // Could be .apex or .capex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900439 outputFile android.WritablePath
440
Jooyung Hana6d36672022-02-24 13:58:07 +0900441 // The built uncompressed .apex file.
442 outputApexFile android.WritablePath
443
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900444 // The built APEX file in app bundle format. This file is not directly installed to the
445 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
446 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
447 // system) to be merged into a single app bundle file that Play accepts. See
448 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
449 bundleModuleFile android.WritablePath
450
Colin Cross6340ea52021-11-04 12:01:18 -0700451 // Target directory to install this APEX. Usually out/target/product/<device>/<partition>/apex.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900452 installDir android.InstallPath
453
Colin Cross6340ea52021-11-04 12:01:18 -0700454 // Path where this APEX was installed.
455 installedFile android.InstallPath
456
Jooyung Han286957d2023-10-30 16:17:56 +0900457 // fragment for this apex for apexkeys.txt
458 apexKeysPath android.WritablePath
459
Colin Cross6340ea52021-11-04 12:01:18 -0700460 // Installed locations of symlinks for backward compatibility.
461 compatSymlinks android.InstallPaths
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900462
463 // Text file having the list of individual files that are included in this APEX. Used for
464 // debugging purpose.
465 installedFilesFile android.WritablePath
466
467 // List of module names that this APEX is including (to be shown via *-deps-info target).
468 // Used for debugging purpose.
469 android.ApexBundleDepsInfo
470
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900471 // Optional list of lint report zip files for apexes that contain java or app modules
472 lintReports android.Paths
473
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000474 isCompressed bool
475
sophiezc80a2b32020-11-12 16:39:19 +0000476 // Path of API coverage generate file
sophiez02347372021-11-02 17:58:02 -0700477 nativeApisUsedByModuleFile android.ModuleOutPath
478 nativeApisBackedByModuleFile android.ModuleOutPath
479 javaApisUsedByModuleFile android.ModuleOutPath
braleeb0c1f0c2021-06-07 22:49:13 +0800480
481 // Collect the module directory for IDE info in java/jdeps.go.
482 modulePaths []string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900483}
484
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900485// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900486type apexFileClass int
487
Jooyung Han72bd2f82019-10-23 16:46:38 +0900488const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900489 app apexFileClass = iota
490 appSet
491 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900492 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900493 nativeExecutable
494 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900495 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900496 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900497)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900498
Jingwen Chen2d37b642023-03-14 16:11:38 +0000499var (
500 classes = map[string]apexFileClass{
501 "app": app,
502 "appSet": appSet,
503 "etc": etc,
Jingwen Chen2d37b642023-03-14 16:11:38 +0000504 "javaSharedLib": javaSharedLib,
505 "nativeExecutable": nativeExecutable,
506 "nativeSharedLib": nativeSharedLib,
507 "nativeTest": nativeTest,
Jingwen Chen2d37b642023-03-14 16:11:38 +0000508 "shBinary": shBinary,
509 }
510)
511
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900512// apexFile represents a file in an APEX bundle. This is created during the first half of
513// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
514// of the function, this is used to create commands that copies the files into a staging directory,
Jooyung Haneec1b3f2023-06-20 16:25:59 +0900515// where they are packaged into the APEX file.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900516type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900517 // buildFile is put in the installDir inside the APEX.
Bob Badourde6a0872022-04-01 18:00:00 +0000518 builtFile android.Path
519 installDir string
Jiyong Parkce243632023-02-17 18:22:25 +0900520 partition string
Bob Badourde6a0872022-04-01 18:00:00 +0000521 customStem string
522 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900524 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
525 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
526 // suffix>]
527 androidMkModuleName string // becomes LOCAL_MODULE
528 class apexFileClass // becomes LOCAL_MODULE_CLASS
529 moduleDir string // becomes LOCAL_PATH
530 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
531 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
532 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
533 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900534
535 jacocoReportClassesFile android.Path // only for javalibs and apps
536 lintDepSets java.LintDepSets // only for javalibs and apps
537 certificate java.Certificate // only for apps
538 overriddenPackageName string // only for apps
539
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900540 transitiveDep bool
541 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900542
Jiyong Park57621b22021-01-20 20:33:11 +0900543 multilib string
544
Jingwen Chen2d37b642023-03-14 16:11:38 +0000545 isBazelPrebuilt bool
546 unstrippedBuiltFile android.Path
547 arch string
548
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900549 // TODO(jiyong): remove this
550 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900551}
552
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900553// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900554func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
555 ret := apexFile{
556 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900557 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900558 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900559 class: class,
560 module: module,
561 }
562 if module != nil {
563 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Parkce243632023-02-17 18:22:25 +0900564 ret.partition = module.PartitionTag(ctx.DeviceConfig())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900565 ret.requiredModuleNames = module.RequiredModuleNames()
566 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
567 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park57621b22021-01-20 20:33:11 +0900568 ret.multilib = module.Target().Arch.ArchType.Multilib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900569 }
570 return ret
571}
572
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900573func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900574 return af.builtFile != nil && af.builtFile.String() != ""
575}
576
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900577// apexRelativePath returns the relative path of the given path from the install directory of this
578// apexFile.
579// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900580func (af *apexFile) apexRelativePath(path string) string {
581 return filepath.Join(af.installDir, path)
582}
583
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900584// path returns path of this apex file relative to the APEX root
585func (af *apexFile) path() string {
586 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900587}
588
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900589// stem returns the base filename of this apex file
590func (af *apexFile) stem() string {
591 if af.customStem != "" {
592 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900593 }
594 return af.builtFile.Base()
595}
596
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900597// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
598func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900599 var ret []string
600 for _, symlink := range af.symlinks {
601 ret = append(ret, af.apexRelativePath(symlink))
602 }
603 return ret
604}
605
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900606// availableToPlatform tests whether this apexFile is from a module that can be installed to the
607// platform.
608func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900609 if af.module == nil {
610 return false
611 }
612 if am, ok := af.module.(android.ApexModule); ok {
613 return am.AvailableFor(android.AvailableToPlatform)
614 }
615 return false
616}
617
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900618////////////////////////////////////////////////////////////////////////////////////////////////////
619// Mutators
620//
621// Brief description about mutators for APEX. The following three mutators are the most important
622// ones.
623//
624// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
625// to the (direct) dependencies of this APEX bundle.
626//
Paul Duffin949abc02020-12-08 10:34:30 +0000627// 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900628// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
629// modules are marked as being included in the APEX via BuildForApex().
630//
Paul Duffin949abc02020-12-08 10:34:30 +0000631// 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that
632// are marked by the apexInfoMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900633
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900634type dependencyTag struct {
635 blueprint.BaseDependencyTag
636 name string
637
638 // Determines if the dependent will be part of the APEX payload. Can be false for the
639 // dependencies to the signing key module, etc.
640 payload bool
Paul Duffin8c535da2021-03-17 14:51:03 +0000641
642 // True if the dependent can only be a source module, false if a prebuilt module is a suitable
643 // replacement. This is needed because some prebuilt modules do not provide all the information
644 // needed by the apex.
645 sourceOnly bool
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000646
647 // If not-nil and an APEX is a member of an SDK then dependencies of that APEX with this tag will
648 // also be added as exported members of that SDK.
649 memberType android.SdkMemberType
650}
651
652func (d *dependencyTag) SdkMemberType(_ android.Module) android.SdkMemberType {
653 return d.memberType
654}
655
656func (d *dependencyTag) ExportMember() bool {
657 return true
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900658}
659
Paul Duffin520917a2022-05-13 13:01:59 +0000660func (d *dependencyTag) String() string {
661 return fmt.Sprintf("apex.dependencyTag{%q}", d.name)
662}
663
664func (d *dependencyTag) ReplaceSourceWithPrebuilt() bool {
Paul Duffin8c535da2021-03-17 14:51:03 +0000665 return !d.sourceOnly
666}
667
668var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{}
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000669var _ android.SdkMemberDependencyTag = &dependencyTag{}
Paul Duffin8c535da2021-03-17 14:51:03 +0000670
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900671var (
Paul Duffin520917a2022-05-13 13:01:59 +0000672 androidAppTag = &dependencyTag{name: "androidApp", payload: true}
673 bpfTag = &dependencyTag{name: "bpf", payload: true}
674 certificateTag = &dependencyTag{name: "certificate"}
Dennis Shene2ed70c2023-01-11 14:15:43 +0000675 dclaTag = &dependencyTag{name: "dcla"}
Paul Duffin520917a2022-05-13 13:01:59 +0000676 executableTag = &dependencyTag{name: "executable", payload: true}
677 fsTag = &dependencyTag{name: "filesystem", payload: true}
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000678 bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true, memberType: java.BootclasspathFragmentSdkMemberType}
679 sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true, memberType: java.SystemServerClasspathFragmentSdkMemberType}
Paul Duffinfcf79852022-07-20 14:18:24 +0000680 compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true, memberType: java.CompatConfigSdkMemberType}
Paul Duffin520917a2022-05-13 13:01:59 +0000681 javaLibTag = &dependencyTag{name: "javaLib", payload: true}
682 jniLibTag = &dependencyTag{name: "jniLib", payload: true}
683 keyTag = &dependencyTag{name: "key"}
684 prebuiltTag = &dependencyTag{name: "prebuilt", payload: true}
685 rroTag = &dependencyTag{name: "rro", payload: true}
686 sharedLibTag = &dependencyTag{name: "sharedLib", payload: true}
687 testForTag = &dependencyTag{name: "test for"}
688 testTag = &dependencyTag{name: "test", payload: true}
689 shBinaryTag = &dependencyTag{name: "shBinary", payload: true}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900690)
691
692// TODO(jiyong): shorten this function signature
693func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900694 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900695 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900696 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900697
Jooyung Han8d4a1f02023-08-23 13:54:08 +0900698 // Append "image" variation
699 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
700 libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
701 rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900702
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900703 // Use *FarVariation* to be able to depend on modules having conflicting variations with
704 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
705 // 'arm' or 'arm64' for native shared libs.
Colin Cross70572ed2022-11-02 13:14:20 -0700706 ctx.AddFarVariationDependencies(binVariations, executableTag,
707 android.RemoveListFromList(nativeModules.Binaries, nativeModules.Exclude_binaries)...)
708 ctx.AddFarVariationDependencies(binVariations, testTag,
709 android.RemoveListFromList(nativeModules.Tests, nativeModules.Exclude_tests)...)
710 ctx.AddFarVariationDependencies(libVariations, jniLibTag,
711 android.RemoveListFromList(nativeModules.Jni_libs, nativeModules.Exclude_jni_libs)...)
712 ctx.AddFarVariationDependencies(libVariations, sharedLibTag,
713 android.RemoveListFromList(nativeModules.Native_shared_libs, nativeModules.Exclude_native_shared_libs)...)
714 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag,
715 android.RemoveListFromList(nativeModules.Rust_dyn_libs, nativeModules.Exclude_rust_dyn_libs)...)
716 ctx.AddFarVariationDependencies(target.Variations(), fsTag,
717 android.RemoveListFromList(nativeModules.Filesystems, nativeModules.Exclude_filesystems)...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900718}
719
720func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jooyung Han8d4a1f02023-08-23 13:54:08 +0900721 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900722}
723
Jooyung Hand045ebc2022-12-06 15:23:57 +0900724// getImageVariationPair returns a pair for the image variation name as its
725// prefix and suffix. The prefix indicates whether it's core/vendor/product and the
726// suffix indicates the vndk version when it's vendor or product.
727// getImageVariation can simply join the result of this function to get the
728// image variation name.
729func (a *apexBundle) getImageVariationPair(deviceConfig android.DeviceConfig) (string, string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900730 if a.vndkApex {
Jooyung Hand045ebc2022-12-06 15:23:57 +0900731 return cc.VendorVariationPrefix, a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900732 }
733
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900734 var prefix string
735 var vndkVersion string
736 if deviceConfig.VndkVersion() != "" {
Steven Moreland2c4000c2021-04-27 02:08:49 +0000737 if a.SocSpecific() || a.DeviceSpecific() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900738 prefix = cc.VendorVariationPrefix
739 vndkVersion = deviceConfig.VndkVersion()
740 } else if a.ProductSpecific() {
741 prefix = cc.ProductVariationPrefix
Justin Yunaf1fde42023-09-27 16:22:10 +0900742 vndkVersion = deviceConfig.PlatformVndkVersion()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900743 }
744 }
745 if vndkVersion == "current" {
746 vndkVersion = deviceConfig.PlatformVndkVersion()
747 }
748 if vndkVersion != "" {
Jooyung Hand045ebc2022-12-06 15:23:57 +0900749 return prefix, vndkVersion
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900750 }
751
Jooyung Hand045ebc2022-12-06 15:23:57 +0900752 return android.CoreVariation, "" // The usual case
753}
754
755// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
756// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
757func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
758 prefix, vndkVersion := a.getImageVariationPair(ctx.DeviceConfig())
759 return prefix + vndkVersion
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900760}
761
762func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900763 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
764 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
765 // each target os/architectures, appropriate dependencies are selected by their
766 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900767 targets := ctx.MultiTargets()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900768 imageVariation := a.getImageVariation(ctx)
769
770 a.combineProperties(ctx)
771
772 has32BitTarget := false
773 for _, target := range targets {
774 if target.Arch.ArchType.Multilib == "lib32" {
775 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000776 }
777 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900778 for i, target := range targets {
Colin Cross70572ed2022-11-02 13:14:20 -0700779 var deps ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000780
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900781 // Add native modules targeting both ABIs. When multilib.* is omitted for
782 // native_shared_libs/jni_libs/tests, it implies multilib.both
Colin Cross70572ed2022-11-02 13:14:20 -0700783 deps.Merge(a.properties.Multilib.Both)
784 deps.Merge(ApexNativeDependencies{
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900785 Native_shared_libs: a.properties.Native_shared_libs,
786 Tests: a.properties.Tests,
787 Jni_libs: a.properties.Jni_libs,
788 Binaries: nil,
789 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900790
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900791 // Add native modules targeting the first ABI When multilib.* is omitted for
792 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900793 isPrimaryAbi := i == 0
794 if isPrimaryAbi {
Colin Cross70572ed2022-11-02 13:14:20 -0700795 deps.Merge(a.properties.Multilib.First)
796 deps.Merge(ApexNativeDependencies{
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900797 Native_shared_libs: nil,
798 Tests: nil,
799 Jni_libs: nil,
800 Binaries: a.properties.Binaries,
801 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900802 }
803
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900804 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900805 switch target.Arch.ArchType.Multilib {
806 case "lib32":
Colin Cross70572ed2022-11-02 13:14:20 -0700807 deps.Merge(a.properties.Multilib.Lib32)
808 deps.Merge(a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900809 case "lib64":
Colin Cross70572ed2022-11-02 13:14:20 -0700810 deps.Merge(a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900811 if !has32BitTarget {
Colin Cross70572ed2022-11-02 13:14:20 -0700812 deps.Merge(a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900813 }
814 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900815
Jiyong Park59140302020-12-14 18:44:04 +0900816 // Add native modules targeting a specific arch variant
817 switch target.Arch.ArchType {
818 case android.Arm:
Colin Cross70572ed2022-11-02 13:14:20 -0700819 deps.Merge(a.archProperties.Arch.Arm.ApexNativeDependencies)
Jiyong Park59140302020-12-14 18:44:04 +0900820 case android.Arm64:
Colin Cross70572ed2022-11-02 13:14:20 -0700821 deps.Merge(a.archProperties.Arch.Arm64.ApexNativeDependencies)
Colin Crossa2aaa2f2022-10-03 12:41:50 -0700822 case android.Riscv64:
Colin Cross70572ed2022-11-02 13:14:20 -0700823 deps.Merge(a.archProperties.Arch.Riscv64.ApexNativeDependencies)
Jiyong Park59140302020-12-14 18:44:04 +0900824 case android.X86:
Colin Cross70572ed2022-11-02 13:14:20 -0700825 deps.Merge(a.archProperties.Arch.X86.ApexNativeDependencies)
Jiyong Park59140302020-12-14 18:44:04 +0900826 case android.X86_64:
Colin Cross70572ed2022-11-02 13:14:20 -0700827 deps.Merge(a.archProperties.Arch.X86_64.ApexNativeDependencies)
Jiyong Park59140302020-12-14 18:44:04 +0900828 default:
829 panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType))
830 }
831
Colin Cross70572ed2022-11-02 13:14:20 -0700832 addDependenciesForNativeModules(ctx, deps, target, imageVariation)
Sundong Ahn80c04892021-11-23 00:57:19 +0000833 ctx.AddFarVariationDependencies([]blueprint.Variation{
834 {Mutator: "os", Variation: target.OsVariation()},
835 {Mutator: "arch", Variation: target.ArchVariation()},
836 }, shBinaryTag, a.properties.Sh_binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900837 }
838
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900839 // Common-arch dependencies come next
840 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
Anton Hansson72e7ffe2023-02-24 11:12:31 +0000841 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.properties.Rros...)
Anton Hanssone7545852023-02-24 11:06:07 +0000842 ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...)
843 ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...)
844 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
Jiyong Park12a719c2021-01-07 15:31:24 +0900845 ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
Paul Duffin0b817782021-03-17 15:02:19 +0000846 ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100847}
848
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900849// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900850func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
851 if a.overridableProperties.Allowed_files != nil {
852 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100853 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900854
855 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
856 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
markchien7c803b82021-08-26 22:10:06 +0800857 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...)
Daniel Norman5a3ce132021-08-26 15:44:43 -0700858 if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 {
859 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
860 // regardless of the TARGET_PREFER_* setting. See b/144532908
861 arches := ctx.DeviceConfig().Arches()
862 if len(arches) != 0 {
863 archForPrebuiltEtc := arches[0]
864 for _, arch := range arches {
865 // Prefer 64-bit arch if there is any
866 if arch.ArchType.Multilib == "lib64" {
867 archForPrebuiltEtc = arch
868 break
869 }
870 }
871 ctx.AddFarVariationDependencies([]blueprint.Variation{
872 {Mutator: "os", Variation: ctx.Os().String()},
873 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
874 }, prebuiltTag, prebuilts...)
875 }
876 }
Jaewoong Jung4cfdf7d2021-04-20 16:21:24 -0700877
878 // Dependencies for signing
879 if String(a.overridableProperties.Key) == "" {
880 ctx.PropertyErrorf("key", "missing")
881 return
882 }
883 ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key))
884
885 cert := android.SrcIsModule(a.getCertString(ctx))
886 if cert != "" {
887 ctx.AddDependency(ctx.Module(), certificateTag, cert)
888 // empty cert is not an error. Cert and private keys will be directly found under
889 // PRODUCT_DEFAULT_DEV_CERTIFICATE
890 }
Andrei Onea115e7e72020-06-05 21:14:03 +0100891}
892
Dennis Shene2ed70c2023-01-11 14:15:43 +0000893func apexDCLADepsMutator(mctx android.BottomUpMutatorContext) {
894 if !mctx.Config().ApexTrimEnabled() {
895 return
896 }
897 if a, ok := mctx.Module().(*apexBundle); ok && a.overridableProperties.Trim_against != nil {
898 commonVariation := mctx.Config().AndroidCommonTarget.Variations()
899 mctx.AddFarVariationDependencies(commonVariation, dclaTag, String(a.overridableProperties.Trim_against))
900 } else if o, ok := mctx.Module().(*OverrideApex); ok {
901 for _, p := range o.GetProperties() {
902 properties, ok := p.(*overridableProperties)
903 if !ok {
904 continue
905 }
906 if properties.Trim_against != nil {
907 commonVariation := mctx.Config().AndroidCommonTarget.Variations()
908 mctx.AddFarVariationDependencies(commonVariation, dclaTag, String(properties.Trim_against))
909 }
910 }
911 }
912}
913
914type DCLAInfo struct {
915 ProvidedLibs []string
916}
917
918var DCLAInfoProvider = blueprint.NewMutatorProvider(DCLAInfo{}, "apex_info")
919
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900920type ApexBundleInfo struct {
921 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100922}
923
Paul Duffin949abc02020-12-08 10:34:30 +0000924var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900925
Paul Duffina7d6a892020-12-07 17:39:59 +0000926var _ ApexInfoMutator = (*apexBundle)(nil)
927
Martin Stjernholmbfffae72021-06-24 14:37:13 +0100928func (a *apexBundle) ApexVariationName() string {
929 return a.properties.ApexVariationName
930}
931
Paul Duffina7d6a892020-12-07 17:39:59 +0000932// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900933// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
934// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
935// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
936// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Paul Duffin949abc02020-12-08 10:34:30 +0000937//
938// For each dependency between an apex and an ApexModule an ApexInfo object describing the apex
939// is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list.
940// The apexMutator uses that list to create module variants for the apexes to which it belongs.
941// The relationship between module variants and apexes is not one-to-one as variants will be
942// shared between compatible apexes.
Paul Duffina7d6a892020-12-07 17:39:59 +0000943func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Jooyung Handf78e212020-07-22 15:54:47 +0900944
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900945 // The VNDK APEX is special. For the APEX, the membership is described in a very different
946 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
947 // libraries are self-identified by their vndk.enabled properties. There is no need to run
948 // this mutator for the APEX as nothing will be collected. So, let's return fast.
949 if a.vndkApex {
950 return
951 }
952
953 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
954 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
955 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
956 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
957 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900958 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
Kiyoung Kim8269cee2023-07-26 12:39:19 +0900959 excludeVndkLibs := useVndk && a.useVndkAsStable(mctx)
Jooyung Hanc5a96762022-02-04 11:54:50 +0900960 if proptools.Bool(a.properties.Use_vndk_as_stable) {
961 if !useVndk {
962 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
963 }
Jooyung Han02873da2023-03-22 17:41:03 +0900964 if a.minSdkVersionValue(mctx) != "" {
965 mctx.PropertyErrorf("use_vndk_as_stable", "not supported when min_sdk_version is set")
966 }
Jooyung Hanc5a96762022-02-04 11:54:50 +0900967 mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) {
968 if c, ok := dep.(*cc.Module); ok && c.IsVndk() {
969 mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name())
970 }
971 })
972 if mctx.Failed() {
973 return
974 }
Jooyung Handf78e212020-07-22 15:54:47 +0900975 }
976
Colin Cross56a83212020-09-15 18:30:11 -0700977 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900978 am, ok := child.(android.ApexModule)
979 if !ok || !am.CanHaveApexVariants() {
980 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900981 }
Paul Duffin573989d2021-03-17 13:25:29 +0000982 depTag := mctx.OtherModuleDependencyTag(child)
983
984 // Check to see if the tag always requires that the child module has an apex variant for every
985 // apex variant of the parent module. If it does not then it is still possible for something
986 // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
987 if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
988 return true
989 }
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000990 if !android.IsDepInSameApex(mctx, parent, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900991 return false
992 }
Jooyung Handf78e212020-07-22 15:54:47 +0900993 if excludeVndkLibs {
994 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
995 return false
996 }
997 }
Kiyoung Kimcbe2ba02023-09-07 16:00:04 +0900998
999 //TODO: b/296491928 Vendor APEX should use libbinder.ndk instead of libbinder once VNDK is fully deprecated.
1000 if useVndk && mctx.Config().IsVndkDeprecated() && child.Name() == "libbinder" {
1001 log.Print("Libbinder is linked from Vendor APEX ", a.Name(), " with module ", parent.Name())
1002 return false
1003 }
1004
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001005 // By default, all the transitive dependencies are collected, unless filtered out
1006 // above.
Colin Cross56a83212020-09-15 18:30:11 -07001007 return true
1008 }
1009
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001010 // Records whether a certain module is included in this apexBundle via direct dependency or
1011 // inndirect dependency.
1012 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -07001013 mctx.WalkDeps(func(child, parent android.Module) bool {
1014 if !continueApexDepsWalk(child, parent) {
1015 return false
1016 }
Jooyung Han698dd9f2020-07-22 15:17:19 +09001017 // If the parent is apexBundle, this child is directly depended.
1018 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001019 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -07001020 contents[depName] = contents[depName].Add(directDep)
1021 return true
1022 })
1023
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001024 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +09001025 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -07001026 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
1027 Contents: apexContents,
1028 })
1029
Jooyung Haned124c32021-01-26 11:43:46 +09001030 minSdkVersion := a.minSdkVersion(mctx)
1031 // When min_sdk_version is not set, the apex is built against FutureApiLevel.
1032 if minSdkVersion.IsNone() {
1033 minSdkVersion = android.FutureApiLevel
1034 }
1035
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001036 // This is the main part of this mutator. Mark the collected dependencies that they need to
1037 // be built for this apexBundle.
Jiyong Park78349b52021-05-12 17:13:56 +09001038
Jooyung Han63dff462023-02-09 00:11:27 +00001039 apexVariationName := mctx.ModuleName() // could be com.android.foo
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001040 a.properties.ApexVariationName = apexVariationName
Spandan Dase8173a82023-04-12 17:14:11 +00001041 testApexes := []string{}
1042 if a.testApex {
1043 testApexes = []string{apexVariationName}
1044 }
Colin Cross56a83212020-09-15 18:30:11 -07001045 apexInfo := android.ApexInfo{
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001046 ApexVariationName: apexVariationName,
Jiyong Park4eab21d2021-04-15 15:17:54 +09001047 MinSdkVersion: minSdkVersion,
Colin Cross56a83212020-09-15 18:30:11 -07001048 Updatable: a.Updatable(),
Jiyong Park1bc84122021-06-22 20:23:05 +09001049 UsePlatformApis: a.UsePlatformApis(),
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001050 InApexVariants: []string{apexVariationName},
1051 InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo
Colin Cross56a83212020-09-15 18:30:11 -07001052 ApexContents: []*android.ApexContents{apexContents},
Spandan Dase8173a82023-04-12 17:14:11 +00001053 TestApexes: testApexes,
Colin Cross56a83212020-09-15 18:30:11 -07001054 }
Colin Cross56a83212020-09-15 18:30:11 -07001055 mctx.WalkDeps(func(child, parent android.Module) bool {
1056 if !continueApexDepsWalk(child, parent) {
1057 return false
1058 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001059 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +09001060 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +09001061 })
Dennis Shene2ed70c2023-01-11 14:15:43 +00001062
1063 if a.dynamic_common_lib_apex() {
1064 mctx.SetProvider(DCLAInfoProvider, DCLAInfo{
1065 ProvidedLibs: a.properties.Native_shared_libs,
1066 })
1067 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068}
1069
Paul Duffina7d6a892020-12-07 17:39:59 +00001070type ApexInfoMutator interface {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001071 // ApexVariationName returns the name of the APEX variation to use in the apex
1072 // mutator etc. It is the same name as ApexInfo.ApexVariationName.
1073 ApexVariationName() string
1074
Paul Duffina7d6a892020-12-07 17:39:59 +00001075 // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are
1076 // depended upon by an apex and which require an apex specific variant.
1077 ApexInfoMutator(android.TopDownMutatorContext)
1078}
1079
1080// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex
1081// specific variant to modules that support the ApexInfoMutator.
Spandan Das42e89502022-05-06 22:12:55 +00001082// It also propagates updatable=true to apps of updatable apexes
Paul Duffina7d6a892020-12-07 17:39:59 +00001083func apexInfoMutator(mctx android.TopDownMutatorContext) {
1084 if !mctx.Module().Enabled() {
1085 return
1086 }
1087
1088 if a, ok := mctx.Module().(ApexInfoMutator); ok {
1089 a.ApexInfoMutator(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +00001090 }
Spandan Das42e89502022-05-06 22:12:55 +00001091 enforceAppUpdatability(mctx)
Paul Duffina7d6a892020-12-07 17:39:59 +00001092}
1093
Spandan Das66773252022-01-15 00:23:18 +00001094// apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module
1095// This check is enforced for updatable modules
1096func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
1097 if !mctx.Module().Enabled() {
1098 return
1099 }
Spandan Das08c911f2022-01-21 22:07:26 +00001100 if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
Spandan Das66773252022-01-15 00:23:18 +00001101 mctx.WalkDeps(func(child, parent android.Module) bool {
Spandan Dasd9c23ab2022-02-10 02:34:13 +00001102 // b/208656169 Do not propagate strict updatability linting to libcore/
1103 // These libs are available on the classpath during compilation
1104 // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep
1105 // Only skip libraries defined in libcore root, not subdirectories
1106 if mctx.OtherModuleDir(child) == "libcore" {
1107 // Do not traverse transitive deps of libcore/ libs
1108 return false
1109 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001110 if android.InList(child.Name(), skipLintJavalibAllowlist) {
1111 return false
1112 }
Spandan Das66773252022-01-15 00:23:18 +00001113 if lintable, ok := child.(java.LintDepSetsIntf); ok {
1114 lintable.SetStrictUpdatabilityLinting(true)
1115 }
1116 // visit transitive deps
1117 return true
1118 })
1119 }
1120}
1121
Spandan Das42e89502022-05-06 22:12:55 +00001122// enforceAppUpdatability propagates updatable=true to apps of updatable apexes
1123func enforceAppUpdatability(mctx android.TopDownMutatorContext) {
1124 if !mctx.Module().Enabled() {
1125 return
1126 }
1127 if apex, ok := mctx.Module().(*apexBundle); ok && apex.Updatable() {
1128 // checking direct deps is sufficient since apex->apk is a direct edge, even when inherited via apex_defaults
1129 mctx.VisitDirectDeps(func(module android.Module) {
1130 // ignore android_test_app
1131 if app, ok := module.(*java.AndroidApp); ok {
1132 app.SetUpdatable(true)
1133 }
1134 })
1135 }
1136}
1137
Spandan Das08c911f2022-01-21 22:07:26 +00001138// TODO: b/215736885 Whittle the denylist
1139// Transitive deps of certain mainline modules baseline NewApi errors
1140// Skip these mainline modules for now
1141var (
1142 skipStrictUpdatabilityLintAllowlist = []string{
1143 "com.android.art",
1144 "com.android.art.debug",
1145 "com.android.conscrypt",
1146 "com.android.media",
1147 // test apexes
1148 "test_com.android.art",
1149 "test_com.android.conscrypt",
1150 "test_com.android.media",
1151 "test_jitzygote_com.android.art",
1152 }
Spandan Das2cf278e2022-03-24 20:19:35 +00001153
1154 // TODO: b/215736885 Remove this list
1155 skipLintJavalibAllowlist = []string{
1156 "conscrypt.module.platform.api.stubs",
1157 "conscrypt.module.public.api.stubs",
1158 "conscrypt.module.public.api.stubs.system",
1159 "conscrypt.module.public.api.stubs.module_lib",
1160 "framework-media.stubs",
1161 "framework-media.stubs.system",
1162 "framework-media.stubs.module_lib",
1163 }
Spandan Das08c911f2022-01-21 22:07:26 +00001164)
1165
1166func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
1167 return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
1168}
1169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001170// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
1171// unique apex variations for this module. See android/apex.go for more about unique apex variant.
1172// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -07001173func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
1174 if !mctx.Module().Enabled() {
1175 return
1176 }
1177 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -07001178 android.UpdateUniqueApexVariationsForDeps(mctx, am)
1179 }
1180}
1181
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001182// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
1183// the apex in order to retrieve its contents later.
1184// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001185func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
1186 if !mctx.Module().Enabled() {
1187 return
1188 }
Colin Cross56a83212020-09-15 18:30:11 -07001189 if am, ok := mctx.Module().(android.ApexModule); ok {
1190 if testFor := am.TestFor(); len(testFor) > 0 {
1191 mctx.AddFarVariationDependencies([]blueprint.Variation{
1192 {Mutator: "os", Variation: am.Target().OsVariation()},
1193 {"arch", "common"},
1194 }, testForTag, testFor...)
1195 }
1196 }
1197}
1198
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001199// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001200func apexTestForMutator(mctx android.BottomUpMutatorContext) {
1201 if !mctx.Module().Enabled() {
1202 return
1203 }
Colin Cross56a83212020-09-15 18:30:11 -07001204 if _, ok := mctx.Module().(android.ApexModule); ok {
1205 var contents []*android.ApexContents
1206 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
1207 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
1208 contents = append(contents, abInfo.Contents)
1209 }
1210 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
1211 ApexContents: contents,
1212 })
Colin Crossaede88c2020-08-11 12:17:01 -07001213 }
1214}
1215
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001216// markPlatformAvailability marks whether or not a module can be available to platform. A module
1217// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
1218// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
1219// be) available to platform
1220// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +09001221func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
Jooyung Han8d4a1f02023-08-23 13:54:08 +09001222 // Recovery is not considered as platform
1223 if mctx.Module().InstallInRecovery() {
Jiyong Park89e850a2020-04-07 16:37:39 +09001224 return
1225 }
1226
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001227 am, ok := mctx.Module().(android.ApexModule)
1228 if !ok {
1229 return
1230 }
Jiyong Park89e850a2020-04-07 16:37:39 +09001231
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001232 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +09001233
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001234 // If any of the dep is not available to platform, this module is also considered as being
1235 // not available to platform even if it has "//apex_available:platform"
1236 mctx.VisitDirectDeps(func(child android.Module) {
Paul Duffin4c3e8e22021-03-18 15:41:29 +00001237 if !android.IsDepInSameApex(mctx, am, child) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001238 // if the dependency crosses apex boundary, don't consider it
1239 return
Jiyong Park89e850a2020-04-07 16:37:39 +09001240 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001241 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
1242 availableToPlatform = false
1243 // TODO(b/154889534) trigger an error when 'am' has
1244 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +09001245 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 })
Jiyong Park89e850a2020-04-07 16:37:39 +09001247
Paul Duffinb5769c12021-05-12 16:16:51 +01001248 // Exception 1: check to see if the module always requires it.
1249 if am.AlwaysRequiresPlatformApexVariant() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001250 availableToPlatform = true
1251 }
1252
1253 // Exception 2: bootstrap bionic libraries are also always available to platform
1254 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
1255 availableToPlatform = true
1256 }
1257
1258 if !availableToPlatform {
1259 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +09001260 }
1261}
1262
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001263// apexMutator visits each module and creates apex variations if the module was marked in the
Paul Duffin949abc02020-12-08 10:34:30 +00001264// previous run of apexInfoMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001265func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001266 if !mctx.Module().Enabled() {
1267 return
1268 }
Colin Cross56a83212020-09-15 18:30:11 -07001269
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001270 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001271 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -07001272 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001273 return
1274 }
1275
1276 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001277 if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
1278 apexBundleName := ai.ApexVariationName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001279 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001280 if strings.HasPrefix(apexBundleName, "com.android.art") {
1281 // Create an alias from the platform variant. This is done to make
1282 // test_for dependencies work for modules that are split by the APEX
1283 // mutator, since test_for dependencies always go to the platform variant.
1284 // This doesn't happen for normal APEXes that are disjunct, so only do
1285 // this for the overlapping ART APEXes.
1286 // TODO(b/183882457): Remove this if the test_for functionality is
1287 // refactored to depend on the proper APEX variants instead of platform.
1288 mctx.CreateAliasVariation("", apexBundleName)
1289 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001290 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1291 apexBundleName := o.GetOverriddenModuleName()
1292 if apexBundleName == "" {
1293 mctx.ModuleErrorf("base property is not set")
1294 return
1295 }
1296 mctx.CreateVariations(apexBundleName)
Martin Stjernholmec009002021-03-27 15:18:31 +00001297 if strings.HasPrefix(apexBundleName, "com.android.art") {
1298 // TODO(b/183882457): See note for CreateAliasVariation above.
1299 mctx.CreateAliasVariation("", apexBundleName)
1300 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001301 }
1302}
Sundong Ahne9b55722019-09-06 17:37:42 +09001303
Paul Duffin6717d882021-06-15 19:09:41 +01001304// apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific
1305// variant.
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001306func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool {
Paul Duffin6717d882021-06-15 19:09:41 +01001307 if a, ok := module.(*apexBundle); ok {
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001308 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
Paul Duffin6717d882021-06-15 19:09:41 +01001309 return !a.vndkApex
1310 }
1311
Martin Stjernholmbfffae72021-06-24 14:37:13 +01001312 return true
Paul Duffin6717d882021-06-15 19:09:41 +01001313}
1314
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001315// See android.UpdateDirectlyInAnyApex
1316// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -07001317func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
1318 if !mctx.Module().Enabled() {
1319 return
1320 }
1321 if am, ok := mctx.Module().(android.ApexModule); ok {
1322 android.UpdateDirectlyInAnyApex(mctx, am)
1323 }
1324}
1325
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001326const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001327 // File extensions of an APEX for different packaging methods
Samiul Islam7c02e262021-09-08 17:48:28 +01001328 imageApexSuffix = ".apex"
1329 imageCapexSuffix = ".capex"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001330
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001331 // variant names each of which is for a packaging method
Jooyung Haneec1b3f2023-06-20 16:25:59 +09001332 imageApexType = "image"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001333
Dan Willemsen47e1a752021-10-16 18:36:13 -07001334 ext4FsType = "ext4"
1335 f2fsFsType = "f2fs"
Huang Jianan13cac632021-08-02 15:02:17 +08001336 erofsFsType = "erofs"
Jiyong Park8e6d52f2020-11-19 14:37:47 +09001337)
1338
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001339var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001340
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001341// Implements android.DepInInSameApex
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07001342func (a *apexBundle) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001343 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001344 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001345 return true
1346}
1347
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001348var _ android.OutputFileProducer = (*apexBundle)(nil)
1349
1350// Implements android.OutputFileProducer
1351func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1352 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001353 case "", android.DefaultDistTag:
1354 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001355 return android.Paths{a.outputFile}, nil
Jooyung Hana6d36672022-02-24 13:58:07 +09001356 case imageApexSuffix:
1357 // uncompressed one
1358 if a.outputApexFile != nil {
1359 return android.Paths{a.outputApexFile}, nil
1360 }
1361 fallthrough
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001362 default:
1363 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1364 }
1365}
1366
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001367var _ multitree.Exportable = (*apexBundle)(nil)
1368
1369func (a *apexBundle) Exportable() bool {
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001370 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 {
Jooyung Han8d4a1f02023-08-23 13:54:08 +09001383 return ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001384}
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
Dennis Shenaf41bc12022-08-03 16:46:43 +00001459// See the dynamic_common_lib_apex property
1460func (a *apexBundle) dynamic_common_lib_apex() bool {
1461 return proptools.BoolDefault(a.properties.Dynamic_common_lib_apex, false)
1462}
1463
Dennis Shene2ed70c2023-01-11 14:15:43 +00001464// See the list of libs to trim
1465func (a *apexBundle) libs_to_trim(ctx android.ModuleContext) []string {
1466 dclaModules := ctx.GetDirectDepsWithTag(dclaTag)
1467 if len(dclaModules) > 1 {
1468 panic(fmt.Errorf("expected exactly at most one dcla dependency, got %d", len(dclaModules)))
1469 }
1470 if len(dclaModules) > 0 {
1471 DCLAInfo := ctx.OtherModuleProvider(dclaModules[0], DCLAInfoProvider).(DCLAInfo)
1472 return DCLAInfo.ProvidedLibs
1473 }
1474 return []string{}
1475}
1476
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001477// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1478// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1479// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001480
Jiyong Parkf97782b2019-02-13 20:28:58 +09001481func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1482 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1483 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1484 }
1485}
1486
Lukacs T. Berki01a648a2022-06-17 08:59:37 +02001487func (a *apexBundle) IsSanitizerEnabled(config android.Config, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001488 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1489 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001490 }
1491
1492 // Then follow the global setting
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07001493 var globalSanitizerNames []string
Jooyung Han8d4a1f02023-08-23 13:54:08 +09001494 arches := config.SanitizeDeviceArch()
1495 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1496 globalSanitizerNames = config.SanitizeDevice()
Jiyong Park388ef3f2019-01-28 19:47:32 +09001497 }
1498 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001499}
1500
Jooyung Han8ce8db92020-05-15 19:05:05 +09001501func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001502 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1503 // Keep only the mechanism here.
Jooyung Han8d4a1f02023-08-23 13:54:08 +09001504 if sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001505 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001506 for _, target := range ctx.MultiTargets() {
1507 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001508 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
Colin Cross4c4c1be2022-02-10 11:41:18 -08001509 Native_shared_libs: []string{"libclang_rt.hwasan"},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001510 Tests: nil,
1511 Jni_libs: nil,
1512 Binaries: nil,
1513 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001514 break
1515 }
1516 }
1517 }
1518}
1519
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001520// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1521// returned apexFile saves information about the Soong module that will be used for creating the
1522// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001523func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001524 // Decide the APEX-local directory by the multilib of the library In the future, we may
1525 // query this to the module.
1526 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001527 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001528 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001529 case "lib32":
1530 dirInApex = "lib"
1531 case "lib64":
1532 dirInApex = "lib64"
1533 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001534 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001535 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001536 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001537 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001538 // Special case for Bionic libs and other libs installed with them. This is to
1539 // prevent those libs from being included in the search path
1540 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1541 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1542 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1543 // will be loaded into the default linker namespace (aka "platform" namespace). If
1544 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1545 // be loaded again into the runtime linker namespace, which will result in double
1546 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001547 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001548 }
Florian Mayer95cd6db2023-03-23 17:48:07 -07001549 // This needs to go after the runtime APEX handling because otherwise we would get
1550 // weird paths like lib64/rel_install_path/bionic rather than
1551 // lib64/bionic/rel_install_path.
1552 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001553
Colin Cross1d487152022-10-03 19:14:46 -07001554 fileToCopy := android.OutputFileForModule(ctx, ccMod, "")
Yo Chiange8128052020-07-23 20:09:18 +08001555 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1556 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001557}
1558
Jiyong Park1833cef2019-12-13 13:28:36 +09001559func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001560 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001561 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001562 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001563 }
Jooyung Han35155c42020-02-06 17:33:20 +09001564 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Colin Cross1d487152022-10-03 19:14:46 -07001565 fileToCopy := android.OutputFileForModule(ctx, cc, "")
Yo Chiange8128052020-07-23 20:09:18 +08001566 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1567 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001568 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001569 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001570 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001571}
1572
Jiyong Park99644e92020-11-17 22:21:02 +09001573func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1574 dirInApex := "bin"
1575 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1576 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1577 }
Jooyung Han4ed512b2023-08-11 16:30:04 +09001578 dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath())
Colin Cross1d487152022-10-03 19:14:46 -07001579 fileToCopy := android.OutputFileForModule(ctx, rustm, "")
Jiyong Park99644e92020-11-17 22:21:02 +09001580 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1581 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1582 return af
1583}
1584
1585func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1586 // Decide the APEX-local directory by the multilib of the library
1587 // In the future, we may query this to the module.
1588 var dirInApex string
1589 switch rustm.Arch().ArchType.Multilib {
1590 case "lib32":
1591 dirInApex = "lib"
1592 case "lib64":
1593 dirInApex = "lib64"
1594 }
1595 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1596 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1597 }
Jooyung Han4ed512b2023-08-11 16:30:04 +09001598 dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath())
Colin Cross1d487152022-10-03 19:14:46 -07001599 fileToCopy := android.OutputFileForModule(ctx, rustm, "")
Jiyong Park99644e92020-11-17 22:21:02 +09001600 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1601 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1602}
1603
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001604func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001605 dirInApex := filepath.Join("bin", sh.SubDir())
Sundong Ahn80c04892021-11-23 00:57:19 +00001606 if sh.Target().NativeBridge == android.NativeBridgeEnabled {
1607 dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath)
1608 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001609 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001610 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001611 af.symlinks = sh.Symlinks()
1612 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001613}
1614
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001615func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001616 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001617 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001618 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001619}
1620
atrost6e126252020-01-27 17:01:16 +00001621func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1622 dirInApex := filepath.Join("etc", config.SubDir())
1623 fileToCopy := config.CompatConfig()
1624 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1625}
1626
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001627// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1628// way.
1629type javaModule interface {
1630 android.Module
1631 BaseModuleName() string
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001632 DexJarBuildPath() java.OptionalDexJarPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001633 JacocoReportClassesFile() android.Path
1634 LintDepSets() java.LintDepSets
1635 Stem() string
1636}
1637
1638var _ javaModule = (*java.Library)(nil)
Bill Peckhama41a6962021-01-11 10:58:54 -08001639var _ javaModule = (*java.Import)(nil)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001640var _ javaModule = (*java.SdkLibrary)(nil)
1641var _ javaModule = (*java.DexImport)(nil)
1642var _ javaModule = (*java.SdkLibraryImport)(nil)
1643
Paul Duffin190fdef2021-04-26 10:33:59 +01001644// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001645func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001646 return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
Paul Duffin190fdef2021-04-26 10:33:59 +01001647}
1648
1649// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
1650func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001651 dirInApex := "javalib"
Paul Duffin190fdef2021-04-26 10:33:59 +01001652 af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001653 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1654 af.lintDepSets = module.LintDepSets()
1655 af.customStem = module.Stem() + ".jar"
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001656 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
1657 for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() {
1658 af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName())
1659 }
1660 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001661 return af
1662}
1663
Jiakai Zhang3317ce72023-02-08 01:19:19 +08001664func apexFileForJavaModuleProfile(ctx android.BaseModuleContext, module javaModule) *apexFile {
1665 if dexpreopter, ok := module.(java.DexpreopterInterface); ok {
Jiakai Zhang81e46812023-02-08 21:56:07 +08001666 if profilePathOnHost := dexpreopter.OutputProfilePathOnHost(); profilePathOnHost != nil {
Jiakai Zhang3317ce72023-02-08 01:19:19 +08001667 dirInApex := "javalib"
1668 af := newApexFile(ctx, profilePathOnHost, module.BaseModuleName()+"-profile", dirInApex, etc, nil)
1669 af.customStem = module.Stem() + ".jar.prof"
1670 return &af
1671 }
1672 }
1673 return nil
1674}
1675
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001676// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1677// the same way.
1678type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001679 android.Module
1680 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001681 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001682 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001683 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001684 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001685 BaseModuleName() string
Colin Cross8355c152021-08-10 19:24:07 -07001686 LintDepSets() java.LintDepSets
Andrei Onea580636b2022-08-17 16:53:46 +00001687 PrivAppAllowlist() android.OptionalPath
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001688}
1689
1690var _ androidApp = (*java.AndroidApp)(nil)
1691var _ androidApp = (*java.AndroidAppImport)(nil)
1692
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +00001693func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string {
1694 buildId := ctx.Config().BuildId()
1695
1696 // The build ID is used as a suffix for a filename, so ensure that
1697 // the set of characters being used are sanitized.
1698 // - any word character: [a-zA-Z0-9_]
1699 // - dots: .
1700 // - dashes: -
1701 validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`)
1702 if !validRegex.MatchString(buildId) {
1703 ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId)
1704 }
1705 return buildId
1706}
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001707
Andrei Onea580636b2022-08-17 16:53:46 +00001708func apexFilesForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) []apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001709 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001710 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001711 appDir = "priv-app"
1712 }
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001713
1714 // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed
1715 // so that PackageManager correctly invalidates the existing installed apk
1716 // in favour of the new APK-in-APEX. See bugs for more information.
Oriol Prieto Gasco17e22902022-05-05 13:52:25 +00001717 dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx))
Jiyong Parkf653b052019-11-18 15:39:01 +09001718 fileToCopy := aapp.OutputFile()
Jingwen Chen8ce1efc2022-04-19 13:57:01 +00001719
Yo Chiange8128052020-07-23 20:09:18 +08001720 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001721 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross8355c152021-08-10 19:24:07 -07001722 af.lintDepSets = aapp.LintDepSets()
Colin Cross503c1d02020-01-28 14:00:53 -08001723 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001724
1725 if app, ok := aapp.(interface {
1726 OverriddenManifestPackageName() string
1727 }); ok {
1728 af.overriddenPackageName = app.OverriddenManifestPackageName()
1729 }
Sam Delmericob1daccd2023-05-25 14:45:30 -04001730
1731 apexFiles := []apexFile{}
Andrei Onea580636b2022-08-17 16:53:46 +00001732
1733 if allowlist := aapp.PrivAppAllowlist(); allowlist.Valid() {
1734 dirInApex := filepath.Join("etc", "permissions")
Sam Delmericob1daccd2023-05-25 14:45:30 -04001735 privAppAllowlist := newApexFile(ctx, allowlist.Path(), aapp.BaseModuleName()+"_privapp", dirInApex, etc, aapp)
Andrei Onea580636b2022-08-17 16:53:46 +00001736 apexFiles = append(apexFiles, privAppAllowlist)
1737 }
1738
Sam Delmericob1daccd2023-05-25 14:45:30 -04001739 apexFiles = append(apexFiles, af)
1740
Andrei Onea580636b2022-08-17 16:53:46 +00001741 return apexFiles
Dario Frenicde2a032019-10-27 00:29:22 +01001742}
1743
Jiyong Park69aeba92020-04-24 21:16:36 +09001744func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1745 rroDir := "overlay"
1746 dirInApex := filepath.Join(rroDir, rro.Theme())
1747 fileToCopy := rro.OutputFile()
1748 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1749 af.certificate = rro.Certificate()
1750
1751 if a, ok := rro.(interface {
1752 OverriddenManifestPackageName() string
1753 }); ok {
1754 af.overriddenPackageName = a.OverriddenManifestPackageName()
1755 }
1756 return af
1757}
1758
Ken Chenfad7f9d2021-11-10 22:02:57 +08001759func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile {
1760 dirInApex := filepath.Join("etc", "bpf", apex_sub_dir)
markchien2f59ec92020-09-02 16:23:38 +08001761 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1762}
1763
Jiyong Park12a719c2021-01-07 15:31:24 +09001764func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
1765 dirInApex := filepath.Join("etc", "fs")
1766 return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
1767}
1768
Paul Duffin064b70c2020-11-02 17:32:38 +00001769// WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001770// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1771// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1772// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001773func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001774 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001775 am, ok := child.(android.ApexModule)
1776 if !ok || !am.CanHaveApexVariants() {
1777 return false
1778 }
1779
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001780 // Filter-out unwanted depedendencies
1781 depTag := ctx.OtherModuleDependencyTag(child)
1782 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1783 return false
1784 }
Paul Duffin520917a2022-05-13 13:01:59 +00001785 if dt, ok := depTag.(*dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001786 return false
1787 }
1788
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001789 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
Jiyong Parkab50b072021-05-12 17:13:56 +09001790 externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants)
Jiyong Park0f80c182020-01-31 02:49:53 +09001791
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001792 // Visit actually
1793 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001794 })
1795}
1796
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001797// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1798type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001799
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001800const (
1801 ext4 fsType = iota
1802 f2fs
Huang Jianan13cac632021-08-02 15:02:17 +08001803 erofs
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001804)
Artur Satayev849f8442020-04-28 14:57:42 +01001805
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001806func (f fsType) string() string {
1807 switch f {
1808 case ext4:
1809 return ext4FsType
1810 case f2fs:
1811 return f2fsFsType
Huang Jianan13cac632021-08-02 15:02:17 +08001812 case erofs:
1813 return erofsFsType
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001814 default:
1815 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001816 }
1817}
1818
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001819var _ android.MixedBuildBuildable = (*apexBundle)(nil)
1820
1821func (a *apexBundle) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
Jooyung Han06a8a1c2023-08-23 11:11:43 +09001822 return true
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001823}
1824
1825func (a *apexBundle) QueueBazelCall(ctx android.BaseModuleContext) {
1826 bazelCtx := ctx.Config().BazelContext
1827 bazelCtx.QueueBazelRequest(a.GetBazelLabel(ctx, a), cquery.GetApexInfo, android.GetConfigKey(ctx))
1828}
1829
Jingwen Chen889f2f22022-12-16 08:16:01 +00001830// GetBazelLabel returns the bazel label of this apexBundle, or the label of the
1831// override_apex module overriding this apexBundle. An apexBundle can be
1832// overridden by different override_apex modules (e.g. Google or Go variants),
1833// which is handled by the overrides mutators.
1834func (a *apexBundle) GetBazelLabel(ctx android.BazelConversionPathContext, module blueprint.Module) string {
Jingwen Chen889f2f22022-12-16 08:16:01 +00001835 return a.BazelModuleBase.GetBazelLabel(ctx, a)
1836}
1837
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001838func (a *apexBundle) ProcessBazelQueryResponse(ctx android.ModuleContext) {
1839 if !a.commonBuildActions(ctx) {
1840 return
1841 }
1842
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001843 a.setPayloadFsType(ctx)
1844 a.setSystemLibLink(ctx)
Jooyung Han06a8a1c2023-08-23 11:11:43 +09001845 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001846
1847 bazelCtx := ctx.Config().BazelContext
1848 outputs, err := bazelCtx.GetApexInfo(a.GetBazelLabel(ctx, a), android.GetConfigKey(ctx))
1849 if err != nil {
1850 ctx.ModuleErrorf(err.Error())
1851 return
1852 }
1853 a.installDir = android.PathForModuleInstall(ctx, "apex")
Jingwen Chen94098e82023-01-10 14:50:42 +00001854
1855 // Set the output file to .apex or .capex depending on the compression configuration.
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001856 a.setCompression(ctx)
Jingwen Chen94098e82023-01-10 14:50:42 +00001857 if a.isCompressed {
Cole Faustb0bfa072023-04-03 14:28:36 -07001858 a.outputApexFile = android.PathForBazelOutRelative(ctx, ctx.ModuleDir(), outputs.SignedCompressedOutput)
Jingwen Chen94098e82023-01-10 14:50:42 +00001859 } else {
Cole Faustb0bfa072023-04-03 14:28:36 -07001860 a.outputApexFile = android.PathForBazelOutRelative(ctx, ctx.ModuleDir(), outputs.SignedOutput)
Jingwen Chen94098e82023-01-10 14:50:42 +00001861 }
1862 a.outputFile = a.outputApexFile
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001863
Sam Delmerico4ed95e22023-02-03 18:12:15 -05001864 if len(outputs.TidyFiles) > 0 {
1865 tidyFiles := android.PathsForBazelOut(ctx, outputs.TidyFiles)
1866 a.outputFile = android.AttachValidationActions(ctx, a.outputFile, tidyFiles)
1867 }
1868
Liz Kammer0e255ef2022-11-04 16:07:04 -04001869 // TODO(b/257829940): These are used by the apex_keys_text singleton; would probably be a clearer
1870 // interface if these were set in a provider rather than the module itself
Wei Li32dcdf92022-10-26 22:30:48 -07001871 a.publicKeyFile = android.PathForBazelOut(ctx, outputs.BundleKeyInfo[0])
1872 a.privateKeyFile = android.PathForBazelOut(ctx, outputs.BundleKeyInfo[1])
1873 a.containerCertificateFile = android.PathForBazelOut(ctx, outputs.ContainerKeyInfo[0])
1874 a.containerPrivateKeyFile = android.PathForBazelOut(ctx, outputs.ContainerKeyInfo[1])
Liz Kammer0e255ef2022-11-04 16:07:04 -04001875
Jingwen Chen29743c82023-01-25 17:49:46 +00001876 // Ensure ApexMkInfo.install_to_system make module names are installed as
1877 // part of a bundled build.
1878 a.makeModulesToInstall = append(a.makeModulesToInstall, outputs.MakeModulesToInstall...)
Vinh Tranb6803a52022-12-14 11:34:54 -05001879
Jooyung Han06a8a1c2023-08-23 11:11:43 +09001880 a.bundleModuleFile = android.PathForBazelOut(ctx, outputs.BundleFile)
1881 a.nativeApisUsedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.SymbolsUsedByApex))
1882 a.nativeApisBackedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.BackingLibs))
1883 // TODO(b/239084755): Generate the java api using.xml file from Bazel.
1884 a.javaApisUsedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.JavaSymbolsUsedByApex))
1885 a.installedFilesFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.InstalledFiles))
1886 installSuffix := imageApexSuffix
1887 if a.isCompressed {
1888 installSuffix = imageCapexSuffix
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001889 }
Jooyung Han06a8a1c2023-08-23 11:11:43 +09001890 a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile,
1891 a.compatSymlinks.Paths()...)
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001892
Jingwen Chen2d37b642023-03-14 16:11:38 +00001893 // filesInfo in mixed mode must retrieve all information about the apex's
1894 // contents completely from the Starlark providers. It should never rely on
1895 // Android.bp information, as they might not exist for fully migrated
1896 // dependencies.
Jingwen Chen2d7f6fd2023-02-03 10:31:08 +00001897 //
1898 // Prevent accidental writes to filesInfo in the earlier parts Soong by
1899 // asserting it to be nil.
1900 if a.filesInfo != nil {
Jingwen Chen2d37b642023-03-14 16:11:38 +00001901 panic(
1902 fmt.Errorf("internal error: filesInfo must be nil for an apex handled by Bazel. " +
1903 "Did something else set filesInfo before this line of code?"))
1904 }
1905 for _, f := range outputs.PayloadFilesInfo {
1906 fileInfo := apexFile{
1907 isBazelPrebuilt: true,
1908
1909 builtFile: android.PathForBazelOut(ctx, f["built_file"]),
1910 unstrippedBuiltFile: android.PathForBazelOut(ctx, f["unstripped_built_file"]),
1911 androidMkModuleName: f["make_module_name"],
1912 installDir: f["install_dir"],
1913 class: classes[f["class"]],
1914 customStem: f["basename"],
1915 moduleDir: f["package"],
1916 }
1917
1918 arch := f["arch"]
1919 fileInfo.arch = arch
1920 if len(arch) > 0 {
1921 fileInfo.multilib = "lib32"
1922 if strings.HasSuffix(arch, "64") {
1923 fileInfo.multilib = "lib64"
1924 }
1925 }
1926
1927 a.filesInfo = append(a.filesInfo, fileInfo)
Jingwen Chen2d7f6fd2023-02-03 10:31:08 +00001928 }
Jooyung Han286957d2023-10-30 16:17:56 +09001929 a.apexKeysPath = writeApexKeys(ctx, a)
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001930}
1931
1932func (a *apexBundle) setCompression(ctx android.ModuleContext) {
Jooyung Han06a8a1c2023-08-23 11:11:43 +09001933 if a.testOnlyShouldForceCompression() {
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001934 a.isCompressed = true
1935 } else {
1936 a.isCompressed = ctx.Config().ApexCompressionEnabled() && a.isCompressable()
1937 }
1938}
1939
1940func (a *apexBundle) setSystemLibLink(ctx android.ModuleContext) {
1941 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1942 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1943 // the same library in the system partition, thus effectively sharing the same libraries
1944 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1945 // in the APEX.
1946 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable()
1947
1948 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
1949 // So we can't link them to /system/lib libs which are core variants.
1950 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
1951 a.linkToSystemLib = false
1952 }
1953
1954 forced := ctx.Config().ForceApexSymlinkOptimization()
1955 updatable := a.Updatable() || a.FutureUpdatable()
1956
1957 // We don't need the optimization for updatable APEXes, as it might give false signal
1958 // to the system health when the APEXes are still bundled (b/149805758).
Jooyung Han06a8a1c2023-08-23 11:11:43 +09001959 if !forced && updatable {
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001960 a.linkToSystemLib = false
1961 }
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001962}
1963
1964func (a *apexBundle) setPayloadFsType(ctx android.ModuleContext) {
1965 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
1966 case ext4FsType:
1967 a.payloadFsType = ext4
1968 case f2fsFsType:
1969 a.payloadFsType = f2fs
1970 case erofsFsType:
1971 a.payloadFsType = erofs
1972 default:
1973 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type)
1974 }
1975}
1976
Jooyung Haneec1b3f2023-06-20 16:25:59 +09001977func (a *apexBundle) isCompressable() bool {
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07001978 return proptools.BoolDefault(a.overridableProperties.Compressible, false) && !a.testApex
1979}
1980
1981func (a *apexBundle) commonBuildActions(ctx android.ModuleContext) bool {
1982 a.checkApexAvailability(ctx)
1983 a.checkUpdatable(ctx)
1984 a.CheckMinSdkVersion(ctx)
1985 a.checkStaticLinkingToStubLibraries(ctx)
1986 a.checkStaticExecutables(ctx)
1987 if len(a.properties.Tests) > 0 && !a.testApex {
1988 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1989 return false
1990 }
1991 return true
1992}
1993
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07001994type visitorContext struct {
1995 // all the files that will be included in this APEX
1996 filesInfo []apexFile
1997
1998 // native lib dependencies
1999 provideNativeLibs []string
2000 requireNativeLibs []string
2001
2002 handleSpecialLibs bool
Jooyung Han862c0d62022-12-21 10:15:37 +09002003
2004 // if true, raise error on duplicate apexFile
2005 checkDuplicate bool
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002006}
2007
Jooyung Han862c0d62022-12-21 10:15:37 +09002008func (vctx *visitorContext) normalizeFileInfo(mctx android.ModuleContext) {
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002009 encountered := make(map[string]apexFile)
2010 for _, f := range vctx.filesInfo {
2011 dest := filepath.Join(f.installDir, f.builtFile.Base())
2012 if e, ok := encountered[dest]; !ok {
2013 encountered[dest] = f
2014 } else {
Jooyung Han862c0d62022-12-21 10:15:37 +09002015 if vctx.checkDuplicate && f.builtFile.String() != e.builtFile.String() {
2016 mctx.ModuleErrorf("apex file %v is provided by two different files %v and %v",
2017 dest, e.builtFile, f.builtFile)
2018 return
2019 }
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002020 // If a module is directly included and also transitively depended on
2021 // consider it as directly included.
2022 e.transitiveDep = e.transitiveDep && f.transitiveDep
Jiakai Zhang9c60c172023-09-05 15:19:21 +01002023 // If a module is added as both a JNI library and a regular shared library, consider it as a
2024 // JNI library.
2025 e.isJniLib = e.isJniLib || f.isJniLib
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002026 encountered[dest] = e
2027 }
2028 }
2029 vctx.filesInfo = vctx.filesInfo[:0]
2030 for _, v := range encountered {
2031 vctx.filesInfo = append(vctx.filesInfo, v)
2032 }
2033 sort.Slice(vctx.filesInfo, func(i, j int) bool {
2034 // Sort by destination path so as to ensure consistent ordering even if the source of the files
2035 // changes.
2036 return vctx.filesInfo[i].path() < vctx.filesInfo[j].path()
2037 })
2038}
2039
2040func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, child, parent blueprint.Module) bool {
2041 depTag := ctx.OtherModuleDependencyTag(child)
2042 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2043 return false
2044 }
2045 if mod, ok := child.(android.Module); ok && !mod.Enabled() {
2046 return false
2047 }
2048 depName := ctx.OtherModuleName(child)
2049 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
2050 switch depTag {
2051 case sharedLibTag, jniLibTag:
2052 isJniLib := depTag == jniLibTag
2053 switch ch := child.(type) {
2054 case *cc.Module:
2055 fi := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs)
2056 fi.isJniLib = isJniLib
2057 vctx.filesInfo = append(vctx.filesInfo, fi)
2058 // Collect the list of stub-providing libs except:
2059 // - VNDK libs are only for vendors
2060 // - bootstrap bionic libs are treated as provided by system
2061 if ch.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(ch.BaseModuleName(), ctx.Config()) {
2062 vctx.provideNativeLibs = append(vctx.provideNativeLibs, fi.stem())
2063 }
2064 return true // track transitive dependencies
2065 case *rust.Module:
2066 fi := apexFileForRustLibrary(ctx, ch)
2067 fi.isJniLib = isJniLib
2068 vctx.filesInfo = append(vctx.filesInfo, fi)
2069 return true // track transitive dependencies
2070 default:
2071 propertyName := "native_shared_libs"
2072 if isJniLib {
2073 propertyName = "jni_libs"
2074 }
2075 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
2076 }
2077 case executableTag:
2078 switch ch := child.(type) {
2079 case *cc.Module:
2080 vctx.filesInfo = append(vctx.filesInfo, apexFileForExecutable(ctx, ch))
2081 return true // track transitive dependencies
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002082 case *rust.Module:
2083 vctx.filesInfo = append(vctx.filesInfo, apexFileForRustExecutable(ctx, ch))
2084 return true // track transitive dependencies
2085 default:
2086 ctx.PropertyErrorf("binaries",
2087 "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName)
2088 }
2089 case shBinaryTag:
2090 if csh, ok := child.(*sh.ShBinary); ok {
2091 vctx.filesInfo = append(vctx.filesInfo, apexFileForShBinary(ctx, csh))
2092 } else {
2093 ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName)
2094 }
2095 case bcpfTag:
Jiakai Zhangb47cacc2023-05-10 16:40:18 +01002096 _, ok := child.(*java.BootclasspathFragmentModule)
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002097 if !ok {
2098 ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName)
2099 return false
2100 }
2101
2102 vctx.filesInfo = append(vctx.filesInfo, apexBootclasspathFragmentFiles(ctx, child)...)
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002103 return true
2104 case sscpfTag:
2105 if _, ok := child.(*java.SystemServerClasspathModule); !ok {
2106 ctx.PropertyErrorf("systemserverclasspath_fragments",
2107 "%q is not a systemserverclasspath_fragment module", depName)
2108 return false
2109 }
2110 if af := apexClasspathFragmentProtoFile(ctx, child); af != nil {
2111 vctx.filesInfo = append(vctx.filesInfo, *af)
2112 }
2113 return true
2114 case javaLibTag:
2115 switch child.(type) {
2116 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import:
2117 af := apexFileForJavaModule(ctx, child.(javaModule))
2118 if !af.ok() {
2119 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2120 return false
2121 }
2122 vctx.filesInfo = append(vctx.filesInfo, af)
2123 return true // track transitive dependencies
2124 default:
2125 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
2126 }
2127 case androidAppTag:
2128 switch ap := child.(type) {
2129 case *java.AndroidApp:
Andrei Onea580636b2022-08-17 16:53:46 +00002130 vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...)
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002131 return true // track transitive dependencies
2132 case *java.AndroidAppImport:
Andrei Onea580636b2022-08-17 16:53:46 +00002133 vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...)
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002134 case *java.AndroidTestHelperApp:
Andrei Onea580636b2022-08-17 16:53:46 +00002135 vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...)
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002136 case *java.AndroidAppSet:
2137 appDir := "app"
2138 if ap.Privileged() {
2139 appDir = "priv-app"
2140 }
2141 // TODO(b/224589412, b/226559955): Ensure that the dirname is
2142 // suffixed so that PackageManager correctly invalidates the
2143 // existing installed apk in favour of the new APK-in-APEX.
2144 // See bugs for more information.
2145 appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx))
2146 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap)
2147 af.certificate = java.PresignedCertificate
2148 vctx.filesInfo = append(vctx.filesInfo, af)
2149 default:
2150 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2151 }
2152 case rroTag:
2153 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2154 vctx.filesInfo = append(vctx.filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2155 } else {
2156 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2157 }
2158 case bpfTag:
2159 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2160 filesToCopy, _ := bpfProgram.OutputFiles("")
2161 apex_sub_dir := bpfProgram.SubDir()
2162 for _, bpfFile := range filesToCopy {
2163 vctx.filesInfo = append(vctx.filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
2164 }
2165 } else {
2166 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2167 }
2168 case fsTag:
2169 if fs, ok := child.(filesystem.Filesystem); ok {
2170 vctx.filesInfo = append(vctx.filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
2171 } else {
2172 ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
2173 }
2174 case prebuiltTag:
2175 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
2176 vctx.filesInfo = append(vctx.filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2177 } else {
2178 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
2179 }
2180 case compatConfigTag:
2181 if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok {
2182 vctx.filesInfo = append(vctx.filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName))
2183 } else {
2184 ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName)
2185 }
2186 case testTag:
2187 if ccTest, ok := child.(*cc.Module); ok {
2188 if ccTest.IsTestPerSrcAllTestsVariation() {
2189 // Multiple-output test module (where `test_per_src: true`).
2190 //
2191 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2192 // We do not add this variation to `filesInfo`, as it has no output;
2193 // however, we do add the other variations of this module as indirect
2194 // dependencies (see below).
2195 } else {
2196 // Single-output test module (where `test_per_src: false`).
2197 af := apexFileForExecutable(ctx, ccTest)
2198 af.class = nativeTest
2199 vctx.filesInfo = append(vctx.filesInfo, af)
2200 }
2201 return true // track transitive dependencies
2202 } else {
2203 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2204 }
2205 case keyTag:
2206 if key, ok := child.(*apexKey); ok {
2207 a.privateKeyFile = key.privateKeyFile
2208 a.publicKeyFile = key.publicKeyFile
2209 } else {
2210 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
2211 }
2212 case certificateTag:
2213 if dep, ok := child.(*java.AndroidAppCertificate); ok {
2214 a.containerCertificateFile = dep.Certificate.Pem
2215 a.containerPrivateKeyFile = dep.Certificate.Key
2216 } else {
2217 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2218 }
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002219 }
2220 return false
2221 }
2222
2223 if a.vndkApex {
2224 return false
2225 }
2226
2227 // indirect dependencies
2228 am, ok := child.(android.ApexModule)
2229 if !ok {
2230 return false
2231 }
2232 // We cannot use a switch statement on `depTag` here as the checked
2233 // tags used below are private (e.g. `cc.sharedDepTag`).
2234 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
2235 if ch, ok := child.(*cc.Module); ok {
Kiyoung Kim8269cee2023-07-26 12:39:19 +09002236 if ch.UseVndk() && a.useVndkAsStable(ctx) && ch.IsVndk() {
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002237 vctx.requireNativeLibs = append(vctx.requireNativeLibs, ":vndk")
2238 return false
2239 }
Kiyoung Kimcbe2ba02023-09-07 16:00:04 +09002240
2241 //TODO: b/296491928 Vendor APEX should use libbinder.ndk instead of libbinder once VNDK is fully deprecated.
2242 if ch.UseVndk() && ctx.Config().IsVndkDeprecated() && child.Name() == "libbinder" {
2243 return false
2244 }
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002245 af := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs)
2246 af.transitiveDep = true
2247
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002248 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2249 if !abInfo.Contents.DirectlyInApex(depName) && (ch.IsStubs() || ch.HasStubsVariants()) {
2250 // If the dependency is a stubs lib, don't include it in this APEX,
2251 // but make sure that the lib is installed on the device.
2252 // In case no APEX is having the lib, the lib is installed to the system
2253 // partition.
2254 //
2255 // Always include if we are a host-apex however since those won't have any
2256 // system libraries.
Colin Crossdf2043e2023-01-26 15:39:15 -08002257 //
2258 // Skip the dependency in unbundled builds where the device image is not
2259 // being built.
2260 if ch.IsStubsImplementationRequired() && !am.DirectlyInAnyApex() && !ctx.Config().UnbundledBuild() {
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002261 // we need a module name for Make
2262 name := ch.ImplementationModuleNameForMake(ctx) + ch.Properties.SubName
Jingwen Chen29743c82023-01-25 17:49:46 +00002263 if !android.InList(name, a.makeModulesToInstall) {
2264 a.makeModulesToInstall = append(a.makeModulesToInstall, name)
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002265 }
2266 }
2267 vctx.requireNativeLibs = append(vctx.requireNativeLibs, af.stem())
2268 // Don't track further
2269 return false
2270 }
2271
2272 // If the dep is not considered to be in the same
2273 // apex, don't add it to filesInfo so that it is not
2274 // included in this APEX.
2275 // TODO(jiyong): move this to at the top of the
2276 // else-if clause for the indirect dependencies.
2277 // Currently, that's impossible because we would
2278 // like to record requiredNativeLibs even when
2279 // DepIsInSameAPex is false. We also shouldn't do
2280 // this for host.
2281 //
2282 // TODO(jiyong): explain why the same module is passed in twice.
2283 // Switching the first am to parent breaks lots of tests.
2284 if !android.IsDepInSameApex(ctx, am, am) {
2285 return false
2286 }
2287
2288 vctx.filesInfo = append(vctx.filesInfo, af)
2289 return true // track transitive dependencies
2290 } else if rm, ok := child.(*rust.Module); ok {
2291 af := apexFileForRustLibrary(ctx, rm)
2292 af.transitiveDep = true
2293 vctx.filesInfo = append(vctx.filesInfo, af)
2294 return true // track transitive dependencies
2295 }
2296 } else if cc.IsTestPerSrcDepTag(depTag) {
2297 if ch, ok := child.(*cc.Module); ok {
2298 af := apexFileForExecutable(ctx, ch)
2299 // Handle modules created as `test_per_src` variations of a single test module:
2300 // use the name of the generated test binary (`fileToCopy`) instead of the name
2301 // of the original test module (`depName`, shared by all `test_per_src`
2302 // variations of that module).
2303 af.androidMkModuleName = filepath.Base(af.builtFile.String())
2304 // these are not considered transitive dep
2305 af.transitiveDep = false
2306 vctx.filesInfo = append(vctx.filesInfo, af)
2307 return true // track transitive dependencies
2308 }
2309 } else if cc.IsHeaderDepTag(depTag) {
2310 // nothing
2311 } else if java.IsJniDepTag(depTag) {
2312 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2313 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2314 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
2315 vctx.filesInfo = append(vctx.filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2316 }
2317 } else if rust.IsDylibDepTag(depTag) {
2318 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
2319 af := apexFileForRustLibrary(ctx, rustm)
2320 af.transitiveDep = true
2321 vctx.filesInfo = append(vctx.filesInfo, af)
2322 return true // track transitive dependencies
2323 }
2324 } else if rust.IsRlibDepTag(depTag) {
2325 // Rlib is statically linked, but it might have shared lib
2326 // dependencies. Track them.
2327 return true
2328 } else if java.IsBootclasspathFragmentContentDepTag(depTag) {
2329 // Add the contents of the bootclasspath fragment to the apex.
2330 switch child.(type) {
2331 case *java.Library, *java.SdkLibrary:
2332 javaModule := child.(javaModule)
2333 af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule)
2334 if !af.ok() {
2335 ctx.PropertyErrorf("bootclasspath_fragments",
2336 "bootclasspath_fragment content %q is not configured to be compiled into dex", depName)
2337 return false
2338 }
2339 vctx.filesInfo = append(vctx.filesInfo, af)
2340 return true // track transitive dependencies
2341 default:
2342 ctx.PropertyErrorf("bootclasspath_fragments",
2343 "bootclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2344 }
2345 } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) {
2346 // Add the contents of the systemserverclasspath fragment to the apex.
2347 switch child.(type) {
2348 case *java.Library, *java.SdkLibrary:
2349 af := apexFileForJavaModule(ctx, child.(javaModule))
2350 vctx.filesInfo = append(vctx.filesInfo, af)
Jiakai Zhang3317ce72023-02-08 01:19:19 +08002351 if profileAf := apexFileForJavaModuleProfile(ctx, child.(javaModule)); profileAf != nil {
2352 vctx.filesInfo = append(vctx.filesInfo, *profileAf)
2353 }
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002354 return true // track transitive dependencies
2355 default:
2356 ctx.PropertyErrorf("systemserverclasspath_fragments",
2357 "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child))
2358 }
2359 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2360 // nothing
2361 } else if depTag == android.DarwinUniversalVariantTag {
2362 // nothing
2363 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
2364 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
2365 }
2366 return false
2367}
2368
Jooyung Han862c0d62022-12-21 10:15:37 +09002369func (a *apexBundle) shouldCheckDuplicate(ctx android.ModuleContext) bool {
2370 // TODO(b/263308293) remove this
2371 if a.properties.IsCoverageVariant {
2372 return false
2373 }
2374 // TODO(b/263308515) remove this
2375 if a.testApex {
2376 return false
2377 }
Jooyung Han8d4a1f02023-08-23 13:54:08 +09002378 if ctx.DeviceConfig().DeviceArch() == "" {
Jooyung Han862c0d62022-12-21 10:15:37 +09002379 return false
2380 }
2381 return true
2382}
2383
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002384// Creates build rules for an APEX. It consists of the following major steps:
2385//
2386// 1) do some validity checks such as apex_available, min_sdk_version, etc.
2387// 2) traverse the dependency tree to collect apexFile structs from them.
2388// 3) some fields in apexBundle struct are configured
2389// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002390func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002391 ////////////////////////////////////////////////////////////////////////////////////////////
2392 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07002393 if !a.commonBuildActions(ctx) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002394 return
2395 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002396 ////////////////////////////////////////////////////////////////////////////////////////////
2397 // 2) traverse the dependency tree to collect apexFile structs from them.
braleeb0c1f0c2021-06-07 22:49:13 +08002398 // Collect the module directory for IDE info in java/jdeps.go.
2399 a.modulePaths = append(a.modulePaths, ctx.ModuleDir())
2400
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002401 // TODO(jiyong): do this using WalkPayloadDeps
2402 // TODO(jiyong): make this clean!!!
Jooyung Han862c0d62022-12-21 10:15:37 +09002403 vctx := visitorContext{
2404 handleSpecialLibs: !android.Bool(a.properties.Ignore_system_library_special_case),
2405 checkDuplicate: a.shouldCheckDuplicate(ctx),
2406 }
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002407 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { return a.depVisitor(&vctx, ctx, child, parent) })
Jooyung Han862c0d62022-12-21 10:15:37 +09002408 vctx.normalizeFileInfo(ctx)
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002409 if a.privateKeyFile == nil {
Nicolas Geoffray036ff9a2023-05-15 10:46:38 +01002410 if ctx.Config().AllowMissingDependencies() {
2411 // TODO(b/266099037): a better approach for slim manifests.
2412 ctx.AddMissingDependencies([]string{String(a.overridableProperties.Key)})
2413 // Create placeholder paths for later stages that expect to see those paths,
2414 // though they won't be used.
2415 var unusedPath = android.PathForModuleOut(ctx, "nonexistentprivatekey")
2416 ctx.Build(pctx, android.BuildParams{
2417 Rule: android.ErrorRule,
2418 Output: unusedPath,
2419 Args: map[string]string{
2420 "error": "Private key not available",
2421 },
2422 })
2423 a.privateKeyFile = unusedPath
2424 } else {
2425 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key))
2426 return
2427 }
2428 }
2429
2430 if a.publicKeyFile == nil {
2431 if ctx.Config().AllowMissingDependencies() {
2432 // TODO(b/266099037): a better approach for slim manifests.
2433 ctx.AddMissingDependencies([]string{String(a.overridableProperties.Key)})
2434 // Create placeholder paths for later stages that expect to see those paths,
2435 // though they won't be used.
2436 var unusedPath = android.PathForModuleOut(ctx, "nonexistentpublickey")
2437 ctx.Build(pctx, android.BuildParams{
2438 Rule: android.ErrorRule,
2439 Output: unusedPath,
2440 Args: map[string]string{
2441 "error": "Public key not available",
2442 },
2443 })
2444 a.publicKeyFile = unusedPath
2445 } else {
2446 ctx.PropertyErrorf("key", "public_key for %q could not be found", String(a.overridableProperties.Key))
2447 return
2448 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002449 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002450
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002451 ////////////////////////////////////////////////////////////////////////////////////////////
2452 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09002453 a.installDir = android.PathForModuleInstall(ctx, "apex")
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002454 a.filesInfo = vctx.filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002455
Sasha Smundakfe9a5b82022-07-27 14:51:45 -07002456 a.setPayloadFsType(ctx)
2457 a.setSystemLibLink(ctx)
Jooyung Han06a8a1c2023-08-23 11:11:43 +09002458 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002459
2460 ////////////////////////////////////////////////////////////////////////////////////////////
2461 // 4) generate the build rules to create the APEX. This is done in builder.go.
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002462 a.buildManifest(ctx, vctx.provideNativeLibs, vctx.requireNativeLibs)
Jooyung Haneec1b3f2023-06-20 16:25:59 +09002463 a.buildApex(ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002464 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002465 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002466}
2467
Paul Duffincc33ec82021-04-25 23:14:55 +01002468// apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that
2469// the bootclasspath_fragment contributes to the apex.
2470func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile {
2471 bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2472 var filesToAdd []apexFile
2473
satayev3db35472021-05-06 23:59:58 +01002474 // Add classpaths.proto config.
satayevb98371c2021-06-15 16:49:50 +01002475 if af := apexClasspathFragmentProtoFile(ctx, module); af != nil {
2476 filesToAdd = append(filesToAdd, *af)
2477 }
satayev3db35472021-05-06 23:59:58 +01002478
Ulya Trafimovichf5c548d2022-11-16 14:52:41 +00002479 pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex()
Jiakai Zhangbc698cd2023-05-08 16:28:38 +00002480 if pathInApex != "" {
Jiakai Zhang49b1eb62021-11-26 18:09:27 +00002481 pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
2482 tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
2483
2484 if pathOnHost != nil {
2485 // We need to copy the profile to a temporary path with the right filename because the apexer
2486 // will take the filename as is.
2487 ctx.Build(pctx, android.BuildParams{
2488 Rule: android.Cp,
2489 Input: pathOnHost,
2490 Output: tempPath,
2491 })
2492 } else {
2493 // At this point, the boot image profile cannot be generated. It is probably because the boot
2494 // image profile source file does not exist on the branch, or it is not available for the
2495 // current build target.
2496 // However, we cannot enforce the boot image profile to be generated because some build
2497 // targets (such as module SDK) do not need it. It is only needed when the APEX is being
2498 // built. Therefore, we create an error rule so that an error will occur at the ninja phase
2499 // only if the APEX is being built.
2500 ctx.Build(pctx, android.BuildParams{
2501 Rule: android.ErrorRule,
2502 Output: tempPath,
2503 Args: map[string]string{
2504 "error": "Boot image profile cannot be generated",
2505 },
2506 })
2507 }
2508
2509 androidMkModuleName := filepath.Base(pathInApex)
2510 af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
2511 filesToAdd = append(filesToAdd, af)
2512 }
2513
Paul Duffincc33ec82021-04-25 23:14:55 +01002514 return filesToAdd
2515}
2516
satayevb98371c2021-06-15 16:49:50 +01002517// apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that
2518// the module contributes to the apex; or nil if the proto config was not generated.
2519func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile {
2520 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2521 if !info.ClasspathFragmentProtoGenerated {
2522 return nil
2523 }
2524 classpathProtoOutput := info.ClasspathFragmentProtoOutput
2525 af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil)
2526 return &af
satayev14e49132021-05-17 21:03:07 +01002527}
2528
Paul Duffincc33ec82021-04-25 23:14:55 +01002529// apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment
2530// content module, i.e. a library that is part of the bootclasspath.
Paul Duffin190fdef2021-04-26 10:33:59 +01002531func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile {
2532 bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
2533
2534 // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the
2535 // hidden API encpding.
Paul Duffin1a8010a2021-05-15 12:39:23 +01002536 dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule)
2537 if err != nil {
2538 ctx.ModuleErrorf("%s", err)
2539 }
Paul Duffin190fdef2021-04-26 10:33:59 +01002540
2541 // Create an apexFile as for a normal java module but with the dex boot jar provided by the
2542 // bootclasspath_fragment.
2543 af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar)
2544 return af
Paul Duffincc33ec82021-04-25 23:14:55 +01002545}
2546
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002547///////////////////////////////////////////////////////////////////////////////////////////////////
2548// Factory functions
2549//
2550
2551func newApexBundle() *apexBundle {
2552 module := &apexBundle{}
2553
2554 module.AddProperties(&module.properties)
2555 module.AddProperties(&module.targetProperties)
Jiyong Park59140302020-12-14 18:44:04 +09002556 module.AddProperties(&module.archProperties)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002557 module.AddProperties(&module.overridableProperties)
2558
Jooyung Han8d4a1f02023-08-23 13:54:08 +09002559 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002560 android.InitDefaultableModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002561 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jingwen Chenf59a8e12021-07-16 09:28:53 +00002562 android.InitBazelModule(module)
Inseob Kim5eb7ee92022-04-27 10:30:34 +09002563 multitree.InitExportableModule(module)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002564 return module
2565}
2566
Paul Duffineb8051d2021-10-18 17:49:39 +01002567func ApexBundleFactory(testApex bool) android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002568 bundle := newApexBundle()
2569 bundle.testApex = testApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002570 return bundle
2571}
2572
2573// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2574// certain compatibility checks such as apex_available are not done for apex_test.
Yu Liu4c212ce2022-10-14 12:20:20 -07002575func TestApexBundleFactory() android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002576 bundle := newApexBundle()
2577 bundle.testApex = true
2578 return bundle
2579}
2580
2581// apex packages other modules into an APEX file which is a packaging format for system-level
2582// components like binaries, shared libraries, etc.
2583func BundleFactory() android.Module {
2584 return newApexBundle()
2585}
2586
2587type Defaults struct {
2588 android.ModuleBase
2589 android.DefaultsModuleBase
2590}
2591
2592// apex_defaults provides defaultable properties to other apex modules.
Cole Faust912bc882023-03-08 12:29:50 -08002593func DefaultsFactory() android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002594 module := &Defaults{}
2595
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002596 module.AddProperties(
2597 &apexBundleProperties{},
2598 &apexTargetBundleProperties{},
Nikita Ioffee58f5272022-10-24 17:24:38 +01002599 &apexArchBundleProperties{},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002600 &overridableProperties{},
2601 )
2602
2603 android.InitDefaultsModule(module)
2604 return module
2605}
2606
2607type OverrideApex struct {
2608 android.ModuleBase
2609 android.OverrideModuleBase
Wei Li1c66fc72022-05-09 23:59:14 -07002610 android.BazelModuleBase
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002611}
2612
Sasha Smundak6f9e91d2022-06-28 22:43:04 -07002613func (o *OverrideApex) GenerateAndroidBuildActions(_ android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002614 // All the overrides happen in the base module.
2615}
2616
2617// override_apex is used to create an apex module based on another apex module by overriding some of
2618// its properties.
Wei Li1c66fc72022-05-09 23:59:14 -07002619func OverrideApexFactory() android.Module {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002620 m := &OverrideApex{}
2621
2622 m.AddProperties(&overridableProperties{})
2623
2624 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2625 android.InitOverrideModule(m)
Wei Li1c66fc72022-05-09 23:59:14 -07002626 android.InitBazelModule(m)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002627 return m
2628}
2629
Chris Parsons637458d2023-09-19 20:09:00 +00002630func (o *OverrideApex) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Wei Li1c66fc72022-05-09 23:59:14 -07002631 if ctx.ModuleType() != "override_apex" {
2632 return
2633 }
2634
2635 baseApexModuleName := o.OverrideModuleBase.GetOverriddenModuleName()
2636 baseModule, baseApexExists := ctx.ModuleFromName(baseApexModuleName)
2637 if !baseApexExists {
2638 panic(fmt.Errorf("Base apex module doesn't exist: %s", baseApexModuleName))
2639 }
2640
2641 a, baseModuleIsApex := baseModule.(*apexBundle)
2642 if !baseModuleIsApex {
2643 panic(fmt.Errorf("Base module is not apex module: %s", baseApexModuleName))
2644 }
Liz Kammer1a1c9df2023-03-28 11:39:50 -04002645 attrs, props, commonAttrs := convertWithBp2build(a, ctx)
Wei Li1c66fc72022-05-09 23:59:14 -07002646
Jingwen Chenc4c34e12022-11-29 12:07:45 +00002647 // We just want the name, not module reference.
2648 baseApexName := strings.TrimPrefix(baseApexModuleName, ":")
2649 attrs.Base_apex_name = &baseApexName
2650
Wei Li1c66fc72022-05-09 23:59:14 -07002651 for _, p := range o.GetProperties() {
2652 overridableProperties, ok := p.(*overridableProperties)
2653 if !ok {
2654 continue
2655 }
Wei Li40f98732022-05-20 22:08:11 -07002656
2657 // Manifest is either empty or a file in the directory of base APEX and is not overridable.
2658 // After it is converted in convertWithBp2build(baseApex, ctx),
2659 // the attrs.Manifest.Value.Label is the file path relative to the directory
2660 // of base apex. So the following code converts it to a label that looks like
2661 // <package of base apex>:<path of manifest file> if base apex and override
2662 // apex are not in the same package.
2663 baseApexPackage := ctx.OtherModuleDir(a)
2664 overrideApexPackage := ctx.ModuleDir()
2665 if baseApexPackage != overrideApexPackage {
2666 attrs.Manifest.Value.Label = "//" + baseApexPackage + ":" + attrs.Manifest.Value.Label
2667 }
2668
Wei Li1c66fc72022-05-09 23:59:14 -07002669 // Key
2670 if overridableProperties.Key != nil {
2671 attrs.Key = bazel.LabelAttribute{}
2672 attrs.Key.SetValue(android.BazelLabelForModuleDepSingle(ctx, *overridableProperties.Key))
2673 }
2674
2675 // Certificate
Jingwen Chenbea58092022-09-29 16:56:02 +00002676 if overridableProperties.Certificate == nil {
Jingwen Chen6817bbb2022-10-14 09:56:07 +00002677 // If overridableProperties.Certificate is nil, clear this out as
2678 // well with zeroed structs, so the override_apex does not use the
2679 // base apex's certificate.
2680 attrs.Certificate = bazel.LabelAttribute{}
2681 attrs.Certificate_name = bazel.StringAttribute{}
Jingwen Chenbea58092022-09-29 16:56:02 +00002682 } else {
Jingwen Chen6817bbb2022-10-14 09:56:07 +00002683 attrs.Certificate, attrs.Certificate_name = android.BazelStringOrLabelFromProp(ctx, overridableProperties.Certificate)
Wei Li1c66fc72022-05-09 23:59:14 -07002684 }
2685
2686 // Prebuilts
Jingwen Chendf165c92022-06-08 16:00:39 +00002687 if overridableProperties.Prebuilts != nil {
2688 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, overridableProperties.Prebuilts)
2689 attrs.Prebuilts = bazel.MakeLabelListAttribute(prebuiltsLabelList)
2690 }
Wei Li1c66fc72022-05-09 23:59:14 -07002691
2692 // Compressible
2693 if overridableProperties.Compressible != nil {
2694 attrs.Compressible = bazel.BoolAttribute{Value: overridableProperties.Compressible}
2695 }
Jingwen Chen9b7ebca2022-06-03 09:11:20 +00002696
2697 // Package name
2698 //
2699 // e.g. com.android.adbd's package name is com.android.adbd, but
2700 // com.google.android.adbd overrides the package name to com.google.android.adbd
2701 //
2702 // TODO: this can be overridden from the product configuration, see
2703 // getOverrideManifestPackageName and
2704 // PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES.
2705 //
2706 // Instead of generating the BUILD files differently based on the product config
2707 // at the point of conversion, this should be handled by the BUILD file loading
2708 // from the soong_injection's product_vars, so product config is decoupled from bp2build.
2709 if overridableProperties.Package_name != "" {
2710 attrs.Package_name = &overridableProperties.Package_name
2711 }
Jingwen Chenb732d7c2022-06-10 08:14:19 +00002712
2713 // Logging parent
2714 if overridableProperties.Logging_parent != "" {
2715 attrs.Logging_parent = &overridableProperties.Logging_parent
2716 }
Wei Li1c66fc72022-05-09 23:59:14 -07002717 }
2718
Liz Kammer1a1c9df2023-03-28 11:39:50 -04002719 commonAttrs.Name = o.Name()
2720
2721 ctx.CreateBazelTargetModule(props, commonAttrs, &attrs)
Wei Li1c66fc72022-05-09 23:59:14 -07002722}
2723
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002724///////////////////////////////////////////////////////////////////////////////////////////////////
2725// Vality check routines
2726//
2727// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
2728// certain conditions are not met.
2729//
2730// TODO(jiyong): move these checks to a separate go file.
2731
satayevad991492021-12-03 18:58:32 +00002732var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
2733
Spandan Dasa5f39a12022-08-05 02:35:52 +00002734// Ensures that min_sdk_version of the included modules are equal or less than the min_sdk_version
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002735// of this apexBundle.
satayevb3fd4112021-12-02 13:59:35 +00002736func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002737 if a.testApex || a.vndkApex {
2738 return
2739 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002740 // apexBundle::minSdkVersion reports its own errors.
2741 minSdkVersion := a.minSdkVersion(ctx)
satayevb3fd4112021-12-02 13:59:35 +00002742 android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002743}
2744
Albert Martineefabcf2022-03-21 20:11:16 +00002745// Returns apex's min_sdk_version string value, honoring overrides
2746func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
2747 // Only override the minSdkVersion value on Apexes which already specify
2748 // a min_sdk_version (it's optional for non-updatable apexes), and that its
2749 // min_sdk_version value is lower than the one to override with.
Sam Delmerico0e0d96e2023-08-18 22:43:28 +00002750 minApiLevel := android.MinSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
Colin Cross56534df2022-10-04 09:58:58 -07002751 if minApiLevel.IsNone() {
2752 return ""
Albert Martineefabcf2022-03-21 20:11:16 +00002753 }
2754
Colin Cross56534df2022-10-04 09:58:58 -07002755 overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride()
Sam Delmerico0e0d96e2023-08-18 22:43:28 +00002756 overrideApiLevel := android.MinSdkVersionFromValue(ctx, overrideMinSdkValue)
Colin Cross56534df2022-10-04 09:58:58 -07002757 if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(minApiLevel) > 0 {
2758 minApiLevel = overrideApiLevel
2759 }
2760
2761 return minApiLevel.String()
Albert Martineefabcf2022-03-21 20:11:16 +00002762}
2763
2764// Returns apex's min_sdk_version SdkSpec, honoring overrides
Spandan Das8c9ae7e2023-03-03 21:20:36 +00002765func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
2766 return a.minSdkVersion(ctx)
satayevad991492021-12-03 18:58:32 +00002767}
2768
Albert Martineefabcf2022-03-21 20:11:16 +00002769// Returns apex's min_sdk_version ApiLevel, honoring overrides
satayevad991492021-12-03 18:58:32 +00002770func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Sam Delmerico0e0d96e2023-08-18 22:43:28 +00002771 return android.MinSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx))
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002772}
2773
2774// Ensures that a lib providing stub isn't statically linked
2775func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2776 // Practically, we only care about regular APEXes on the device.
Jooyung Han8d4a1f02023-08-23 13:54:08 +09002777 if a.testApex || a.vndkApex {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002778 return
2779 }
2780
2781 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2782
2783 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2784 if ccm, ok := to.(*cc.Module); ok {
2785 apexName := ctx.ModuleName()
2786 fromName := ctx.OtherModuleName(from)
2787 toName := ctx.OtherModuleName(to)
2788
2789 // If `to` is not actually in the same APEX as `from` then it does not need
2790 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002791 //
2792 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002793 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2794 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2795 return false
2796 }
2797
2798 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2799 // exception to this rule. It can't make the static dependencies dynamic
2800 // because it can't do the dynamic linking for itself.
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09002801 // Same rule should be applied to linkerconfig, because it should be executed
2802 // only with static linked libraries before linker is available with ld.config.txt
2803 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002804 return false
2805 }
2806
2807 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2808 if isStubLibraryFromOtherApex && !externalDep {
2809 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2810 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2811 }
2812
2813 }
2814 return true
2815 })
2816}
2817
satayevb98371c2021-06-15 16:49:50 +01002818// checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002819func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2820 if a.Updatable() {
Albert Martineefabcf2022-03-21 20:11:16 +00002821 if a.minSdkVersionValue(ctx) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002822 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2823 }
Jiyong Park1bc84122021-06-22 20:23:05 +09002824 if a.UsePlatformApis() {
2825 ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs")
2826 }
Jooyung Handfc864c2023-03-20 18:19:07 +09002827 if proptools.Bool(a.properties.Use_vndk_as_stable) {
2828 ctx.PropertyErrorf("use_vndk_as_stable", "updatable APEXes can't use external VNDK libs")
Daniel Norman69109112021-12-02 12:52:42 -08002829 }
Jiyong Parkf4020582021-11-29 12:37:10 +09002830 if a.FutureUpdatable() {
2831 ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`")
2832 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002833 a.checkJavaStableSdkVersion(ctx)
satayevb98371c2021-06-15 16:49:50 +01002834 a.checkClasspathFragments(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002835 }
2836}
2837
satayevb98371c2021-06-15 16:49:50 +01002838// checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config.
2839func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) {
2840 ctx.VisitDirectDeps(func(module android.Module) {
2841 if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag {
2842 info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo)
2843 if !info.ClasspathFragmentProtoGenerated {
2844 ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName())
2845 }
2846 }
2847 })
2848}
2849
2850// checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile.
Artur Satayev8cf899a2020-04-15 17:29:42 +01002851func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002852 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2853 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002854 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2855 tag := ctx.OtherModuleDependencyTag(module)
2856 switch tag {
2857 case javaLibTag, androidAppTag:
Jiyong Parkdbd710c2021-04-02 08:45:46 +09002858 if m, ok := module.(interface {
2859 CheckStableSdkVersion(ctx android.BaseModuleContext) error
2860 }); ok {
2861 if err := m.CheckStableSdkVersion(ctx); err != nil {
Artur Satayev8cf899a2020-04-15 17:29:42 +01002862 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2863 }
2864 }
2865 }
2866 })
2867}
2868
satayevb98371c2021-06-15 16:49:50 +01002869// checkApexAvailability ensures that the all the dependencies are marked as available for this APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002870func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2871 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
Jooyung Han8d4a1f02023-08-23 13:54:08 +09002872 if a.testApex || a.vndkApex {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002873 return
2874 }
2875
2876 // Because APEXes targeting other than system/system_ext partitions can't set
2877 // apex_available, we skip checks for these APEXes
2878 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2879 return
2880 }
2881
2882 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2883 // Requiring them and their transitive depencies with apex_available is not right
2884 // because they just add noise.
2885 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2886 return
2887 }
2888
2889 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2890 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2891 if externalDep {
2892 return false
2893 }
2894
2895 apexName := ctx.ModuleName()
Sam Delmericoca816532023-06-02 14:09:50 -04002896 for _, props := range ctx.Module().GetProperties() {
2897 if apexProps, ok := props.(*apexBundleProperties); ok {
2898 if apexProps.Apex_available_name != nil {
2899 apexName = *apexProps.Apex_available_name
2900 }
2901 }
2902 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002903 fromName := ctx.OtherModuleName(from)
2904 toName := ctx.OtherModuleName(to)
2905
2906 // If `to` is not actually in the same APEX as `from` then it does not need
2907 // apex_available and neither do any of its dependencies.
Paul Duffin4c3e8e22021-03-18 15:41:29 +00002908 //
2909 // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps().
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002910 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2911 // As soon as the dependency graph crosses the APEX boundary, don't go
2912 // further.
2913 return false
2914 }
2915
2916 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2917 return true
2918 }
Jiyong Park767dbd92021-03-04 13:03:10 +09002919 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+
2920 "\n\nDependency path:%s\n\n"+
2921 "Consider adding %q to 'apex_available' property of %q",
2922 fromName, toName, ctx.GetPathString(true), apexName, toName)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002923 // Visit this module's dependencies to check and report any issues with their availability.
2924 return true
2925 })
2926}
2927
Jiyong Park192600a2021-08-03 07:52:17 +00002928// checkStaticExecutable ensures that executables in an APEX are not static.
2929func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
2930 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2931 if ctx.OtherModuleDependencyTag(module) != executableTag {
2932 return
2933 }
Jiyong Parkd12979d2021-08-03 13:36:09 +09002934
2935 if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() {
Jiyong Park192600a2021-08-03 07:52:17 +00002936 apex := a.ApexVariationName()
2937 exec := ctx.OtherModuleName(module)
2938 if isStaticExecutableAllowed(apex, exec) {
2939 return
2940 }
2941 ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
2942 }
2943 })
2944}
2945
2946// A small list of exceptions where static executables are allowed in APEXes.
2947func isStaticExecutableAllowed(apex string, exec string) bool {
2948 m := map[string][]string{
Wei Li40f98732022-05-20 22:08:11 -07002949 "com.android.runtime": {
Jiyong Park192600a2021-08-03 07:52:17 +00002950 "linker",
2951 "linkerconfig",
2952 },
2953 }
2954 execNames, ok := m[apex]
2955 return ok && android.InList(exec, execNames)
2956}
2957
braleeb0c1f0c2021-06-07 22:49:13 +08002958// Collect information for opening IDE project files in java/jdeps.go.
2959func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
Anton Hanssone7545852023-02-24 11:06:07 +00002960 dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
2961 dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
2962 dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...)
braleeb0c1f0c2021-06-07 22:49:13 +08002963 dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...)
2964}
2965
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002966var (
2967 apexAvailBaseline = makeApexAvailableBaseline()
2968 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2969)
2970
Colin Cross440e0d02020-06-11 11:32:11 -07002971func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002972 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002973 moduleName = normalizeModuleName(moduleName)
2974
Colin Cross440e0d02020-06-11 11:32:11 -07002975 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002976 return true
2977 }
2978
2979 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002980 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002981 return true
2982 }
2983
2984 return false
2985}
2986
2987func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002988 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2989 // system. Trim the prefix for the check since they are confusing
Paul Duffind23c7262020-12-11 18:13:08 +00002990 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
Jiyong Park0f80c182020-01-31 02:49:53 +09002991 if strings.HasPrefix(moduleName, "libclang_rt.") {
2992 // This module has many arch variants that depend on the product being built.
2993 // We don't want to list them all
2994 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002995 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002996 if strings.HasPrefix(moduleName, "androidx.") {
2997 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2998 moduleName = "androidx"
2999 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00003000 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003001}
3002
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003003// Transform the map of apex -> modules to module -> apexes.
3004func invertApexBaseline(m map[string][]string) map[string][]string {
3005 r := make(map[string][]string)
3006 for apex, modules := range m {
3007 for _, module := range modules {
3008 r[module] = append(r[module], apex)
3009 }
3010 }
3011 return r
3012}
3013
3014// Retrieve the baseline of apexes to which the supplied module belongs.
3015func BaselineApexAvailable(moduleName string) []string {
3016 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
3017}
3018
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09003019// This is a map from apex to modules, which overrides the apex_available setting for that
3020// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003021// TODO(b/147364041): remove this
3022func makeApexAvailableBaseline() map[string][]string {
3023 // The "Module separator"s below are employed to minimize merge conflicts.
3024 m := make(map[string][]string)
3025 //
3026 // Module separator
3027 //
3028 m["com.android.appsearch"] = []string{
3029 "icing-java-proto-lite",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003030 }
3031 //
3032 // Module separator
3033 //
Oriol Prieto Gasco8132fbf2022-06-17 19:44:25 +00003034 m["com.android.btservices"] = []string{
William Escande89bca3f2022-06-28 18:03:30 -07003035 // empty
Oriol Prieto Gasco8132fbf2022-06-17 19:44:25 +00003036 }
3037 //
3038 // Module separator
3039 //
Spandan Das072f7bc2023-05-05 21:06:23 +00003040 m["com.android.cellbroadcast"] = []string{}
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003041 //
3042 // Module separator
3043 //
3044 m["com.android.extservices"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003045 "ExtServices-core",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003046 "libtextclassifier-java",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003047 "textclassifier-statsd",
3048 "TextClassifierNotificationLibNoManifest",
3049 "TextClassifierServiceLibNoManifest",
3050 }
3051 //
3052 // Module separator
3053 //
3054 m["com.android.neuralnetworks"] = []string{
3055 "android.hardware.neuralnetworks@1.0",
3056 "android.hardware.neuralnetworks@1.1",
3057 "android.hardware.neuralnetworks@1.2",
3058 "android.hardware.neuralnetworks@1.3",
3059 "android.hidl.allocator@1.0",
3060 "android.hidl.memory.token@1.0",
3061 "android.hidl.memory@1.0",
3062 "android.hidl.safe_union@1.0",
3063 "libarect",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003064 "libprocpartition",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003065 }
3066 //
3067 // Module separator
3068 //
3069 m["com.android.media"] = []string{
Ray Essick5d240fb2022-02-07 11:01:32 -08003070 // empty
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003071 }
3072 //
3073 // Module separator
3074 //
3075 m["com.android.media.swcodec"] = []string{
Ray Essickde1e3002022-02-10 17:37:51 -08003076 // empty
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003077 }
3078 //
3079 // Module separator
3080 //
3081 m["com.android.mediaprovider"] = []string{
3082 "MediaProvider",
3083 "MediaProviderGoogle",
3084 "fmtlib_ndk",
3085 "libbase_ndk",
3086 "libfuse",
3087 "libfuse_jni",
3088 }
3089 //
3090 // Module separator
3091 //
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003092 m["com.android.runtime"] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003093 "libdebuggerd",
3094 "libdebuggerd_common_headers",
3095 "libdebuggerd_handler_core",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003096 "libdl_static",
3097 "libjemalloc5",
3098 "liblinker_main",
3099 "liblinker_malloc",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003100 "liblzma",
3101 "libprocinfo",
3102 "libpropertyinfoparser",
3103 "libscudo",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003104 "libsystemproperties",
3105 "libtombstoned_client_static",
3106 "libunwindstack",
3107 "libz",
3108 "libziparchive",
3109 }
3110 //
3111 // Module separator
3112 //
3113 m["com.android.tethering"] = []string{
3114 "android.hardware.tetheroffload.config-V1.0-java",
3115 "android.hardware.tetheroffload.control-V1.0-java",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003116 "net-utils-framework-common",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003117 }
3118 //
3119 // Module separator
3120 //
3121 m["com.android.wifi"] = []string{
3122 "PlatformProperties",
3123 "android.hardware.wifi-V1.0-java",
3124 "android.hardware.wifi-V1.0-java-constants",
3125 "android.hardware.wifi-V1.1-java",
3126 "android.hardware.wifi-V1.2-java",
3127 "android.hardware.wifi-V1.3-java",
3128 "android.hardware.wifi-V1.4-java",
3129 "android.hardware.wifi.hostapd-V1.0-java",
3130 "android.hardware.wifi.hostapd-V1.1-java",
3131 "android.hardware.wifi.hostapd-V1.2-java",
3132 "android.hardware.wifi.supplicant-V1.0-java",
3133 "android.hardware.wifi.supplicant-V1.1-java",
3134 "android.hardware.wifi.supplicant-V1.2-java",
3135 "android.hardware.wifi.supplicant-V1.3-java",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003136 "bouncycastle-unbundled",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003137 "framework-wifi-util-lib",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003138 "ksoap2",
3139 "libnanohttpd",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003140 "wifi-lite-protos",
3141 "wifi-nano-protos",
3142 "wifi-service-pre-jarjar",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003143 }
3144 //
3145 // Module separator
3146 //
3147 m[android.AvailableToAnyApex] = []string{
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003148 "libprofile-clang-extras",
3149 "libprofile-clang-extras_ndk",
3150 "libprofile-extras",
3151 "libprofile-extras_ndk",
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003152 }
3153 return m
3154}
3155
3156func init() {
Spandan Dasf14e2542021-11-12 00:01:37 +00003157 android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...)
3158 android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003159}
3160
Spandan Dasf14e2542021-11-12 00:01:37 +00003161func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule {
3162 rules := make([]android.Rule, 0, len(bcpPermittedPackages))
3163 for jar, permittedPackages := range bcpPermittedPackages {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003164 permittedPackagesRule := android.NeverAllow().
Spandan Dasf14e2542021-11-12 00:01:37 +00003165 With("name", jar).
3166 WithMatcher("permitted_packages", android.NotInList(permittedPackages)).
3167 Because(jar +
3168 " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") +
Anton Hanssone1b18362021-12-23 15:05:38 +00003169 ". Please consider the following alternatives:\n" +
Andrei Onead967aee2022-01-19 15:36:40 +00003170 " 1. If the offending code is from a statically linked library, consider " +
3171 "removing that dependency and using an alternative already in the " +
3172 "bootclasspath, or perhaps a shared library." +
3173 " 2. Move the offending code into an allowed package.\n" +
3174 " 3. Jarjar the offending code. Please be mindful of the potential system " +
3175 "health implications of bundling that code, particularly if the offending jar " +
3176 "is part of the bootclasspath.")
Spandan Dasf14e2542021-11-12 00:01:37 +00003177
Jaewoong Jung18aefc12020-12-21 09:11:10 -08003178 rules = append(rules, permittedPackagesRule)
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003179 }
3180 return rules
3181}
3182
Anton Hanssone1b18362021-12-23 15:05:38 +00003183// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003184// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003185func qBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003186 return map[string][]string{
Wei Li40f98732022-05-20 22:08:11 -07003187 "conscrypt": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003188 "android.net.ssl",
3189 "com.android.org.conscrypt",
3190 },
Wei Li40f98732022-05-20 22:08:11 -07003191 "updatable-media": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003192 "android.media",
3193 },
3194 }
3195}
3196
Anton Hanssone1b18362021-12-23 15:05:38 +00003197// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003198// Adding code to the bootclasspath in new packages will cause issues on module update.
Spandan Dasf14e2542021-11-12 00:01:37 +00003199func rBcpPackages() map[string][]string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003200 return map[string][]string{
Wei Li40f98732022-05-20 22:08:11 -07003201 "framework-mediaprovider": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003202 "android.provider",
3203 },
Wei Li40f98732022-05-20 22:08:11 -07003204 "framework-permission": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003205 "android.permission",
3206 "android.app.role",
3207 "com.android.permission",
3208 "com.android.role",
3209 },
Wei Li40f98732022-05-20 22:08:11 -07003210 "framework-sdkextensions": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003211 "android.os.ext",
3212 },
Wei Li40f98732022-05-20 22:08:11 -07003213 "framework-statsd": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003214 "android.app",
3215 "android.os",
3216 "android.util",
3217 "com.android.internal.statsd",
3218 "com.android.server.stats",
3219 },
Wei Li40f98732022-05-20 22:08:11 -07003220 "framework-wifi": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003221 "com.android.server.wifi",
3222 "com.android.wifi.x",
3223 "android.hardware.wifi",
3224 "android.net.wifi",
3225 },
Wei Li40f98732022-05-20 22:08:11 -07003226 "framework-tethering": {
Jiyong Park8e6d52f2020-11-19 14:37:47 +09003227 "android.net",
3228 },
3229 }
3230}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003231
3232// For Bazel / bp2build
3233
3234type bazelApexBundleAttributes struct {
Yu Liu4ae55d12022-01-05 17:17:23 -08003235 Manifest bazel.LabelAttribute
3236 Android_manifest bazel.LabelAttribute
3237 File_contexts bazel.LabelAttribute
Jingwen Chena8623da2023-03-28 13:05:02 +00003238 Canned_fs_config bazel.LabelAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003239 Key bazel.LabelAttribute
Jingwen Chen6817bbb2022-10-14 09:56:07 +00003240 Certificate bazel.LabelAttribute // used when the certificate prop is a module
3241 Certificate_name bazel.StringAttribute // used when the certificate prop is a string
Liz Kammerb83b7b02022-12-21 14:53:41 -05003242 Min_sdk_version bazel.StringAttribute
Yu Liu4ae55d12022-01-05 17:17:23 -08003243 Updatable bazel.BoolAttribute
3244 Installable bazel.BoolAttribute
3245 Binaries bazel.LabelListAttribute
3246 Prebuilts bazel.LabelListAttribute
3247 Native_shared_libs_32 bazel.LabelListAttribute
3248 Native_shared_libs_64 bazel.LabelListAttribute
Wei Lif034cb42022-01-19 15:54:31 -08003249 Compressible bazel.BoolAttribute
Jingwen Chen9b7ebca2022-06-03 09:11:20 +00003250 Package_name *string
Jingwen Chenb732d7c2022-06-10 08:14:19 +00003251 Logging_parent *string
Yu Liu4c212ce2022-10-14 12:20:20 -07003252 Tests bazel.LabelListAttribute
Jingwen Chenc4c34e12022-11-29 12:07:45 +00003253 Base_apex_name *string
Sam Delmericoe91698a2023-06-06 11:30:31 -04003254 Apex_available_name *string
Sam Delmerico743b4c52023-06-06 12:06:53 -04003255 Variant_version *string
Yu Liu4ae55d12022-01-05 17:17:23 -08003256}
3257
3258type convertedNativeSharedLibs struct {
3259 Native_shared_libs_32 bazel.LabelListAttribute
3260 Native_shared_libs_64 bazel.LabelListAttribute
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003261}
3262
Liz Kammerb83b7b02022-12-21 14:53:41 -05003263const (
3264 minSdkVersionPropName = "Min_sdk_version"
3265)
3266
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003267// ConvertWithBp2build performs bp2build conversion of an apex
Chris Parsons637458d2023-09-19 20:09:00 +00003268func (a *apexBundle) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Yu Liu4c212ce2022-10-14 12:20:20 -07003269 // We only convert apex and apex_test modules at this time
3270 if ctx.ModuleType() != "apex" && ctx.ModuleType() != "apex_test" {
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003271 return
3272 }
3273
Liz Kammer1a1c9df2023-03-28 11:39:50 -04003274 attrs, props, commonAttrs := convertWithBp2build(a, ctx)
3275 commonAttrs.Name = a.Name()
Yu Liu4c212ce2022-10-14 12:20:20 -07003276 ctx.CreateBazelTargetModule(props, commonAttrs, &attrs)
Wei Li1c66fc72022-05-09 23:59:14 -07003277}
3278
Chris Parsons637458d2023-09-19 20:09:00 +00003279func convertWithBp2build(a *apexBundle, ctx android.Bp2buildMutatorContext) (bazelApexBundleAttributes, bazel.BazelTargetModuleProperties, android.CommonAttributes) {
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003280 var manifestLabelAttribute bazel.LabelAttribute
Wei Li40f98732022-05-20 22:08:11 -07003281 manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003282
3283 var androidManifestLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003284 if a.properties.AndroidManifest != nil {
3285 androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003286 }
3287
3288 var fileContextsLabelAttribute bazel.LabelAttribute
Wei Li1c66fc72022-05-09 23:59:14 -07003289 if a.properties.File_contexts == nil {
3290 // See buildFileContexts(), if file_contexts is not specified the default one is used, which is //system/sepolicy/apex:<module name>-file_contexts
3291 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, a.Name()+"-file_contexts"))
3292 } else if strings.HasPrefix(*a.properties.File_contexts, ":") {
3293 // File_contexts is a module
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003294 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
Wei Li1c66fc72022-05-09 23:59:14 -07003295 } else {
3296 // File_contexts is a file
3297 fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.File_contexts))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003298 }
3299
Jingwen Chena8623da2023-03-28 13:05:02 +00003300 var cannedFsConfigAttribute bazel.LabelAttribute
3301 if a.properties.Canned_fs_config != nil {
3302 cannedFsConfigAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Canned_fs_config))
3303 }
3304
Liz Kammer9e2a5a72023-09-19 08:41:14 -04003305 productVariableProps, errs := android.ProductVariableProperties(ctx, a)
3306 for _, err := range errs {
3307 ctx.ModuleErrorf("ProductVariableProperties error: %s", err)
3308 }
Albert Martineefabcf2022-03-21 20:11:16 +00003309 // TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
3310 // given it's coming via config, we probably don't want to put it in here.
Liz Kammerb83b7b02022-12-21 14:53:41 -05003311 var minSdkVersion bazel.StringAttribute
Liz Kammerbd58e742023-05-11 15:58:13 +00003312 if a.properties.Min_sdk_version != nil {
3313 minSdkVersion.SetValue(*a.properties.Min_sdk_version)
Liz Kammerb83b7b02022-12-21 14:53:41 -05003314 }
3315 if props, ok := productVariableProps[minSdkVersionPropName]; ok {
3316 for c, p := range props {
3317 if val, ok := p.(*string); ok {
3318 minSdkVersion.SetSelectValue(c.ConfigurationAxis(), c.SelectKey(), val)
3319 }
3320 }
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003321 }
3322
3323 var keyLabelAttribute bazel.LabelAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003324 if a.overridableProperties.Key != nil {
3325 keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003326 }
3327
Jingwen Chen6817bbb2022-10-14 09:56:07 +00003328 // Certificate
3329 certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableProperties.Certificate)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003330
Yu Liu4ae55d12022-01-05 17:17:23 -08003331 nativeSharedLibs := &convertedNativeSharedLibs{
3332 Native_shared_libs_32: bazel.LabelListAttribute{},
3333 Native_shared_libs_64: bazel.LabelListAttribute{},
3334 }
Vinh Tran8f5310f2022-10-07 18:16:47 -04003335
3336 // https://cs.android.com/android/platform/superproject/+/master:build/soong/android/arch.go;l=698;drc=f05b0d35d2fbe51be9961ce8ce8031f840295c68
3337 // https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=2549;drc=ec731a83e3e2d80a1254e32fd4ad7ef85e262669
3338 // In Soong, decodeMultilib, used to get multilib, return "first" if defaultMultilib is set to "common".
3339 // Since apex sets defaultMultilib to be "common", equivalent compileMultilib in bp2build for apex should be "first"
3340 compileMultilib := "first"
Yu Liu4ae55d12022-01-05 17:17:23 -08003341 if a.CompileMultilib() != nil {
3342 compileMultilib = *a.CompileMultilib()
3343 }
3344
3345 // properties.Native_shared_libs is treated as "both"
3346 convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
3347 convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
3348 convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
3349 convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
3350 convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003351
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003352 prebuilts := a.overridableProperties.Prebuilts
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -04003353 prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
3354 prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
3355
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003356 binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
Jingwen Chenb07c9012021-12-08 10:05:45 +00003357 binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003358
Yu Liu4c212ce2022-10-14 12:20:20 -07003359 var testsAttrs bazel.LabelListAttribute
3360 if a.testApex && len(a.properties.ApexNativeDependencies.Tests) > 0 {
3361 tests := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Tests)
3362 testsAttrs = bazel.MakeLabelListAttribute(tests)
3363 }
3364
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003365 var updatableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003366 if a.properties.Updatable != nil {
3367 updatableAttribute.Value = a.properties.Updatable
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -04003368 }
3369
3370 var installableAttribute bazel.BoolAttribute
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003371 if a.properties.Installable != nil {
3372 installableAttribute.Value = a.properties.Installable
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003373 }
3374
Wei Lif034cb42022-01-19 15:54:31 -08003375 var compressibleAttribute bazel.BoolAttribute
3376 if a.overridableProperties.Compressible != nil {
3377 compressibleAttribute.Value = a.overridableProperties.Compressible
3378 }
3379
Jingwen Chen9b7ebca2022-06-03 09:11:20 +00003380 var packageName *string
3381 if a.overridableProperties.Package_name != "" {
3382 packageName = &a.overridableProperties.Package_name
3383 }
3384
Jingwen Chenb732d7c2022-06-10 08:14:19 +00003385 var loggingParent *string
3386 if a.overridableProperties.Logging_parent != "" {
3387 loggingParent = &a.overridableProperties.Logging_parent
3388 }
3389
Wei Li1c66fc72022-05-09 23:59:14 -07003390 attrs := bazelApexBundleAttributes{
Yu Liu4ae55d12022-01-05 17:17:23 -08003391 Manifest: manifestLabelAttribute,
3392 Android_manifest: androidManifestLabelAttribute,
3393 File_contexts: fileContextsLabelAttribute,
Jingwen Chena8623da2023-03-28 13:05:02 +00003394 Canned_fs_config: cannedFsConfigAttribute,
Yu Liu4ae55d12022-01-05 17:17:23 -08003395 Min_sdk_version: minSdkVersion,
3396 Key: keyLabelAttribute,
Jingwen Chenbea58092022-09-29 16:56:02 +00003397 Certificate: certificate,
3398 Certificate_name: certificateName,
Yu Liu4ae55d12022-01-05 17:17:23 -08003399 Updatable: updatableAttribute,
3400 Installable: installableAttribute,
3401 Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
3402 Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
3403 Binaries: binariesLabelListAttribute,
3404 Prebuilts: prebuiltsLabelListAttribute,
Wei Lif034cb42022-01-19 15:54:31 -08003405 Compressible: compressibleAttribute,
Jingwen Chen9b7ebca2022-06-03 09:11:20 +00003406 Package_name: packageName,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00003407 Logging_parent: loggingParent,
Yu Liu4c212ce2022-10-14 12:20:20 -07003408 Tests: testsAttrs,
Sam Delmericoe91698a2023-06-06 11:30:31 -04003409 Apex_available_name: a.properties.Apex_available_name,
Sam Delmerico743b4c52023-06-06 12:06:53 -04003410 Variant_version: a.properties.Variant_version,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003411 }
3412
3413 props := bazel.BazelTargetModuleProperties{
3414 Rule_class: "apex",
Cole Faust5f90da32022-04-29 13:37:43 -07003415 Bzl_load_location: "//build/bazel/rules/apex:apex.bzl",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003416 }
3417
Liz Kammer1a1c9df2023-03-28 11:39:50 -04003418 commonAttrs := android.CommonAttributes{}
3419 if a.testApex {
3420 commonAttrs.Testonly = proptools.BoolPtr(true)
Spandan Dasa43ae132023-05-08 18:33:16 +00003421 // Set the api_domain of the test apex
3422 attrs.Base_apex_name = proptools.StringPtr(cc.GetApiDomain(a.Name()))
Liz Kammer1a1c9df2023-03-28 11:39:50 -04003423 }
3424
3425 return attrs, props, commonAttrs
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04003426}
Yu Liu4ae55d12022-01-05 17:17:23 -08003427
3428// The following conversions are based on this table where the rows are the compile_multilib
3429// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
3430// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
3431// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
3432// should not be compiled.
3433// multib/compile_multilib, 32, 64, both, first
3434// 32, 32/32, none/none, 32/32, none/32
3435// 64, none/none, 64/none, 64/none, 64/none
3436// both, 32/32, 64/none, 32&64/32, 64/32
3437// first, 32/32, 64/none, 64/32, 64/32
3438
Chris Parsons637458d2023-09-19 20:09:00 +00003439func convert32Libs(ctx android.Bp2buildMutatorContext, compileMultilb string,
Yu Liu4ae55d12022-01-05 17:17:23 -08003440 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3441 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3442 switch compileMultilb {
3443 case "both", "32":
3444 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3445 case "first":
3446 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3447 case "64":
3448 // Incompatible, ignore
3449 default:
3450 invalidCompileMultilib(ctx, compileMultilb)
3451 }
3452}
3453
Chris Parsons637458d2023-09-19 20:09:00 +00003454func convert64Libs(ctx android.Bp2buildMutatorContext, compileMultilb string,
Yu Liu4ae55d12022-01-05 17:17:23 -08003455 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3456 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3457 switch compileMultilb {
3458 case "both", "64", "first":
3459 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3460 case "32":
3461 // Incompatible, ignore
3462 default:
3463 invalidCompileMultilib(ctx, compileMultilb)
3464 }
3465}
3466
Chris Parsons637458d2023-09-19 20:09:00 +00003467func convertBothLibs(ctx android.Bp2buildMutatorContext, compileMultilb string,
Yu Liu4ae55d12022-01-05 17:17:23 -08003468 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3469 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3470 switch compileMultilb {
3471 case "both":
3472 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3473 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3474 case "first":
3475 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3476 case "32":
3477 makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3478 case "64":
3479 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3480 default:
3481 invalidCompileMultilib(ctx, compileMultilb)
3482 }
3483}
3484
Chris Parsons637458d2023-09-19 20:09:00 +00003485func convertFirstLibs(ctx android.Bp2buildMutatorContext, compileMultilb string,
Yu Liu4ae55d12022-01-05 17:17:23 -08003486 libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
3487 libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
3488 switch compileMultilb {
3489 case "both", "first":
3490 makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
3491 case "32":
3492 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3493 case "64":
3494 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3495 default:
3496 invalidCompileMultilib(ctx, compileMultilb)
3497 }
3498}
3499
3500func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3501 make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3502 make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
3503}
3504
3505func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3506 list := bazel.LabelListAttribute{}
3507 list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
3508 nativeSharedLibs.Native_shared_libs_32.Append(list)
3509}
3510
3511func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3512 makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3513 makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
3514}
3515
3516func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
3517 makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3518 makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
3519}
3520
3521func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
3522 labelListAttr *bazel.LabelListAttribute) {
3523 list := bazel.LabelListAttribute{}
3524 list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
3525 labelListAttr.Append(list)
3526}
3527
Chris Parsons637458d2023-09-19 20:09:00 +00003528func invalidCompileMultilib(ctx android.Bp2buildMutatorContext, value string) {
Yu Liu4ae55d12022-01-05 17:17:23 -08003529 ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
3530}
Spandan Dasf57a9662023-04-12 19:05:49 +00003531
3532func (a *apexBundle) IsTestApex() bool {
3533 return a.testApex
3534}
Kiyoung Kim8269cee2023-07-26 12:39:19 +09003535
3536func (a *apexBundle) useVndkAsStable(ctx android.BaseModuleContext) bool {
3537 // VNDK cannot be linked if it is deprecated
3538 if ctx.Config().IsVndkDeprecated() {
3539 return false
3540 }
3541
3542 return proptools.Bool(a.properties.Use_vndk_as_stable)
3543}