blob: a405721e98a31243742db64509e1e941b729938e [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090015// package apex implements build rules for creating the APEX files which are container for
16// lower-level system components. See https://source.android.com/devices/tech/ota/apex
Jiyong Park48ca7dc2018-10-10 14:01:00 +090017package apex
18
19import (
20 "fmt"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
markchien2f59ec92020-09-02 16:23:38 +080030 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070031 "android/soong/cc"
32 prebuilt_etc "android/soong/etc"
33 "android/soong/java"
34 "android/soong/python"
Jiyong Park99644e92020-11-17 22:21:02 +090035 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070036 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090037)
38
Jiyong Park8e6d52f2020-11-19 14:37:47 +090039func init() {
40 android.RegisterModuleType("apex", BundleFactory)
41 android.RegisterModuleType("apex_test", testApexBundleFactory)
42 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
43 android.RegisterModuleType("apex_defaults", defaultsFactory)
44 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
45 android.RegisterModuleType("override_apex", overrideApexFactory)
46 android.RegisterModuleType("apex_set", apexSetFactory)
47
48 android.PreDepsMutators(RegisterPreDepsMutators)
49 android.PostDepsMutators(RegisterPostDepsMutators)
50}
51
52func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
53 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
54 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
55}
56
57func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
58 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
59 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
60 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
61 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
62 ctx.BottomUp("apex", apexMutator).Parallel()
63 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
64 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
65 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
66}
67
68type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090069 // Json manifest file describing meta info of this APEX bundle. Refer to
70 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090071 Manifest *string `android:"path"`
72
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090073 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
74 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090075 AndroidManifest *string `android:"path"`
76
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090077 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
78 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090079 Apex_name *string
80
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090081 // Determines the file contexts file for setting the security contexts to files in this APEX
82 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
83 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090084 File_contexts *string `android:"path"`
85
86 ApexNativeDependencies
87
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090088 Multilib apexMultilibProperties
89
90 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090091 Java_libs []string
92
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090093 // List of prebuilt files that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090094 Prebuilts []string
95
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090096 // List of BPF programs inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090097 Bpfs []string
98
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090099 // Name of the apex_key module that provides the private key to sign this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900100 Key *string
101
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900102 // Specifies the certificate and the private key to sign the zip container of this APEX. If
103 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
104 // as the certificate and the private key, respectively. If this is ":module", then the
105 // certificate and the private key are provided from the android_app_certificate module
106 // named "module".
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900107 Certificate *string
108
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900109 // The minimum SDK version that this APEX must support at minimum. This is usually set to
110 // the SDK version that the APEX was first introduced.
111 Min_sdk_version *string
112
113 // Whether this APEX is considered updatable or not. When set to true, this will enforce
114 // additional rules for making sure that the APEX is truly updatable. To be updatable,
115 // min_sdk_version should be set as well. This will also disable the size optimizations like
116 // symlinking to the system libs. Default is false.
117 Updatable *bool
118
119 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
120 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900121 Installable *bool
122
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900123 // For native libraries and binaries, use the vendor variant instead of the core (platform)
124 // variant. Default is false. DO NOT use this for APEXes that are installed to the system or
125 // system_ext partition.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900126 Use_vendor *bool
127
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900128 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
129 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
130 Use_vndk_as_stable *bool
131
132 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
133 // `name#version` or `name` which is an alias for `name#current`. If left empty,
134 // `platform#current` is implied. This value affects all modules included in this APEX. In
135 // other words, they are also built with the SDKs specified here.
136 Uses_sdks []string
137
138 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
139 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
140 // container. When set to zip, contents are stored in a zip container directly. This type is
141 // mostly for host-side debugging. When set to both, the two types are both built. Default
142 // is 'image'.
143 Payload_type *string
144
145 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4' or 'f2fs'.
146 // Default 'ext4'.
147 Payload_fs_type *string
148
149 // For telling the APEX to ignore special handling for system libraries such as bionic.
150 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900151 Ignore_system_library_special_case *bool
152
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900153 // Whenever apex_payload.img of the APEX should include dm-verity hashtree. Should be only
154 // used in tests.
155 Test_only_no_hashtree *bool
156
157 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
158 // used in tests.
159 Test_only_unsigned_payload *bool
160
161 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900162
163 // List of sanitizer names that this APEX is enabled for
164 SanitizerNames []string `blueprint:"mutated"`
165
166 PreventInstall bool `blueprint:"mutated"`
167
168 HideFromMake bool `blueprint:"mutated"`
169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900170 // Internal package method for this APEX. When payload_type is image, this can be either
171 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
172 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900173 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900174}
175
176type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900177 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900178 Native_shared_libs []string
179
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900180 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900181 Jni_libs []string
182
Jiyong Park99644e92020-11-17 22:21:02 +0900183 // List of rust dyn libraries
184 Rust_dyn_libs []string
185
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900186 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900187 Binaries []string
188
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900189 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900190 Tests []string
191}
192
193type apexMultilibProperties struct {
194 // Native dependencies whose compile_multilib is "first"
195 First ApexNativeDependencies
196
197 // Native dependencies whose compile_multilib is "both"
198 Both ApexNativeDependencies
199
200 // Native dependencies whose compile_multilib is "prefer32"
201 Prefer32 ApexNativeDependencies
202
203 // Native dependencies whose compile_multilib is "32"
204 Lib32 ApexNativeDependencies
205
206 // Native dependencies whose compile_multilib is "64"
207 Lib64 ApexNativeDependencies
208}
209
210type apexTargetBundleProperties struct {
211 Target struct {
212 // Multilib properties only for android.
213 Android struct {
214 Multilib apexMultilibProperties
215 }
216
217 // Multilib properties only for host.
218 Host struct {
219 Multilib apexMultilibProperties
220 }
221
222 // Multilib properties only for host linux_bionic.
223 Linux_bionic struct {
224 Multilib apexMultilibProperties
225 }
226
227 // Multilib properties only for host linux_glibc.
228 Linux_glibc struct {
229 Multilib apexMultilibProperties
230 }
231 }
232}
233
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900234// These properties can be used in override_apex to override the corresponding properties in the
235// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900236type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900237 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900238 Apps []string
239
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900240 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900241 Rros []string
242
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900243 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
244 // Soong). This does not completely prevent installation of the overridden binaries, but if
245 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
246 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900247 Overrides []string
248
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900249 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900250 Logging_parent string
251
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900252 // Apex Container package name. Override value for attribute package:name in
253 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900254 Package_name string
255
256 // A txt file containing list of files that are allowed to be included in this APEX.
257 Allowed_files *string `android:"path"`
258}
259
260type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900261 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900262 android.ModuleBase
263 android.DefaultableModuleBase
264 android.OverridableModuleBase
265 android.SdkBase
266
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900267 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900268 properties apexBundleProperties
269 targetProperties apexTargetBundleProperties
270 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900271 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900272
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900273 ///////////////////////////////////////////////////////////////////////////////////////////
274 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900275
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900276 // Keys for apex_paylaod.img
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900277 public_key_file android.Path
278 private_key_file android.Path
279
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900280 // Cert/priv-key for the zip container
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900281 container_certificate_file android.Path
282 container_private_key_file android.Path
283
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900284 // Flags for special variants of APEX
285 testApex bool
286 vndkApex bool
287 artApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900288
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900289 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
290 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900291 primaryApexType bool
292
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900293 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900294 suffix string
295
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900296 // File system type of apex_payload.img
297 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900298
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900299 // Whether to create symlink to the system file instead of having a file inside the apex or
300 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900301 linkToSystemLib bool
302
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900303 // List of files to be included in this APEX. This is filled in the first part of
304 // GenerateAndroidBuildActions.
305 filesInfo []apexFile
306
307 // List of other module names that should be installed when this APEX gets installed.
308 requiredDeps []string
309
310 ///////////////////////////////////////////////////////////////////////////////////////////
311 // Outputs (final and intermediates)
312
313 // Processed apex manifest in JSONson format (for Q)
314 manifestJsonOut android.WritablePath
315
316 // Processed apex manifest in PB format (for R+)
317 manifestPbOut android.WritablePath
318
319 // Processed file_contexts files
320 fileContexts android.WritablePath
321
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900322 // Struct holding the merged notice file paths in different formats
323 mergedNotices android.NoticeOutputs
324
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900325 // The built APEX file. This is the main product.
326 outputFile android.WritablePath
327
328 // The built APEX file in app bundle format. This file is not directly installed to the
329 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
330 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
331 // system) to be merged into a single app bundle file that Play accepts. See
332 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
333 bundleModuleFile android.WritablePath
334
335 // Target path to install this APEX. Usually out/target/product/<device>/<partition>/apex.
336 installDir android.InstallPath
337
338 // List of commands to create symlinks for backward compatibility. These commands will be
339 // attached as LOCAL_POST_INSTALL_CMD to apex package itself (for unflattened build) or
340 // apex_manifest (for flattened build) so that compat symlinks are always installed
341 // regardless of TARGET_FLATTEN_APEX setting.
342 compatSymlinks []string
343
344 // Text file having the list of individual files that are included in this APEX. Used for
345 // debugging purpose.
346 installedFilesFile android.WritablePath
347
348 // List of module names that this APEX is including (to be shown via *-deps-info target).
349 // Used for debugging purpose.
350 android.ApexBundleDepsInfo
351
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352 // Optional list of lint report zip files for apexes that contain java or app modules
353 lintReports android.Paths
354
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900355 prebuiltFileToDelete string
sophiezc80a2b32020-11-12 16:39:19 +0000356
357 // Path of API coverage generate file
sophiez6bde0b52021-01-09 01:03:42 +0000358 apisUsedByModuleFile android.ModuleOutPath
359 apisBackedByModuleFile android.ModuleOutPath
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900360}
361
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900362// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363type apexFileClass int
364
Jooyung Han72bd2f82019-10-23 16:46:38 +0900365const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900366 app apexFileClass = iota
367 appSet
368 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900369 goBinary
370 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900371 nativeExecutable
372 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900373 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900374 pyBinary
375 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900376)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900377
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900378// apexFile represents a file in an APEX bundle. This is created during the first half of
379// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
380// of the function, this is used to create commands that copies the files into a staging directory,
381// where they are packaged into the APEX file. This struct is also used for creating Make modules
382// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900383type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900384 // buildFile is put in the installDir inside the APEX.
385 builtFile android.Path
386 noticeFiles android.Paths
387 installDir string
388 customStem string
389 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900390
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900391 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
392 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
393 // suffix>]
394 androidMkModuleName string // becomes LOCAL_MODULE
395 class apexFileClass // becomes LOCAL_MODULE_CLASS
396 moduleDir string // becomes LOCAL_PATH
397 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
398 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
399 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
400 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900401
402 jacocoReportClassesFile android.Path // only for javalibs and apps
403 lintDepSets java.LintDepSets // only for javalibs and apps
404 certificate java.Certificate // only for apps
405 overriddenPackageName string // only for apps
406
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900407 transitiveDep bool
408 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900409
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900410 // TODO(jiyong): remove this
411 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900412}
413
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900414// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900415func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
416 ret := apexFile{
417 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900418 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900419 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900420 class: class,
421 module: module,
422 }
423 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900424 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900425 ret.moduleDir = ctx.OtherModuleDir(module)
426 ret.requiredModuleNames = module.RequiredModuleNames()
427 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
428 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900429 }
430 return ret
431}
432
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900433func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900434 return af.builtFile != nil && af.builtFile.String() != ""
435}
436
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900437// apexRelativePath returns the relative path of the given path from the install directory of this
438// apexFile.
439// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900440func (af *apexFile) apexRelativePath(path string) string {
441 return filepath.Join(af.installDir, path)
442}
443
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900444// path returns path of this apex file relative to the APEX root
445func (af *apexFile) path() string {
446 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900447}
448
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900449// stem returns the base filename of this apex file
450func (af *apexFile) stem() string {
451 if af.customStem != "" {
452 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900453 }
454 return af.builtFile.Base()
455}
456
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900457// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
458func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900459 var ret []string
460 for _, symlink := range af.symlinks {
461 ret = append(ret, af.apexRelativePath(symlink))
462 }
463 return ret
464}
465
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900466// availableToPlatform tests whether this apexFile is from a module that can be installed to the
467// platform.
468func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900469 if af.module == nil {
470 return false
471 }
472 if am, ok := af.module.(android.ApexModule); ok {
473 return am.AvailableFor(android.AvailableToPlatform)
474 }
475 return false
476}
477
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900478////////////////////////////////////////////////////////////////////////////////////////////////////
479// Mutators
480//
481// Brief description about mutators for APEX. The following three mutators are the most important
482// ones.
483//
484// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
485// to the (direct) dependencies of this APEX bundle.
486//
487// 2) apexDepsMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
488// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
489// modules are marked as being included in the APEX via BuildForApex().
490//
491// 3) apexMutator: this is a post-deps mutator that runs after apexDepsMutator. For each module that
492// are marked by the apexDepsMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900493
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900494type dependencyTag struct {
495 blueprint.BaseDependencyTag
496 name string
497
498 // Determines if the dependent will be part of the APEX payload. Can be false for the
499 // dependencies to the signing key module, etc.
500 payload bool
501}
502
503var (
504 androidAppTag = dependencyTag{name: "androidApp", payload: true}
505 bpfTag = dependencyTag{name: "bpf", payload: true}
506 certificateTag = dependencyTag{name: "certificate"}
507 executableTag = dependencyTag{name: "executable", payload: true}
508 javaLibTag = dependencyTag{name: "javaLib", payload: true}
509 jniLibTag = dependencyTag{name: "jniLib", payload: true}
510 keyTag = dependencyTag{name: "key"}
511 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
512 rroTag = dependencyTag{name: "rro", payload: true}
513 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
514 testForTag = dependencyTag{name: "test for"}
515 testTag = dependencyTag{name: "test", payload: true}
516)
517
518// TODO(jiyong): shorten this function signature
519func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900520 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900521 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900522 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523
524 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900525 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900526 libVariations = append(libVariations,
527 blueprint.Variation{Mutator: "image", Variation: imageVariation},
Jiyong Park99644e92020-11-17 22:21:02 +0900528 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
529 rustLibVariations = append(rustLibVariations,
530 blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900531 }
532
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900533 // Use *FarVariation* to be able to depend on modules having conflicting variations with
534 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
535 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900536 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900537 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900538 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
539 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900540 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900541}
542
543func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900544 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900545 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
546 } else {
547 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
548 if ctx.Os().Bionic() {
549 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
550 } else {
551 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
552 }
553 }
554}
555
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900556// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
557// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
558func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
559 deviceConfig := ctx.DeviceConfig()
560 if a.vndkApex {
561 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900562 }
563
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900564 var prefix string
565 var vndkVersion string
566 if deviceConfig.VndkVersion() != "" {
567 if proptools.Bool(a.properties.Use_vendor) {
568 prefix = cc.VendorVariationPrefix
569 vndkVersion = deviceConfig.PlatformVndkVersion()
570 } else if a.SocSpecific() || a.DeviceSpecific() {
571 prefix = cc.VendorVariationPrefix
572 vndkVersion = deviceConfig.VndkVersion()
573 } else if a.ProductSpecific() {
574 prefix = cc.ProductVariationPrefix
575 vndkVersion = deviceConfig.ProductVndkVersion()
576 }
577 }
578 if vndkVersion == "current" {
579 vndkVersion = deviceConfig.PlatformVndkVersion()
580 }
581 if vndkVersion != "" {
582 return prefix + vndkVersion
583 }
584
585 return android.CoreVariation // The usual case
586}
587
588func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
589 // TODO(jiyong): move this kind of checks to GenerateAndroidBuildActions?
590 checkUseVendorProperty(ctx, a)
591
592 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
593 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
594 // each target os/architectures, appropriate dependencies are selected by their
595 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900596 targets := ctx.MultiTargets()
597 config := ctx.DeviceConfig()
598 imageVariation := a.getImageVariation(ctx)
599
600 a.combineProperties(ctx)
601
602 has32BitTarget := false
603 for _, target := range targets {
604 if target.Arch.ArchType.Multilib == "lib32" {
605 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000606 }
607 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900608 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900609 // Don't include artifacts for the host cross targets because there is no way for us
610 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900611 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900612 continue
613 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000614
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900615 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000616
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900617 // Add native modules targeting both ABIs. When multilib.* is omitted for
618 // native_shared_libs/jni_libs/tests, it implies multilib.both
619 depsList = append(depsList, a.properties.Multilib.Both)
620 depsList = append(depsList, ApexNativeDependencies{
621 Native_shared_libs: a.properties.Native_shared_libs,
622 Tests: a.properties.Tests,
623 Jni_libs: a.properties.Jni_libs,
624 Binaries: nil,
625 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900626
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900627 // Add native modules targeting the first ABI When multilib.* is omitted for
628 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900629 isPrimaryAbi := i == 0
630 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900631 depsList = append(depsList, a.properties.Multilib.First)
632 depsList = append(depsList, ApexNativeDependencies{
633 Native_shared_libs: nil,
634 Tests: nil,
635 Jni_libs: nil,
636 Binaries: a.properties.Binaries,
637 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900638 }
639
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900641 switch target.Arch.ArchType.Multilib {
642 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900643 depsList = append(depsList, a.properties.Multilib.Lib32)
644 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900645 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900646 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900648 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900649 }
650 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900651
652 for _, d := range depsList {
653 addDependenciesForNativeModules(ctx, d, target, imageVariation)
654 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900655 }
656
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900657 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
658 // regardless of the TARGET_PREFER_* setting. See b/144532908
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900659 archForPrebuiltEtc := config.Arches()[0]
660 for _, arch := range config.Arches() {
661 // Prefer 64-bit arch if there is any
662 if arch.ArchType.Multilib == "lib64" {
663 archForPrebuiltEtc = arch
664 break
665 }
666 }
667 ctx.AddFarVariationDependencies([]blueprint.Variation{
668 {Mutator: "os", Variation: ctx.Os().String()},
669 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
670 }, prebuiltTag, a.properties.Prebuilts...)
671
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900672 // Common-arch dependencies come next
673 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
674 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
675 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900676
677 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
678 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900679 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900680 }
681
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900682 // Dependencies for signing
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900683 if String(a.properties.Key) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900684 ctx.PropertyErrorf("key", "missing")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900685 return
686 }
687 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
688
689 cert := android.SrcIsModule(a.getCertString(ctx))
690 if cert != "" {
691 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900692 // empty cert is not an error. Cert and private keys will be directly found under
693 // PRODUCT_DEFAULT_DEV_CERTIFICATE
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900694 }
695
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900696 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
697 // This field currently isn't used.
698 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900699 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
700 if len(a.properties.Uses_sdks) > 0 {
701 sdkRefs := []android.SdkRef{}
702 for _, str := range a.properties.Uses_sdks {
703 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
704 sdkRefs = append(sdkRefs, parsed)
705 }
706 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100707 }
708}
709
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900710// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900711func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
712 if a.overridableProperties.Allowed_files != nil {
713 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100714 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900715
716 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
717 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
718 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100719}
720
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900721type ApexBundleInfo struct {
722 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100723}
724
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900725var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900726
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900727// apexDepsMutator is responsible for collecting modules that need to have apex variants. They are
728// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
729// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
730// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
731// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900732func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900733 if !mctx.Module().Enabled() {
734 return
735 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900736
Jooyung Han698dd9f2020-07-22 15:17:19 +0900737 a, ok := mctx.Module().(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900738 if !ok {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900739 return
740 }
Jooyung Handf78e212020-07-22 15:54:47 +0900741
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900742 // The VNDK APEX is special. For the APEX, the membership is described in a very different
743 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
744 // libraries are self-identified by their vndk.enabled properties. There is no need to run
745 // this mutator for the APEX as nothing will be collected. So, let's return fast.
746 if a.vndkApex {
747 return
748 }
749
750 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
751 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
752 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
753 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
754 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900755 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
756 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
757 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
758 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
759 return
760 }
761
Colin Cross56a83212020-09-15 18:30:11 -0700762 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900763 am, ok := child.(android.ApexModule)
764 if !ok || !am.CanHaveApexVariants() {
765 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900766 }
Paul Duffina37eca22020-07-22 13:00:54 +0100767 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900768 return false
769 }
Jooyung Handf78e212020-07-22 15:54:47 +0900770 if excludeVndkLibs {
771 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
772 return false
773 }
774 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900775 // By default, all the transitive dependencies are collected, unless filtered out
776 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700777 return true
778 }
779
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900780 // Records whether a certain module is included in this apexBundle via direct dependency or
781 // inndirect dependency.
782 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700783 mctx.WalkDeps(func(child, parent android.Module) bool {
784 if !continueApexDepsWalk(child, parent) {
785 return false
786 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900787 // If the parent is apexBundle, this child is directly depended.
788 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900789 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700790 contents[depName] = contents[depName].Add(directDep)
791 return true
792 })
793
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900794 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900795 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700796 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
797 Contents: apexContents,
798 })
799
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900800 // This is the main part of this mutator. Mark the collected dependencies that they need to
801 // be built for this apexBundle.
Colin Cross56a83212020-09-15 18:30:11 -0700802 apexInfo := android.ApexInfo{
803 ApexVariationName: mctx.ModuleName(),
804 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
805 RequiredSdks: a.RequiredSdks(),
806 Updatable: a.Updatable(),
807 InApexes: []string{mctx.ModuleName()},
808 ApexContents: []*android.ApexContents{apexContents},
809 }
Colin Cross56a83212020-09-15 18:30:11 -0700810 mctx.WalkDeps(func(child, parent android.Module) bool {
811 if !continueApexDepsWalk(child, parent) {
812 return false
813 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900814 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900815 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900816 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900817}
818
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900819// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
820// unique apex variations for this module. See android/apex.go for more about unique apex variant.
821// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700822func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
823 if !mctx.Module().Enabled() {
824 return
825 }
826 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700827 android.UpdateUniqueApexVariationsForDeps(mctx, am)
828 }
829}
830
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900831// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
832// the apex in order to retrieve its contents later.
833// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700834func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
835 if !mctx.Module().Enabled() {
836 return
837 }
Colin Cross56a83212020-09-15 18:30:11 -0700838 if am, ok := mctx.Module().(android.ApexModule); ok {
839 if testFor := am.TestFor(); len(testFor) > 0 {
840 mctx.AddFarVariationDependencies([]blueprint.Variation{
841 {Mutator: "os", Variation: am.Target().OsVariation()},
842 {"arch", "common"},
843 }, testForTag, testFor...)
844 }
845 }
846}
847
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900848// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700849func apexTestForMutator(mctx android.BottomUpMutatorContext) {
850 if !mctx.Module().Enabled() {
851 return
852 }
Colin Cross56a83212020-09-15 18:30:11 -0700853 if _, ok := mctx.Module().(android.ApexModule); ok {
854 var contents []*android.ApexContents
855 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
856 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
857 contents = append(contents, abInfo.Contents)
858 }
859 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
860 ApexContents: contents,
861 })
Colin Crossaede88c2020-08-11 12:17:01 -0700862 }
863}
864
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900865// markPlatformAvailability marks whether or not a module can be available to platform. A module
866// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
867// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
868// be) available to platform
869// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +0900870func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
871 // Host and recovery are not considered as platform
872 if mctx.Host() || mctx.Module().InstallInRecovery() {
873 return
874 }
875
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900876 am, ok := mctx.Module().(android.ApexModule)
877 if !ok {
878 return
879 }
Jiyong Park89e850a2020-04-07 16:37:39 +0900880
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900881 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +0900882
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900883 // If any of the dep is not available to platform, this module is also considered as being
884 // not available to platform even if it has "//apex_available:platform"
885 mctx.VisitDirectDeps(func(child android.Module) {
886 if !am.DepIsInSameApex(mctx, child) {
887 // if the dependency crosses apex boundary, don't consider it
888 return
Jiyong Park89e850a2020-04-07 16:37:39 +0900889 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900890 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
891 availableToPlatform = false
892 // TODO(b/154889534) trigger an error when 'am' has
893 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +0900894 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900895 })
Jiyong Park89e850a2020-04-07 16:37:39 +0900896
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900897 // Exception 1: stub libraries and native bridge libraries are always available to platform
898 if cc, ok := mctx.Module().(*cc.Module); ok &&
899 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
900 availableToPlatform = true
901 }
902
903 // Exception 2: bootstrap bionic libraries are also always available to platform
904 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
905 availableToPlatform = true
906 }
907
908 if !availableToPlatform {
909 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900910 }
911}
912
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900913// apexMutator visits each module and creates apex variations if the module was marked in the
914// previous run of apexDepsMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900915func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900916 if !mctx.Module().Enabled() {
917 return
918 }
Colin Cross56a83212020-09-15 18:30:11 -0700919
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900920 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900921 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700922 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900923 return
924 }
925
926 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
927 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
928 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900929 apexBundleName := mctx.ModuleName()
930 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900931 } else if o, ok := mctx.Module().(*OverrideApex); ok {
932 apexBundleName := o.GetOverriddenModuleName()
933 if apexBundleName == "" {
934 mctx.ModuleErrorf("base property is not set")
935 return
936 }
937 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900938 }
939}
Sundong Ahne9b55722019-09-06 17:37:42 +0900940
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900941// See android.UpdateDirectlyInAnyApex
942// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700943func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
944 if !mctx.Module().Enabled() {
945 return
946 }
947 if am, ok := mctx.Module().(android.ApexModule); ok {
948 android.UpdateDirectlyInAnyApex(mctx, am)
949 }
950}
951
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900952// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900953type apexPackaging int
954
955const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900956 // imageApex is a packaging method where contents are included in a filesystem image which
957 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900958 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900959
960 // zipApex is a packaging method where contents are directly included in the zip container.
961 // This is used for host-side testing - because the contents are easily accessible by
962 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900963 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900964
965 // flattendApex is a packaging method where contents are not included in the APEX file, but
966 // installed to /apex/<apexname> directory on the device. This packaging method is used for
967 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900968 flattenedApex
969)
970
971const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900972 // File extensions of an APEX for different packaging methods
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900973 imageApexSuffix = ".apex"
974 zipApexSuffix = ".zipapex"
975 flattenedSuffix = ".flattened"
976
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900977 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900978 imageApexType = "image"
979 zipApexType = "zip"
980 flattenedApexType = "flattened"
981
982 ext4FsType = "ext4"
983 f2fsFsType = "f2fs"
984)
985
986// The suffix for the output "file", not the module
987func (a apexPackaging) suffix() string {
988 switch a {
989 case imageApex:
990 return imageApexSuffix
991 case zipApex:
992 return zipApexSuffix
993 default:
994 panic(fmt.Errorf("unknown APEX type %d", a))
995 }
996}
997
998func (a apexPackaging) name() string {
999 switch a {
1000 case imageApex:
1001 return imageApexType
1002 case zipApex:
1003 return zipApexType
1004 default:
1005 panic(fmt.Errorf("unknown APEX type %d", a))
1006 }
1007}
1008
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001009// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1010// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001011func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001012 if !mctx.Module().Enabled() {
1013 return
1014 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001015 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001016 var variants []string
1017 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1018 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001019 // This is the normal case. Note that both image and flattend APEXes are
1020 // created. The image type is installed to the system partition, while the
1021 // flattened APEX is (optionally) installed to the system_ext partition.
1022 // This is mostly for GSI which has to support wide range of devices. If GSI
1023 // is installed on a newer (APEX-capable) device, the image APEX in the
1024 // system will be used. However, if the same GSI is installed on an old
1025 // device which can't support image APEX, the flattened APEX in the
1026 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001027 variants = append(variants, imageApexType, flattenedApexType)
1028 case "zip":
1029 variants = append(variants, zipApexType)
1030 case "both":
1031 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1032 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001033 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001034 return
1035 }
1036
1037 modules := mctx.CreateLocalVariations(variants...)
1038
1039 for i, v := range variants {
1040 switch v {
1041 case imageApexType:
1042 modules[i].(*apexBundle).properties.ApexType = imageApex
1043 case zipApexType:
1044 modules[i].(*apexBundle).properties.ApexType = zipApex
1045 case flattenedApexType:
1046 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001047 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001048 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001049 modules[i].(*apexBundle).MakeAsSystemExt()
1050 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001051 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001052 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001053 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001054 // payload_type is forcibly overridden to "image"
1055 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001056 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001057 }
1058}
1059
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001060// checkUseVendorProperty checks if the use of `use_vendor` property is allowed for the given APEX.
1061// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1062// which may cause compatibility issues. (e.g. libbinder) Even though libbinder restricts its
1063// availability via 'apex_available' property and relies on yet another macro
1064// __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules to avoid
1065// similar problems.
1066func checkUseVendorProperty(ctx android.BottomUpMutatorContext, a *apexBundle) {
1067 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
1068 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1069 }
1070}
1071
Jooyung Handc782442019-11-01 03:14:38 +09001072var (
Colin Cross440e0d02020-06-11 11:32:11 -07001073 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +09001074)
1075
Colin Cross440e0d02020-06-11 11:32:11 -07001076func useVendorAllowList(config android.Config) []string {
1077 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +09001078 return []string{
1079 // swcodec uses "vendor" variants for smaller size
1080 "com.android.media.swcodec",
1081 "test_com.android.media.swcodec",
1082 }
1083 }).([]string)
1084}
1085
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001086// setUseVendorAllowListForTest overrides useVendorAllowList and must be called before the first
1087// call to useVendorAllowList()
Colin Cross440e0d02020-06-11 11:32:11 -07001088func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1089 config.Once(useVendorAllowListKey, func() interface{} {
1090 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001091 })
1092}
1093
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001094var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001095
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001096// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001097func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1098 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001099 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001100 return true
1101}
1102
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001103var _ android.OutputFileProducer = (*apexBundle)(nil)
1104
1105// Implements android.OutputFileProducer
1106func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1107 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001108 case "", android.DefaultDistTag:
1109 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001110 return android.Paths{a.outputFile}, nil
1111 default:
1112 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1113 }
1114}
1115
1116var _ cc.Coverage = (*apexBundle)(nil)
1117
1118// Implements cc.Coverage
1119func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1120 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1121}
1122
1123// Implements cc.Coverage
1124func (a *apexBundle) PreventInstall() {
1125 a.properties.PreventInstall = true
1126}
1127
1128// Implements cc.Coverage
1129func (a *apexBundle) HideFromMake() {
1130 a.properties.HideFromMake = true
1131}
1132
1133// Implements cc.Coverage
1134func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1135 a.properties.IsCoverageVariant = coverage
1136}
1137
1138// Implements cc.Coverage
1139func (a *apexBundle) EnableCoverageIfNeeded() {}
1140
1141var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1142
1143// Implements android.ApexBudleDepsInfoIntf
1144func (a *apexBundle) Updatable() bool {
1145 return proptools.Bool(a.properties.Updatable)
1146}
1147
1148// getCertString returns the name of the cert that should be used to sign this APEX. This is
1149// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001150func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001151 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001152 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1153 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1154 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001155 if a.vndkApex {
1156 moduleName = vndkApexName
1157 }
1158 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001159 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001160 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001161 }
1162 return String(a.properties.Certificate)
1163}
1164
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001165// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001166func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001167 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001168}
1169
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001170// See the test_only_no_hashtree property
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001171func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1172 return proptools.Bool(a.properties.Test_only_no_hashtree)
1173}
1174
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001175// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001176func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1177 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1178}
1179
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001180// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1181// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1182// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001183
Jiyong Parkf97782b2019-02-13 20:28:58 +09001184func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1185 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1186 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1187 }
1188}
1189
Jiyong Park388ef3f2019-01-28 19:47:32 +09001190func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001191 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1192 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001193 }
1194
1195 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001196 globalSanitizerNames := []string{}
1197 if a.Host() {
1198 globalSanitizerNames = ctx.Config().SanitizeHost()
1199 } else {
1200 arches := ctx.Config().SanitizeDeviceArch()
1201 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1202 globalSanitizerNames = ctx.Config().SanitizeDevice()
1203 }
1204 }
1205 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001206}
1207
Jooyung Han8ce8db92020-05-15 19:05:05 +09001208func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001209 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1210 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001211 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001212 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001213 for _, target := range ctx.MultiTargets() {
1214 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001215 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1216 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1217 Tests: nil,
1218 Jni_libs: nil,
1219 Binaries: nil,
1220 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001221 break
1222 }
1223 }
1224 }
1225}
1226
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001227// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1228// returned apexFile saves information about the Soong module that will be used for creating the
1229// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001230func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001231 // Decide the APEX-local directory by the multilib of the library In the future, we may
1232 // query this to the module.
1233 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001234 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001235 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001236 case "lib32":
1237 dirInApex = "lib"
1238 case "lib64":
1239 dirInApex = "lib64"
1240 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001241 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001242 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001243 }
Jooyung Han35155c42020-02-06 17:33:20 +09001244 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001245 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001246 // Special case for Bionic libs and other libs installed with them. This is to
1247 // prevent those libs from being included in the search path
1248 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1249 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1250 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1251 // will be loaded into the default linker namespace (aka "platform" namespace). If
1252 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1253 // be loaded again into the runtime linker namespace, which will result in double
1254 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001255 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001256 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001257
Jiyong Parkf653b052019-11-18 15:39:01 +09001258 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001259 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1260 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001261}
1262
Jiyong Park1833cef2019-12-13 13:28:36 +09001263func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001264 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001265 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001266 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001267 }
Jooyung Han35155c42020-02-06 17:33:20 +09001268 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001269 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001270 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1271 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001272 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001273 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001274 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001275}
1276
Jiyong Park99644e92020-11-17 22:21:02 +09001277func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1278 dirInApex := "bin"
1279 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1280 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1281 }
1282 fileToCopy := rustm.OutputFile().Path()
1283 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1284 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1285 return af
1286}
1287
1288func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1289 // Decide the APEX-local directory by the multilib of the library
1290 // In the future, we may query this to the module.
1291 var dirInApex string
1292 switch rustm.Arch().ArchType.Multilib {
1293 case "lib32":
1294 dirInApex = "lib"
1295 case "lib64":
1296 dirInApex = "lib64"
1297 }
1298 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1299 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1300 }
1301 fileToCopy := rustm.OutputFile().Path()
1302 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1303 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1304}
1305
Jiyong Park1833cef2019-12-13 13:28:36 +09001306func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001307 dirInApex := "bin"
1308 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001309 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001310}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001311
Jiyong Park1833cef2019-12-13 13:28:36 +09001312func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001313 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001314 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1315 if err != nil {
1316 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001317 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001318 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001319 fileToCopy := android.PathForOutput(ctx, s)
1320 // NB: Since go binaries are static we don't need the module for anything here, which is
1321 // good since the go tool is a blueprint.Module not an android.Module like we would
1322 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001323 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001324}
1325
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001326func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001327 dirInApex := filepath.Join("bin", sh.SubDir())
1328 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001329 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001330 af.symlinks = sh.Symlinks()
1331 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001332}
1333
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001334func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001335 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001336 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001337 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001338}
1339
atrost6e126252020-01-27 17:01:16 +00001340func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1341 dirInApex := filepath.Join("etc", config.SubDir())
1342 fileToCopy := config.CompatConfig()
1343 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1344}
1345
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001346// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1347// way.
1348type javaModule interface {
1349 android.Module
1350 BaseModuleName() string
1351 DexJarBuildPath() android.Path
1352 JacocoReportClassesFile() android.Path
1353 LintDepSets() java.LintDepSets
1354 Stem() string
1355}
1356
1357var _ javaModule = (*java.Library)(nil)
1358var _ javaModule = (*java.SdkLibrary)(nil)
1359var _ javaModule = (*java.DexImport)(nil)
1360var _ javaModule = (*java.SdkLibraryImport)(nil)
1361
1362func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
1363 dirInApex := "javalib"
1364 fileToCopy := module.DexJarBuildPath()
1365 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1366 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1367 af.lintDepSets = module.LintDepSets()
1368 af.customStem = module.Stem() + ".jar"
1369 return af
1370}
1371
1372// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1373// the same way.
1374type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001375 android.Module
1376 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001377 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001378 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001379 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001380 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001381 BaseModuleName() string
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001382}
1383
1384var _ androidApp = (*java.AndroidApp)(nil)
1385var _ androidApp = (*java.AndroidAppImport)(nil)
1386
1387func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001388 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001389 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001390 appDir = "priv-app"
1391 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001392 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001393 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001394 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001395 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001396 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001397
1398 if app, ok := aapp.(interface {
1399 OverriddenManifestPackageName() string
1400 }); ok {
1401 af.overriddenPackageName = app.OverriddenManifestPackageName()
1402 }
Jiyong Park618922e2020-01-08 13:35:43 +09001403 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001404}
1405
Jiyong Park69aeba92020-04-24 21:16:36 +09001406func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1407 rroDir := "overlay"
1408 dirInApex := filepath.Join(rroDir, rro.Theme())
1409 fileToCopy := rro.OutputFile()
1410 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1411 af.certificate = rro.Certificate()
1412
1413 if a, ok := rro.(interface {
1414 OverriddenManifestPackageName() string
1415 }); ok {
1416 af.overriddenPackageName = a.OverriddenManifestPackageName()
1417 }
1418 return af
1419}
1420
markchien2f59ec92020-09-02 16:23:38 +08001421func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1422 dirInApex := filepath.Join("etc", "bpf")
1423 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1424}
1425
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001426// WalyPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
1427// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1428// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1429// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001430func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001431 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001432 am, ok := child.(android.ApexModule)
1433 if !ok || !am.CanHaveApexVariants() {
1434 return false
1435 }
1436
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001437 // Filter-out unwanted depedendencies
1438 depTag := ctx.OtherModuleDependencyTag(child)
1439 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1440 return false
1441 }
1442 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001443 return false
1444 }
1445
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001446 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1447 externalDep := !android.InList(ctx.ModuleName(), ai.InApexes)
Jiyong Park0f80c182020-01-31 02:49:53 +09001448
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001449 // Visit actually
1450 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001451 })
1452}
1453
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001454// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1455type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001456
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001457const (
1458 ext4 fsType = iota
1459 f2fs
1460)
Artur Satayev849f8442020-04-28 14:57:42 +01001461
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001462func (f fsType) string() string {
1463 switch f {
1464 case ext4:
1465 return ext4FsType
1466 case f2fs:
1467 return f2fsFsType
1468 default:
1469 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001470 }
1471}
1472
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001473// Creates build rules for an APEX. It consists of the following major steps:
1474//
1475// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1476// 2) traverse the dependency tree to collect apexFile structs from them.
1477// 3) some fields in apexBundle struct are configured
1478// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001479func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001480 ////////////////////////////////////////////////////////////////////////////////////////////
1481 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001482 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001483 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001484 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001485 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001486 if len(a.properties.Tests) > 0 && !a.testApex {
1487 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1488 return
1489 }
Jiyong Park678c8812020-02-07 17:25:49 +09001490
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001491 ////////////////////////////////////////////////////////////////////////////////////////////
1492 // 2) traverse the dependency tree to collect apexFile structs from them.
1493
1494 // all the files that will be included in this APEX
1495 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001496
Jooyung Hane1633032019-08-01 17:41:43 +09001497 // native lib dependencies
1498 var provideNativeLibs []string
1499 var requireNativeLibs []string
1500
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001501 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1502
1503 // TODO(jiyong): do this using WalkPayloadDeps
1504 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001505 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001506 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001507 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1508 return false
1509 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001510 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001511 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001512 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001513 case sharedLibTag, jniLibTag:
1514 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001515 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001516 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1517 fi.isJniLib = isJniLib
1518 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001519 // Collect the list of stub-providing libs except:
1520 // - VNDK libs are only for vendors
1521 // - bootstrap bionic libs are treated as provided by system
1522 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001523 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001524 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001525 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001526 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001527 propertyName := "native_shared_libs"
1528 if isJniLib {
1529 propertyName = "jni_libs"
1530 }
1531 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001532 }
1533 case executableTag:
1534 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001535 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001536 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001537 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001538 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001539 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001540 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001541 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001542 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001543 } else if rust, ok := child.(*rust.Module); ok {
1544 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1545 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001546 } else {
Jiyong Park99644e92020-11-17 22:21:02 +09001547 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001548 }
1549 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001550 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01001551 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001552 af := apexFileForJavaModule(ctx, child.(javaModule))
1553 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001554 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1555 return false
1556 }
1557 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001558 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001559 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001560 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001561 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001562 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001563 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001564 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001565 return true // track transitive dependencies
1566 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001567 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001568 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001569 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001570 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1571 appDir := "app"
1572 if ap.Privileged() {
1573 appDir = "priv-app"
1574 }
Yo Chiange8128052020-07-23 20:09:18 +08001575 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001576 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1577 af.certificate = java.PresignedCertificate
1578 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001579 } else {
1580 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1581 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001582 case rroTag:
1583 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1584 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1585 } else {
1586 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1587 }
markchien2f59ec92020-09-02 16:23:38 +08001588 case bpfTag:
1589 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1590 filesToCopy, _ := bpfProgram.OutputFiles("")
1591 for _, bpfFile := range filesToCopy {
1592 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1593 }
1594 } else {
1595 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1596 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001597 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001598 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001599 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001600 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1601 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001602 } else {
atrost6e126252020-01-27 17:01:16 +00001603 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001604 }
Roland Levillain630846d2019-06-26 12:48:34 +01001605 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001606 if ccTest, ok := child.(*cc.Module); ok {
1607 if ccTest.IsTestPerSrcAllTestsVariation() {
1608 // Multiple-output test module (where `test_per_src: true`).
1609 //
1610 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1611 // We do not add this variation to `filesInfo`, as it has no output;
1612 // however, we do add the other variations of this module as indirect
1613 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001614 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001615 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001616 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001617 af.class = nativeTest
1618 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001619 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001620 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001621 } else {
1622 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1623 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001624 case keyTag:
1625 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001626 a.private_key_file = key.private_key_file
1627 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001628 } else {
1629 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001630 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001631 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001632 case certificateTag:
1633 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001634 a.container_certificate_file = dep.Certificate.Pem
1635 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001636 } else {
1637 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1638 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001639 case android.PrebuiltDepTag:
1640 // If the prebuilt is force disabled, remember to delete the prebuilt file
1641 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001642 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001643 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1644 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001645 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001646 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001647 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001648 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001649 // We cannot use a switch statement on `depTag` here as the checked
1650 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001651 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001652 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001653 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001654 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001655 return false
1656 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001657 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1658 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07001659 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1660 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001661 // If the dependency is a stubs lib, don't include it in this APEX,
1662 // but make sure that the lib is installed on the device.
1663 // In case no APEX is having the lib, the lib is installed to the system
1664 // partition.
1665 //
1666 // Always include if we are a host-apex however since those won't have any
1667 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001668 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001669 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07001670 name := cc.ImplementationModuleName(ctx)
1671
1672 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001673 // we don't use subName(.vendor) for a "use_vendor: true" apex
1674 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07001675 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001676 }
1677 if !android.InList(name, a.requiredDeps) {
1678 a.requiredDeps = append(a.requiredDeps, name)
1679 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001680 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001681 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001682 // Don't track further
1683 return false
1684 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 filesInfo = append(filesInfo, af)
1686 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001687 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001688 } else if cc.IsTestPerSrcDepTag(depTag) {
1689 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001690 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001691 // Handle modules created as `test_per_src` variations of a single test module:
1692 // use the name of the generated test binary (`fileToCopy`) instead of the name
1693 // of the original test module (`depName`, shared by all `test_per_src`
1694 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001695 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001696 // these are not considered transitive dep
1697 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001698 filesInfo = append(filesInfo, af)
1699 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001700 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001701 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001702 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1703 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001704 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001705 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001706 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1707 }
Jiyong Park99644e92020-11-17 22:21:02 +09001708 } else if rust.IsDylibDepTag(depTag) {
1709 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1710 af := apexFileForRustLibrary(ctx, rustm)
1711 af.transitiveDep = true
1712 filesInfo = append(filesInfo, af)
1713 return true // track transitive dependencies
1714 }
Colin Cross56a83212020-09-15 18:30:11 -07001715 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
1716 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09001717 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09001718 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001719 }
1720 }
1721 }
1722 return false
1723 })
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001724 if a.private_key_file == nil {
1725 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1726 return
1727 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001728
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001729 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. Build rules are
1730 // generated by the dexpreopt singleton, and here we access build artifacts via the global
1731 // boot image config.
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001732 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00001733 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001734 dirInApex := filepath.Join("javalib", arch.String())
1735 for _, f := range files {
1736 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001737 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001738 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001739 }
1740 }
1741 }
1742
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001743 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09001744 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001745 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001746 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001747 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001748 if e, ok := encountered[dest]; !ok {
1749 encountered[dest] = f
1750 } else {
1751 // If a module is directly included and also transitively depended on
1752 // consider it as directly included.
1753 e.transitiveDep = e.transitiveDep && f.transitiveDep
1754 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001755 }
1756 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001757 var result []apexFile
1758 for _, v := range encountered {
1759 result = append(result, v)
1760 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001761 return result
1762 }
1763 filesInfo = removeDup(filesInfo)
1764
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001765 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09001766 sort.Slice(filesInfo, func(i, j int) bool {
1767 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1768 })
1769
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001770 ////////////////////////////////////////////////////////////////////////////////////////////
1771 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09001772 a.installDir = android.PathForModuleInstall(ctx, "apex")
1773 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001774
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001775 // Set suffix and primaryApexType depending on the ApexType
1776 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
1777 switch a.properties.ApexType {
1778 case imageApex:
1779 if buildFlattenedAsDefault {
1780 a.suffix = imageApexSuffix
1781 } else {
1782 a.suffix = ""
1783 a.primaryApexType = true
1784
1785 if ctx.Config().InstallExtraFlattenedApexes() {
1786 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
1787 }
1788 }
1789 case zipApex:
1790 if proptools.String(a.properties.Payload_type) == "zip" {
1791 a.suffix = ""
1792 a.primaryApexType = true
1793 } else {
1794 a.suffix = zipApexSuffix
1795 }
1796 case flattenedApex:
1797 if buildFlattenedAsDefault {
1798 a.suffix = ""
1799 a.primaryApexType = true
1800 } else {
1801 a.suffix = flattenedSuffix
1802 }
1803 }
1804
Theotime Combes4ba38c12020-06-12 12:46:59 +00001805 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
1806 case ext4FsType:
1807 a.payloadFsType = ext4
1808 case f2fsFsType:
1809 a.payloadFsType = f2fs
1810 default:
1811 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
1812 }
1813
Jiyong Park7cd10e32020-01-14 09:22:18 +09001814 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1815 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1816 // the same library in the system partition, thus effectively sharing the same libraries
1817 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1818 // in the APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001819 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() && !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001820
Jooyung Han85d61762020-06-24 23:50:26 +09001821 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
1822 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001823 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001824 a.linkToSystemLib = false
1825 }
1826
Jiyong Park9d677202020-02-19 16:29:35 +09001827 // We don't need the optimization for updatable APEXes, as it might give false signal
1828 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01001829 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09001830 a.linkToSystemLib = false
1831 }
1832
Jiyong Park638d30e2020-02-26 18:27:19 +09001833 // We also don't want the optimization for host APEXes, because it doesn't make sense.
1834 if ctx.Host() {
1835 a.linkToSystemLib = false
1836 }
1837
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001838 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
1839
1840 ////////////////////////////////////////////////////////////////////////////////////////////
1841 // 4) generate the build rules to create the APEX. This is done in builder.go.
1842 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001843 if a.properties.ApexType == flattenedApex {
1844 a.buildFlattenedApex(ctx)
1845 } else {
1846 a.buildUnflattenedApex(ctx)
1847 }
Jiyong Park956305c2020-01-09 12:32:06 +09001848 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07001849 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09001850
1851 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
1852 if a.installable() {
1853 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
1854 // along with other ordinary files. (Note that this is done by apexer for
1855 // non-flattened APEXes)
1856 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
1857
1858 // Place the public key as apex_pubkey. This is also done by apexer for
1859 // non-flattened APEXes case.
1860 // TODO(jiyong): Why do we need this CP rule?
1861 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1862 ctx.Build(pctx, android.BuildParams{
1863 Rule: android.Cp,
1864 Input: a.public_key_file,
1865 Output: copiedPubkey,
1866 })
1867 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
1868 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09001869}
1870
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001871///////////////////////////////////////////////////////////////////////////////////////////////////
1872// Factory functions
1873//
1874
1875func newApexBundle() *apexBundle {
1876 module := &apexBundle{}
1877
1878 module.AddProperties(&module.properties)
1879 module.AddProperties(&module.targetProperties)
1880 module.AddProperties(&module.overridableProperties)
1881
1882 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1883 android.InitDefaultableModule(module)
1884 android.InitSdkAwareModule(module)
1885 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
1886 return module
1887}
1888
1889func ApexBundleFactory(testApex bool, artApex bool) android.Module {
1890 bundle := newApexBundle()
1891 bundle.testApex = testApex
1892 bundle.artApex = artApex
1893 return bundle
1894}
1895
1896// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
1897// certain compatibility checks such as apex_available are not done for apex_test.
1898func testApexBundleFactory() android.Module {
1899 bundle := newApexBundle()
1900 bundle.testApex = true
1901 return bundle
1902}
1903
1904// apex packages other modules into an APEX file which is a packaging format for system-level
1905// components like binaries, shared libraries, etc.
1906func BundleFactory() android.Module {
1907 return newApexBundle()
1908}
1909
1910type Defaults struct {
1911 android.ModuleBase
1912 android.DefaultsModuleBase
1913}
1914
1915// apex_defaults provides defaultable properties to other apex modules.
1916func defaultsFactory() android.Module {
1917 return DefaultsFactory()
1918}
1919
1920func DefaultsFactory(props ...interface{}) android.Module {
1921 module := &Defaults{}
1922
1923 module.AddProperties(props...)
1924 module.AddProperties(
1925 &apexBundleProperties{},
1926 &apexTargetBundleProperties{},
1927 &overridableProperties{},
1928 )
1929
1930 android.InitDefaultsModule(module)
1931 return module
1932}
1933
1934type OverrideApex struct {
1935 android.ModuleBase
1936 android.OverrideModuleBase
1937}
1938
1939func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1940 // All the overrides happen in the base module.
1941}
1942
1943// override_apex is used to create an apex module based on another apex module by overriding some of
1944// its properties.
1945func overrideApexFactory() android.Module {
1946 m := &OverrideApex{}
1947
1948 m.AddProperties(&overridableProperties{})
1949
1950 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1951 android.InitOverrideModule(m)
1952 return m
1953}
1954
1955///////////////////////////////////////////////////////////////////////////////////////////////////
1956// Vality check routines
1957//
1958// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
1959// certain conditions are not met.
1960//
1961// TODO(jiyong): move these checks to a separate go file.
1962
1963// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
1964// of this apexBundle.
1965func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1966 if a.testApex || a.vndkApex {
1967 return
1968 }
1969 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1970 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1971 return
1972 }
1973 // apexBundle::minSdkVersion reports its own errors.
1974 minSdkVersion := a.minSdkVersion(ctx)
1975 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
1976}
1977
1978func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
1979 ver := proptools.String(a.properties.Min_sdk_version)
1980 if ver == "" {
1981 return android.FutureApiLevel
1982 }
1983 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
1984 if err != nil {
1985 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
1986 return android.NoneApiLevel
1987 }
1988 if apiLevel.IsPreview() {
1989 // All codenames should build against "current".
1990 return android.FutureApiLevel
1991 }
1992 return apiLevel
1993}
1994
1995// Ensures that a lib providing stub isn't statically linked
1996func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1997 // Practically, we only care about regular APEXes on the device.
1998 if ctx.Host() || a.testApex || a.vndkApex {
1999 return
2000 }
2001
2002 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2003
2004 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2005 if ccm, ok := to.(*cc.Module); ok {
2006 apexName := ctx.ModuleName()
2007 fromName := ctx.OtherModuleName(from)
2008 toName := ctx.OtherModuleName(to)
2009
2010 // If `to` is not actually in the same APEX as `from` then it does not need
2011 // apex_available and neither do any of its dependencies.
2012 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2013 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2014 return false
2015 }
2016
2017 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2018 // exception to this rule. It can't make the static dependencies dynamic
2019 // because it can't do the dynamic linking for itself.
2020 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
2021 return false
2022 }
2023
2024 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2025 if isStubLibraryFromOtherApex && !externalDep {
2026 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2027 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2028 }
2029
2030 }
2031 return true
2032 })
2033}
2034
Artur Satayev8cf899a2020-04-15 17:29:42 +01002035// Enforce that Java deps of the apex are using stable SDKs to compile
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002036func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2037 if a.Updatable() {
2038 if String(a.properties.Min_sdk_version) == "" {
2039 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2040 }
2041 a.checkJavaStableSdkVersion(ctx)
2042 }
2043}
2044
Artur Satayev8cf899a2020-04-15 17:29:42 +01002045func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002046 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2047 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002048 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2049 tag := ctx.OtherModuleDependencyTag(module)
2050 switch tag {
2051 case javaLibTag, androidAppTag:
2052 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2053 if err := m.CheckStableSdkVersion(); err != nil {
2054 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2055 }
2056 }
2057 }
2058 })
2059}
2060
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002061// Ensures that the all the dependencies are marked as available for this APEX
2062func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2063 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2064 if ctx.Host() || a.testApex || a.vndkApex {
2065 return
2066 }
2067
2068 // Because APEXes targeting other than system/system_ext partitions can't set
2069 // apex_available, we skip checks for these APEXes
2070 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2071 return
2072 }
2073
2074 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2075 // Requiring them and their transitive depencies with apex_available is not right
2076 // because they just add noise.
2077 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2078 return
2079 }
2080
2081 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2082 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2083 if externalDep {
2084 return false
2085 }
2086
2087 apexName := ctx.ModuleName()
2088 fromName := ctx.OtherModuleName(from)
2089 toName := ctx.OtherModuleName(to)
2090
2091 // If `to` is not actually in the same APEX as `from` then it does not need
2092 // apex_available and neither do any of its dependencies.
2093 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2094 // As soon as the dependency graph crosses the APEX boundary, don't go
2095 // further.
2096 return false
2097 }
2098
2099 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2100 return true
2101 }
2102 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'. Dependency path:%s",
2103 fromName, toName, ctx.GetPathString(true))
2104 // Visit this module's dependencies to check and report any issues with their availability.
2105 return true
2106 })
2107}
2108
2109var (
2110 apexAvailBaseline = makeApexAvailableBaseline()
2111 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2112)
2113
Colin Cross440e0d02020-06-11 11:32:11 -07002114func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002115 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002116 moduleName = normalizeModuleName(moduleName)
2117
Colin Cross440e0d02020-06-11 11:32:11 -07002118 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002119 return true
2120 }
2121
2122 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002123 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002124 return true
2125 }
2126
2127 return false
2128}
2129
2130func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002131 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2132 // system. Trim the prefix for the check since they are confusing
2133 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2134 if strings.HasPrefix(moduleName, "libclang_rt.") {
2135 // This module has many arch variants that depend on the product being built.
2136 // We don't want to list them all
2137 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002138 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002139 if strings.HasPrefix(moduleName, "androidx.") {
2140 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2141 moduleName = "androidx"
2142 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002143 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002144}
2145
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002146// Transform the map of apex -> modules to module -> apexes.
2147func invertApexBaseline(m map[string][]string) map[string][]string {
2148 r := make(map[string][]string)
2149 for apex, modules := range m {
2150 for _, module := range modules {
2151 r[module] = append(r[module], apex)
2152 }
2153 }
2154 return r
2155}
2156
2157// Retrieve the baseline of apexes to which the supplied module belongs.
2158func BaselineApexAvailable(moduleName string) []string {
2159 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2160}
2161
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002162// This is a map from apex to modules, which overrides the apex_available setting for that
2163// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002164// TODO(b/147364041): remove this
2165func makeApexAvailableBaseline() map[string][]string {
2166 // The "Module separator"s below are employed to minimize merge conflicts.
2167 m := make(map[string][]string)
2168 //
2169 // Module separator
2170 //
2171 m["com.android.appsearch"] = []string{
2172 "icing-java-proto-lite",
2173 "libprotobuf-java-lite",
2174 }
2175 //
2176 // Module separator
2177 //
2178 m["com.android.bluetooth.updatable"] = []string{
2179 "android.hardware.audio.common@5.0",
2180 "android.hardware.bluetooth.a2dp@1.0",
2181 "android.hardware.bluetooth.audio@2.0",
2182 "android.hardware.bluetooth@1.0",
2183 "android.hardware.bluetooth@1.1",
2184 "android.hardware.graphics.bufferqueue@1.0",
2185 "android.hardware.graphics.bufferqueue@2.0",
2186 "android.hardware.graphics.common@1.0",
2187 "android.hardware.graphics.common@1.1",
2188 "android.hardware.graphics.common@1.2",
2189 "android.hardware.media@1.0",
2190 "android.hidl.safe_union@1.0",
2191 "android.hidl.token@1.0",
2192 "android.hidl.token@1.0-utils",
2193 "avrcp-target-service",
2194 "avrcp_headers",
2195 "bluetooth-protos-lite",
2196 "bluetooth.mapsapi",
2197 "com.android.vcard",
2198 "dnsresolver_aidl_interface-V2-java",
2199 "ipmemorystore-aidl-interfaces-V5-java",
2200 "ipmemorystore-aidl-interfaces-java",
2201 "internal_include_headers",
2202 "lib-bt-packets",
2203 "lib-bt-packets-avrcp",
2204 "lib-bt-packets-base",
2205 "libFraunhoferAAC",
2206 "libaudio-a2dp-hw-utils",
2207 "libaudio-hearing-aid-hw-utils",
2208 "libbinder_headers",
2209 "libbluetooth",
2210 "libbluetooth-types",
2211 "libbluetooth-types-header",
2212 "libbluetooth_gd",
2213 "libbluetooth_headers",
2214 "libbluetooth_jni",
2215 "libbt-audio-hal-interface",
2216 "libbt-bta",
2217 "libbt-common",
2218 "libbt-hci",
2219 "libbt-platform-protos-lite",
2220 "libbt-protos-lite",
2221 "libbt-sbc-decoder",
2222 "libbt-sbc-encoder",
2223 "libbt-stack",
2224 "libbt-utils",
2225 "libbtcore",
2226 "libbtdevice",
2227 "libbte",
2228 "libbtif",
2229 "libchrome",
2230 "libevent",
2231 "libfmq",
2232 "libg722codec",
2233 "libgui_headers",
2234 "libmedia_headers",
2235 "libmodpb64",
2236 "libosi",
2237 "libstagefright_foundation_headers",
2238 "libstagefright_headers",
2239 "libstatslog",
2240 "libstatssocket",
2241 "libtinyxml2",
2242 "libudrv-uipc",
2243 "libz",
2244 "media_plugin_headers",
2245 "net-utils-services-common",
2246 "netd_aidl_interface-unstable-java",
2247 "netd_event_listener_interface-java",
2248 "netlink-client",
2249 "networkstack-client",
2250 "sap-api-java-static",
2251 "services.net",
2252 }
2253 //
2254 // Module separator
2255 //
2256 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2257 //
2258 // Module separator
2259 //
2260 m["com.android.extservices"] = []string{
2261 "error_prone_annotations",
2262 "ExtServices-core",
2263 "ExtServices",
2264 "libtextclassifier-java",
2265 "libz_current",
2266 "textclassifier-statsd",
2267 "TextClassifierNotificationLibNoManifest",
2268 "TextClassifierServiceLibNoManifest",
2269 }
2270 //
2271 // Module separator
2272 //
2273 m["com.android.neuralnetworks"] = []string{
2274 "android.hardware.neuralnetworks@1.0",
2275 "android.hardware.neuralnetworks@1.1",
2276 "android.hardware.neuralnetworks@1.2",
2277 "android.hardware.neuralnetworks@1.3",
2278 "android.hidl.allocator@1.0",
2279 "android.hidl.memory.token@1.0",
2280 "android.hidl.memory@1.0",
2281 "android.hidl.safe_union@1.0",
2282 "libarect",
2283 "libbuildversion",
2284 "libmath",
2285 "libprocpartition",
2286 "libsync",
2287 }
2288 //
2289 // Module separator
2290 //
2291 m["com.android.media"] = []string{
2292 "android.frameworks.bufferhub@1.0",
2293 "android.hardware.cas.native@1.0",
2294 "android.hardware.cas@1.0",
2295 "android.hardware.configstore-utils",
2296 "android.hardware.configstore@1.0",
2297 "android.hardware.configstore@1.1",
2298 "android.hardware.graphics.allocator@2.0",
2299 "android.hardware.graphics.allocator@3.0",
2300 "android.hardware.graphics.bufferqueue@1.0",
2301 "android.hardware.graphics.bufferqueue@2.0",
2302 "android.hardware.graphics.common@1.0",
2303 "android.hardware.graphics.common@1.1",
2304 "android.hardware.graphics.common@1.2",
2305 "android.hardware.graphics.mapper@2.0",
2306 "android.hardware.graphics.mapper@2.1",
2307 "android.hardware.graphics.mapper@3.0",
2308 "android.hardware.media.omx@1.0",
2309 "android.hardware.media@1.0",
2310 "android.hidl.allocator@1.0",
2311 "android.hidl.memory.token@1.0",
2312 "android.hidl.memory@1.0",
2313 "android.hidl.token@1.0",
2314 "android.hidl.token@1.0-utils",
2315 "bionic_libc_platform_headers",
2316 "exoplayer2-extractor",
2317 "exoplayer2-extractor-annotation-stubs",
2318 "gl_headers",
2319 "jsr305",
2320 "libEGL",
2321 "libEGL_blobCache",
2322 "libEGL_getProcAddress",
2323 "libFLAC",
2324 "libFLAC-config",
2325 "libFLAC-headers",
2326 "libGLESv2",
2327 "libaacextractor",
2328 "libamrextractor",
2329 "libarect",
2330 "libaudio_system_headers",
2331 "libaudioclient",
2332 "libaudioclient_headers",
2333 "libaudiofoundation",
2334 "libaudiofoundation_headers",
2335 "libaudiomanager",
2336 "libaudiopolicy",
2337 "libaudioutils",
2338 "libaudioutils_fixedfft",
2339 "libbinder_headers",
2340 "libbluetooth-types-header",
2341 "libbufferhub",
2342 "libbufferhub_headers",
2343 "libbufferhubqueue",
2344 "libc_malloc_debug_backtrace",
2345 "libcamera_client",
2346 "libcamera_metadata",
2347 "libdvr_headers",
2348 "libexpat",
2349 "libfifo",
2350 "libflacextractor",
2351 "libgrallocusage",
2352 "libgraphicsenv",
2353 "libgui",
2354 "libgui_headers",
2355 "libhardware_headers",
2356 "libinput",
2357 "liblzma",
2358 "libmath",
2359 "libmedia",
2360 "libmedia_codeclist",
2361 "libmedia_headers",
2362 "libmedia_helper",
2363 "libmedia_helper_headers",
2364 "libmedia_midiiowrapper",
2365 "libmedia_omx",
2366 "libmediautils",
2367 "libmidiextractor",
2368 "libmkvextractor",
2369 "libmp3extractor",
2370 "libmp4extractor",
2371 "libmpeg2extractor",
2372 "libnativebase_headers",
2373 "libnativewindow_headers",
2374 "libnblog",
2375 "liboggextractor",
2376 "libpackagelistparser",
2377 "libpdx",
2378 "libpdx_default_transport",
2379 "libpdx_headers",
2380 "libpdx_uds",
2381 "libprocinfo",
2382 "libspeexresampler",
2383 "libspeexresampler",
2384 "libstagefright_esds",
2385 "libstagefright_flacdec",
2386 "libstagefright_flacdec",
2387 "libstagefright_foundation",
2388 "libstagefright_foundation_headers",
2389 "libstagefright_foundation_without_imemory",
2390 "libstagefright_headers",
2391 "libstagefright_id3",
2392 "libstagefright_metadatautils",
2393 "libstagefright_mpeg2extractor",
2394 "libstagefright_mpeg2support",
2395 "libsync",
2396 "libui",
2397 "libui_headers",
2398 "libunwindstack",
2399 "libvibrator",
2400 "libvorbisidec",
2401 "libwavextractor",
2402 "libwebm",
2403 "media_ndk_headers",
2404 "media_plugin_headers",
2405 "updatable-media",
2406 }
2407 //
2408 // Module separator
2409 //
2410 m["com.android.media.swcodec"] = []string{
2411 "android.frameworks.bufferhub@1.0",
2412 "android.hardware.common-ndk_platform",
2413 "android.hardware.configstore-utils",
2414 "android.hardware.configstore@1.0",
2415 "android.hardware.configstore@1.1",
2416 "android.hardware.graphics.allocator@2.0",
2417 "android.hardware.graphics.allocator@3.0",
2418 "android.hardware.graphics.allocator@4.0",
2419 "android.hardware.graphics.bufferqueue@1.0",
2420 "android.hardware.graphics.bufferqueue@2.0",
2421 "android.hardware.graphics.common-ndk_platform",
2422 "android.hardware.graphics.common@1.0",
2423 "android.hardware.graphics.common@1.1",
2424 "android.hardware.graphics.common@1.2",
2425 "android.hardware.graphics.mapper@2.0",
2426 "android.hardware.graphics.mapper@2.1",
2427 "android.hardware.graphics.mapper@3.0",
2428 "android.hardware.graphics.mapper@4.0",
2429 "android.hardware.media.bufferpool@2.0",
2430 "android.hardware.media.c2@1.0",
2431 "android.hardware.media.c2@1.1",
2432 "android.hardware.media.omx@1.0",
2433 "android.hardware.media@1.0",
2434 "android.hardware.media@1.0",
2435 "android.hidl.memory.token@1.0",
2436 "android.hidl.memory@1.0",
2437 "android.hidl.safe_union@1.0",
2438 "android.hidl.token@1.0",
2439 "android.hidl.token@1.0-utils",
2440 "libEGL",
2441 "libFLAC",
2442 "libFLAC-config",
2443 "libFLAC-headers",
2444 "libFraunhoferAAC",
2445 "libLibGuiProperties",
2446 "libarect",
2447 "libaudio_system_headers",
2448 "libaudioutils",
2449 "libaudioutils",
2450 "libaudioutils_fixedfft",
2451 "libavcdec",
2452 "libavcenc",
2453 "libavservices_minijail",
2454 "libavservices_minijail",
2455 "libbinder_headers",
2456 "libbinderthreadstateutils",
2457 "libbluetooth-types-header",
2458 "libbufferhub_headers",
2459 "libcodec2",
2460 "libcodec2_headers",
2461 "libcodec2_hidl@1.0",
2462 "libcodec2_hidl@1.1",
2463 "libcodec2_internal",
2464 "libcodec2_soft_aacdec",
2465 "libcodec2_soft_aacenc",
2466 "libcodec2_soft_amrnbdec",
2467 "libcodec2_soft_amrnbenc",
2468 "libcodec2_soft_amrwbdec",
2469 "libcodec2_soft_amrwbenc",
2470 "libcodec2_soft_av1dec_gav1",
2471 "libcodec2_soft_avcdec",
2472 "libcodec2_soft_avcenc",
2473 "libcodec2_soft_common",
2474 "libcodec2_soft_flacdec",
2475 "libcodec2_soft_flacenc",
2476 "libcodec2_soft_g711alawdec",
2477 "libcodec2_soft_g711mlawdec",
2478 "libcodec2_soft_gsmdec",
2479 "libcodec2_soft_h263dec",
2480 "libcodec2_soft_h263enc",
2481 "libcodec2_soft_hevcdec",
2482 "libcodec2_soft_hevcenc",
2483 "libcodec2_soft_mp3dec",
2484 "libcodec2_soft_mpeg2dec",
2485 "libcodec2_soft_mpeg4dec",
2486 "libcodec2_soft_mpeg4enc",
2487 "libcodec2_soft_opusdec",
2488 "libcodec2_soft_opusenc",
2489 "libcodec2_soft_rawdec",
2490 "libcodec2_soft_vorbisdec",
2491 "libcodec2_soft_vp8dec",
2492 "libcodec2_soft_vp8enc",
2493 "libcodec2_soft_vp9dec",
2494 "libcodec2_soft_vp9enc",
2495 "libcodec2_vndk",
2496 "libdvr_headers",
2497 "libfmq",
2498 "libfmq",
2499 "libgav1",
2500 "libgralloctypes",
2501 "libgrallocusage",
2502 "libgraphicsenv",
2503 "libgsm",
2504 "libgui_bufferqueue_static",
2505 "libgui_headers",
2506 "libhardware",
2507 "libhardware_headers",
2508 "libhevcdec",
2509 "libhevcenc",
2510 "libion",
2511 "libjpeg",
2512 "liblzma",
2513 "libmath",
2514 "libmedia_codecserviceregistrant",
2515 "libmedia_headers",
2516 "libmpeg2dec",
2517 "libnativebase_headers",
2518 "libnativewindow_headers",
2519 "libpdx_headers",
2520 "libscudo_wrapper",
2521 "libsfplugin_ccodec_utils",
2522 "libspeexresampler",
2523 "libstagefright_amrnb_common",
2524 "libstagefright_amrnbdec",
2525 "libstagefright_amrnbenc",
2526 "libstagefright_amrwbdec",
2527 "libstagefright_amrwbenc",
2528 "libstagefright_bufferpool@2.0.1",
2529 "libstagefright_bufferqueue_helper",
2530 "libstagefright_enc_common",
2531 "libstagefright_flacdec",
2532 "libstagefright_foundation",
2533 "libstagefright_foundation_headers",
2534 "libstagefright_headers",
2535 "libstagefright_m4vh263dec",
2536 "libstagefright_m4vh263enc",
2537 "libstagefright_mp3dec",
2538 "libsync",
2539 "libui",
2540 "libui_headers",
2541 "libunwindstack",
2542 "libvorbisidec",
2543 "libvpx",
2544 "libyuv",
2545 "libyuv_static",
2546 "media_ndk_headers",
2547 "media_plugin_headers",
2548 "mediaswcodec",
2549 }
2550 //
2551 // Module separator
2552 //
2553 m["com.android.mediaprovider"] = []string{
2554 "MediaProvider",
2555 "MediaProviderGoogle",
2556 "fmtlib_ndk",
2557 "libbase_ndk",
2558 "libfuse",
2559 "libfuse_jni",
2560 }
2561 //
2562 // Module separator
2563 //
2564 m["com.android.permission"] = []string{
2565 "car-ui-lib",
2566 "iconloader",
2567 "kotlin-annotations",
2568 "kotlin-stdlib",
2569 "kotlin-stdlib-jdk7",
2570 "kotlin-stdlib-jdk8",
2571 "kotlinx-coroutines-android",
2572 "kotlinx-coroutines-android-nodeps",
2573 "kotlinx-coroutines-core",
2574 "kotlinx-coroutines-core-nodeps",
2575 "permissioncontroller-statsd",
2576 "GooglePermissionController",
2577 "PermissionController",
2578 "SettingsLibActionBarShadow",
2579 "SettingsLibAppPreference",
2580 "SettingsLibBarChartPreference",
2581 "SettingsLibLayoutPreference",
2582 "SettingsLibProgressBar",
2583 "SettingsLibSearchWidget",
2584 "SettingsLibSettingsTheme",
2585 "SettingsLibRestrictedLockUtils",
2586 "SettingsLibHelpUtils",
2587 }
2588 //
2589 // Module separator
2590 //
2591 m["com.android.runtime"] = []string{
2592 "bionic_libc_platform_headers",
2593 "libarm-optimized-routines-math",
2594 "libc_aeabi",
2595 "libc_bionic",
2596 "libc_bionic_ndk",
2597 "libc_bootstrap",
2598 "libc_common",
2599 "libc_common_shared",
2600 "libc_common_static",
2601 "libc_dns",
2602 "libc_dynamic_dispatch",
2603 "libc_fortify",
2604 "libc_freebsd",
2605 "libc_freebsd_large_stack",
2606 "libc_gdtoa",
2607 "libc_init_dynamic",
2608 "libc_init_static",
2609 "libc_jemalloc_wrapper",
2610 "libc_netbsd",
2611 "libc_nomalloc",
2612 "libc_nopthread",
2613 "libc_openbsd",
2614 "libc_openbsd_large_stack",
2615 "libc_openbsd_ndk",
2616 "libc_pthread",
2617 "libc_static_dispatch",
2618 "libc_syscalls",
2619 "libc_tzcode",
2620 "libc_unwind_static",
2621 "libdebuggerd",
2622 "libdebuggerd_common_headers",
2623 "libdebuggerd_handler_core",
2624 "libdebuggerd_handler_fallback",
2625 "libdl_static",
2626 "libjemalloc5",
2627 "liblinker_main",
2628 "liblinker_malloc",
2629 "liblz4",
2630 "liblzma",
2631 "libprocinfo",
2632 "libpropertyinfoparser",
2633 "libscudo",
2634 "libstdc++",
2635 "libsystemproperties",
2636 "libtombstoned_client_static",
2637 "libunwindstack",
2638 "libz",
2639 "libziparchive",
2640 }
2641 //
2642 // Module separator
2643 //
2644 m["com.android.tethering"] = []string{
2645 "android.hardware.tetheroffload.config-V1.0-java",
2646 "android.hardware.tetheroffload.control-V1.0-java",
2647 "android.hidl.base-V1.0-java",
2648 "libcgrouprc",
2649 "libcgrouprc_format",
2650 "libtetherutilsjni",
2651 "libvndksupport",
2652 "net-utils-framework-common",
2653 "netd_aidl_interface-V3-java",
2654 "netlink-client",
2655 "networkstack-aidl-interfaces-java",
2656 "tethering-aidl-interfaces-java",
2657 "TetheringApiCurrentLib",
2658 }
2659 //
2660 // Module separator
2661 //
2662 m["com.android.wifi"] = []string{
2663 "PlatformProperties",
2664 "android.hardware.wifi-V1.0-java",
2665 "android.hardware.wifi-V1.0-java-constants",
2666 "android.hardware.wifi-V1.1-java",
2667 "android.hardware.wifi-V1.2-java",
2668 "android.hardware.wifi-V1.3-java",
2669 "android.hardware.wifi-V1.4-java",
2670 "android.hardware.wifi.hostapd-V1.0-java",
2671 "android.hardware.wifi.hostapd-V1.1-java",
2672 "android.hardware.wifi.hostapd-V1.2-java",
2673 "android.hardware.wifi.supplicant-V1.0-java",
2674 "android.hardware.wifi.supplicant-V1.1-java",
2675 "android.hardware.wifi.supplicant-V1.2-java",
2676 "android.hardware.wifi.supplicant-V1.3-java",
2677 "android.hidl.base-V1.0-java",
2678 "android.hidl.manager-V1.0-java",
2679 "android.hidl.manager-V1.1-java",
2680 "android.hidl.manager-V1.2-java",
2681 "bouncycastle-unbundled",
2682 "dnsresolver_aidl_interface-V2-java",
2683 "error_prone_annotations",
2684 "framework-wifi-pre-jarjar",
2685 "framework-wifi-util-lib",
2686 "ipmemorystore-aidl-interfaces-V3-java",
2687 "ipmemorystore-aidl-interfaces-java",
2688 "ksoap2",
2689 "libnanohttpd",
2690 "libwifi-jni",
2691 "net-utils-services-common",
2692 "netd_aidl_interface-V2-java",
2693 "netd_aidl_interface-unstable-java",
2694 "netd_event_listener_interface-java",
2695 "netlink-client",
2696 "networkstack-client",
2697 "services.net",
2698 "wifi-lite-protos",
2699 "wifi-nano-protos",
2700 "wifi-service-pre-jarjar",
2701 "wifi-service-resources",
2702 }
2703 //
2704 // Module separator
2705 //
2706 m["com.android.sdkext"] = []string{
2707 "fmtlib_ndk",
2708 "libbase_ndk",
2709 "libprotobuf-cpp-lite-ndk",
2710 }
2711 //
2712 // Module separator
2713 //
2714 m["com.android.os.statsd"] = []string{
2715 "libstatssocket",
2716 }
2717 //
2718 // Module separator
2719 //
2720 m[android.AvailableToAnyApex] = []string{
2721 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
2722 "androidx",
2723 "androidx-constraintlayout_constraintlayout",
2724 "androidx-constraintlayout_constraintlayout-nodeps",
2725 "androidx-constraintlayout_constraintlayout-solver",
2726 "androidx-constraintlayout_constraintlayout-solver-nodeps",
2727 "com.google.android.material_material",
2728 "com.google.android.material_material-nodeps",
2729
2730 "libatomic",
2731 "libclang_rt",
2732 "libgcc_stripped",
2733 "libprofile-clang-extras",
2734 "libprofile-clang-extras_ndk",
2735 "libprofile-extras",
2736 "libprofile-extras_ndk",
2737 "libunwind_llvm",
2738 }
2739 return m
2740}
2741
2742func init() {
2743 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
2744 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
2745}
2746
2747func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
2748 rules := make([]android.Rule, 0, len(modules_packages))
2749 for module_name, module_packages := range modules_packages {
2750 permitted_packages_rule := android.NeverAllow().
2751 BootclasspathJar().
2752 With("apex_available", module_name).
2753 WithMatcher("permitted_packages", android.NotInList(module_packages)).
2754 Because("jars that are part of the " + module_name +
2755 " module may only allow these packages: " + strings.Join(module_packages, ",") +
2756 ". Please jarjar or move code around.")
2757 rules = append(rules, permitted_packages_rule)
2758 }
2759 return rules
2760}
2761
2762// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2763// Adding code to the bootclasspath in new packages will cause issues on module update.
2764func qModulesPackages() map[string][]string {
2765 return map[string][]string{
2766 "com.android.conscrypt": []string{
2767 "android.net.ssl",
2768 "com.android.org.conscrypt",
2769 },
2770 "com.android.media": []string{
2771 "android.media",
2772 },
2773 }
2774}
2775
2776// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2777// Adding code to the bootclasspath in new packages will cause issues on module update.
2778func rModulesPackages() map[string][]string {
2779 return map[string][]string{
2780 "com.android.mediaprovider": []string{
2781 "android.provider",
2782 },
2783 "com.android.permission": []string{
2784 "android.permission",
2785 "android.app.role",
2786 "com.android.permission",
2787 "com.android.role",
2788 },
2789 "com.android.sdkext": []string{
2790 "android.os.ext",
2791 },
2792 "com.android.os.statsd": []string{
2793 "android.app",
2794 "android.os",
2795 "android.util",
2796 "com.android.internal.statsd",
2797 "com.android.server.stats",
2798 },
2799 "com.android.wifi": []string{
2800 "com.android.server.wifi",
2801 "com.android.wifi.x",
2802 "android.hardware.wifi",
2803 "android.net.wifi",
2804 },
2805 "com.android.tethering": []string{
2806 "android.net",
2807 },
2808 }
2809}