blob: fceb307f17ea4b9fe0d866264bb22d63d72e92b4 [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
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900356
357 distFiles android.TaggedDistFiles
358}
359
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900360// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361type apexFileClass int
362
Jooyung Han72bd2f82019-10-23 16:46:38 +0900363const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900364 app apexFileClass = iota
365 appSet
366 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900367 goBinary
368 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900369 nativeExecutable
370 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900371 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900372 pyBinary
373 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900374)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900375
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376// apexFile represents a file in an APEX bundle. This is created during the first half of
377// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
378// of the function, this is used to create commands that copies the files into a staging directory,
379// where they are packaged into the APEX file. This struct is also used for creating Make modules
380// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900381type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900382 // buildFile is put in the installDir inside the APEX.
383 builtFile android.Path
384 noticeFiles android.Paths
385 installDir string
386 customStem string
387 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900388
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900389 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
390 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
391 // suffix>]
392 androidMkModuleName string // becomes LOCAL_MODULE
393 class apexFileClass // becomes LOCAL_MODULE_CLASS
394 moduleDir string // becomes LOCAL_PATH
395 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
396 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
397 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
398 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900399
400 jacocoReportClassesFile android.Path // only for javalibs and apps
401 lintDepSets java.LintDepSets // only for javalibs and apps
402 certificate java.Certificate // only for apps
403 overriddenPackageName string // only for apps
404
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900405 transitiveDep bool
406 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900407
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900408 // TODO(jiyong): remove this
409 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900410}
411
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900412// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900413func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
414 ret := apexFile{
415 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900416 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900417 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900418 class: class,
419 module: module,
420 }
421 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900422 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900423 ret.moduleDir = ctx.OtherModuleDir(module)
424 ret.requiredModuleNames = module.RequiredModuleNames()
425 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
426 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900427 }
428 return ret
429}
430
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900431func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900432 return af.builtFile != nil && af.builtFile.String() != ""
433}
434
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900435// apexRelativePath returns the relative path of the given path from the install directory of this
436// apexFile.
437// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900438func (af *apexFile) apexRelativePath(path string) string {
439 return filepath.Join(af.installDir, path)
440}
441
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900442// path returns path of this apex file relative to the APEX root
443func (af *apexFile) path() string {
444 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900445}
446
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900447// stem returns the base filename of this apex file
448func (af *apexFile) stem() string {
449 if af.customStem != "" {
450 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900451 }
452 return af.builtFile.Base()
453}
454
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900455// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
456func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900457 var ret []string
458 for _, symlink := range af.symlinks {
459 ret = append(ret, af.apexRelativePath(symlink))
460 }
461 return ret
462}
463
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900464// availableToPlatform tests whether this apexFile is from a module that can be installed to the
465// platform.
466func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900467 if af.module == nil {
468 return false
469 }
470 if am, ok := af.module.(android.ApexModule); ok {
471 return am.AvailableFor(android.AvailableToPlatform)
472 }
473 return false
474}
475
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900476////////////////////////////////////////////////////////////////////////////////////////////////////
477// Mutators
478//
479// Brief description about mutators for APEX. The following three mutators are the most important
480// ones.
481//
482// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
483// to the (direct) dependencies of this APEX bundle.
484//
485// 2) apexDepsMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
486// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
487// modules are marked as being included in the APEX via BuildForApex().
488//
489// 3) apexMutator: this is a post-deps mutator that runs after apexDepsMutator. For each module that
490// are marked by the apexDepsMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900491
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900492type dependencyTag struct {
493 blueprint.BaseDependencyTag
494 name string
495
496 // Determines if the dependent will be part of the APEX payload. Can be false for the
497 // dependencies to the signing key module, etc.
498 payload bool
499}
500
501var (
502 androidAppTag = dependencyTag{name: "androidApp", payload: true}
503 bpfTag = dependencyTag{name: "bpf", payload: true}
504 certificateTag = dependencyTag{name: "certificate"}
505 executableTag = dependencyTag{name: "executable", payload: true}
506 javaLibTag = dependencyTag{name: "javaLib", payload: true}
507 jniLibTag = dependencyTag{name: "jniLib", payload: true}
508 keyTag = dependencyTag{name: "key"}
509 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
510 rroTag = dependencyTag{name: "rro", payload: true}
511 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
512 testForTag = dependencyTag{name: "test for"}
513 testTag = dependencyTag{name: "test", payload: true}
514)
515
516// TODO(jiyong): shorten this function signature
517func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900518 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900519 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park99644e92020-11-17 22:21:02 +0900520 rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521
522 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900523 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900524 libVariations = append(libVariations,
525 blueprint.Variation{Mutator: "image", Variation: imageVariation},
Jiyong Park99644e92020-11-17 22:21:02 +0900526 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
527 rustLibVariations = append(rustLibVariations,
528 blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900529 }
530
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900531 // Use *FarVariation* to be able to depend on modules having conflicting variations with
532 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
533 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900534 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900535 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900536 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
537 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park99644e92020-11-17 22:21:02 +0900538 ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900539}
540
541func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900542 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900543 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
544 } else {
545 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
546 if ctx.Os().Bionic() {
547 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
548 } else {
549 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
550 }
551 }
552}
553
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900554// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
555// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
556func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
557 deviceConfig := ctx.DeviceConfig()
558 if a.vndkApex {
559 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900560 }
561
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900562 var prefix string
563 var vndkVersion string
564 if deviceConfig.VndkVersion() != "" {
565 if proptools.Bool(a.properties.Use_vendor) {
566 prefix = cc.VendorVariationPrefix
567 vndkVersion = deviceConfig.PlatformVndkVersion()
568 } else if a.SocSpecific() || a.DeviceSpecific() {
569 prefix = cc.VendorVariationPrefix
570 vndkVersion = deviceConfig.VndkVersion()
571 } else if a.ProductSpecific() {
572 prefix = cc.ProductVariationPrefix
573 vndkVersion = deviceConfig.ProductVndkVersion()
574 }
575 }
576 if vndkVersion == "current" {
577 vndkVersion = deviceConfig.PlatformVndkVersion()
578 }
579 if vndkVersion != "" {
580 return prefix + vndkVersion
581 }
582
583 return android.CoreVariation // The usual case
584}
585
586func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
587 // TODO(jiyong): move this kind of checks to GenerateAndroidBuildActions?
588 checkUseVendorProperty(ctx, a)
589
590 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
591 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
592 // each target os/architectures, appropriate dependencies are selected by their
593 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900594 targets := ctx.MultiTargets()
595 config := ctx.DeviceConfig()
596 imageVariation := a.getImageVariation(ctx)
597
598 a.combineProperties(ctx)
599
600 has32BitTarget := false
601 for _, target := range targets {
602 if target.Arch.ArchType.Multilib == "lib32" {
603 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000604 }
605 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900606 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900607 // Don't include artifacts for the host cross targets because there is no way for us
608 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900609 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900610 continue
611 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000612
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900613 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000614
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900615 // Add native modules targeting both ABIs. When multilib.* is omitted for
616 // native_shared_libs/jni_libs/tests, it implies multilib.both
617 depsList = append(depsList, a.properties.Multilib.Both)
618 depsList = append(depsList, ApexNativeDependencies{
619 Native_shared_libs: a.properties.Native_shared_libs,
620 Tests: a.properties.Tests,
621 Jni_libs: a.properties.Jni_libs,
622 Binaries: nil,
623 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900624
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900625 // Add native modules targeting the first ABI When multilib.* is omitted for
626 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900627 isPrimaryAbi := i == 0
628 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900629 depsList = append(depsList, a.properties.Multilib.First)
630 depsList = append(depsList, ApexNativeDependencies{
631 Native_shared_libs: nil,
632 Tests: nil,
633 Jni_libs: nil,
634 Binaries: a.properties.Binaries,
635 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900636 }
637
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900638 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900639 switch target.Arch.ArchType.Multilib {
640 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900641 depsList = append(depsList, a.properties.Multilib.Lib32)
642 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900643 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900644 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900645 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900646 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900647 }
648 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900649
650 for _, d := range depsList {
651 addDependenciesForNativeModules(ctx, d, target, imageVariation)
652 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900653 }
654
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900655 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
656 // regardless of the TARGET_PREFER_* setting. See b/144532908
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900657 archForPrebuiltEtc := config.Arches()[0]
658 for _, arch := range config.Arches() {
659 // Prefer 64-bit arch if there is any
660 if arch.ArchType.Multilib == "lib64" {
661 archForPrebuiltEtc = arch
662 break
663 }
664 }
665 ctx.AddFarVariationDependencies([]blueprint.Variation{
666 {Mutator: "os", Variation: ctx.Os().String()},
667 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
668 }, prebuiltTag, a.properties.Prebuilts...)
669
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900670 // Common-arch dependencies come next
671 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
672 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
673 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900674
675 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
676 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900677 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900678 }
679
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900680 // Dependencies for signing
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900681 if String(a.properties.Key) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900682 ctx.PropertyErrorf("key", "missing")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900683 return
684 }
685 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
686
687 cert := android.SrcIsModule(a.getCertString(ctx))
688 if cert != "" {
689 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900690 // empty cert is not an error. Cert and private keys will be directly found under
691 // PRODUCT_DEFAULT_DEV_CERTIFICATE
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900692 }
693
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900694 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
695 // This field currently isn't used.
696 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900697 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
698 if len(a.properties.Uses_sdks) > 0 {
699 sdkRefs := []android.SdkRef{}
700 for _, str := range a.properties.Uses_sdks {
701 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
702 sdkRefs = append(sdkRefs, parsed)
703 }
704 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100705 }
706}
707
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900708// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900709func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
710 if a.overridableProperties.Allowed_files != nil {
711 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100712 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900713
714 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
715 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
716 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100717}
718
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900719type ApexBundleInfo struct {
720 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100721}
722
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900723var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900724
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900725// apexDepsMutator is responsible for collecting modules that need to have apex variants. They are
726// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
727// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
728// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
729// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900730func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900731 if !mctx.Module().Enabled() {
732 return
733 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900734
Jooyung Han698dd9f2020-07-22 15:17:19 +0900735 a, ok := mctx.Module().(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900736 if !ok {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900737 return
738 }
Jooyung Handf78e212020-07-22 15:54:47 +0900739
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900740 // The VNDK APEX is special. For the APEX, the membership is described in a very different
741 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
742 // libraries are self-identified by their vndk.enabled properties. There is no need to run
743 // this mutator for the APEX as nothing will be collected. So, let's return fast.
744 if a.vndkApex {
745 return
746 }
747
748 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
749 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
750 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
751 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
752 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900753 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
754 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
755 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
756 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
757 return
758 }
759
Colin Cross56a83212020-09-15 18:30:11 -0700760 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900761 am, ok := child.(android.ApexModule)
762 if !ok || !am.CanHaveApexVariants() {
763 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900764 }
Paul Duffina37eca22020-07-22 13:00:54 +0100765 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900766 return false
767 }
Jooyung Handf78e212020-07-22 15:54:47 +0900768 if excludeVndkLibs {
769 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
770 return false
771 }
772 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900773 // By default, all the transitive dependencies are collected, unless filtered out
774 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700775 return true
776 }
777
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900778 // Records whether a certain module is included in this apexBundle via direct dependency or
779 // inndirect dependency.
780 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700781 mctx.WalkDeps(func(child, parent android.Module) bool {
782 if !continueApexDepsWalk(child, parent) {
783 return false
784 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900785 // If the parent is apexBundle, this child is directly depended.
786 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900787 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700788 contents[depName] = contents[depName].Add(directDep)
789 return true
790 })
791
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900792 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900793 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700794 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
795 Contents: apexContents,
796 })
797
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900798 // This is the main part of this mutator. Mark the collected dependencies that they need to
799 // be built for this apexBundle.
Colin Cross56a83212020-09-15 18:30:11 -0700800 apexInfo := android.ApexInfo{
801 ApexVariationName: mctx.ModuleName(),
802 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
803 RequiredSdks: a.RequiredSdks(),
804 Updatable: a.Updatable(),
805 InApexes: []string{mctx.ModuleName()},
806 ApexContents: []*android.ApexContents{apexContents},
807 }
Colin Cross56a83212020-09-15 18:30:11 -0700808 mctx.WalkDeps(func(child, parent android.Module) bool {
809 if !continueApexDepsWalk(child, parent) {
810 return false
811 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900812 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900813 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900814 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900815}
816
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900817// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
818// unique apex variations for this module. See android/apex.go for more about unique apex variant.
819// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700820func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
821 if !mctx.Module().Enabled() {
822 return
823 }
824 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700825 android.UpdateUniqueApexVariationsForDeps(mctx, am)
826 }
827}
828
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900829// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
830// the apex in order to retrieve its contents later.
831// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700832func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
833 if !mctx.Module().Enabled() {
834 return
835 }
Colin Cross56a83212020-09-15 18:30:11 -0700836 if am, ok := mctx.Module().(android.ApexModule); ok {
837 if testFor := am.TestFor(); len(testFor) > 0 {
838 mctx.AddFarVariationDependencies([]blueprint.Variation{
839 {Mutator: "os", Variation: am.Target().OsVariation()},
840 {"arch", "common"},
841 }, testForTag, testFor...)
842 }
843 }
844}
845
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900846// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700847func apexTestForMutator(mctx android.BottomUpMutatorContext) {
848 if !mctx.Module().Enabled() {
849 return
850 }
Colin Cross56a83212020-09-15 18:30:11 -0700851 if _, ok := mctx.Module().(android.ApexModule); ok {
852 var contents []*android.ApexContents
853 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
854 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
855 contents = append(contents, abInfo.Contents)
856 }
857 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
858 ApexContents: contents,
859 })
Colin Crossaede88c2020-08-11 12:17:01 -0700860 }
861}
862
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900863// markPlatformAvailability marks whether or not a module can be available to platform. A module
864// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
865// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
866// be) available to platform
867// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +0900868func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
869 // Host and recovery are not considered as platform
870 if mctx.Host() || mctx.Module().InstallInRecovery() {
871 return
872 }
873
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900874 am, ok := mctx.Module().(android.ApexModule)
875 if !ok {
876 return
877 }
Jiyong Park89e850a2020-04-07 16:37:39 +0900878
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900879 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +0900880
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900881 // If any of the dep is not available to platform, this module is also considered as being
882 // not available to platform even if it has "//apex_available:platform"
883 mctx.VisitDirectDeps(func(child android.Module) {
884 if !am.DepIsInSameApex(mctx, child) {
885 // if the dependency crosses apex boundary, don't consider it
886 return
Jiyong Park89e850a2020-04-07 16:37:39 +0900887 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900888 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
889 availableToPlatform = false
890 // TODO(b/154889534) trigger an error when 'am' has
891 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +0900892 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900893 })
Jiyong Park89e850a2020-04-07 16:37:39 +0900894
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900895 // Exception 1: stub libraries and native bridge libraries are always available to platform
896 if cc, ok := mctx.Module().(*cc.Module); ok &&
897 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
898 availableToPlatform = true
899 }
900
901 // Exception 2: bootstrap bionic libraries are also always available to platform
902 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
903 availableToPlatform = true
904 }
905
906 if !availableToPlatform {
907 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900908 }
909}
910
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900911// apexMutator visits each module and creates apex variations if the module was marked in the
912// previous run of apexDepsMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900913func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900914 if !mctx.Module().Enabled() {
915 return
916 }
Colin Cross56a83212020-09-15 18:30:11 -0700917
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900918 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900919 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700920 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900921 return
922 }
923
924 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
925 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
926 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900927 apexBundleName := mctx.ModuleName()
928 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900929 } else if o, ok := mctx.Module().(*OverrideApex); ok {
930 apexBundleName := o.GetOverriddenModuleName()
931 if apexBundleName == "" {
932 mctx.ModuleErrorf("base property is not set")
933 return
934 }
935 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900936 }
937}
Sundong Ahne9b55722019-09-06 17:37:42 +0900938
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900939// See android.UpdateDirectlyInAnyApex
940// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700941func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
942 if !mctx.Module().Enabled() {
943 return
944 }
945 if am, ok := mctx.Module().(android.ApexModule); ok {
946 android.UpdateDirectlyInAnyApex(mctx, am)
947 }
948}
949
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900950// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900951type apexPackaging int
952
953const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900954 // imageApex is a packaging method where contents are included in a filesystem image which
955 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900956 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900957
958 // zipApex is a packaging method where contents are directly included in the zip container.
959 // This is used for host-side testing - because the contents are easily accessible by
960 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900961 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900962
963 // flattendApex is a packaging method where contents are not included in the APEX file, but
964 // installed to /apex/<apexname> directory on the device. This packaging method is used for
965 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900966 flattenedApex
967)
968
969const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900970 // File extensions of an APEX for different packaging methods
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900971 imageApexSuffix = ".apex"
972 zipApexSuffix = ".zipapex"
973 flattenedSuffix = ".flattened"
974
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900975 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900976 imageApexType = "image"
977 zipApexType = "zip"
978 flattenedApexType = "flattened"
979
980 ext4FsType = "ext4"
981 f2fsFsType = "f2fs"
982)
983
984// The suffix for the output "file", not the module
985func (a apexPackaging) suffix() string {
986 switch a {
987 case imageApex:
988 return imageApexSuffix
989 case zipApex:
990 return zipApexSuffix
991 default:
992 panic(fmt.Errorf("unknown APEX type %d", a))
993 }
994}
995
996func (a apexPackaging) name() string {
997 switch a {
998 case imageApex:
999 return imageApexType
1000 case zipApex:
1001 return zipApexType
1002 default:
1003 panic(fmt.Errorf("unknown APEX type %d", a))
1004 }
1005}
1006
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001007// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1008// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001009func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001010 if !mctx.Module().Enabled() {
1011 return
1012 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001013 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001014 var variants []string
1015 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1016 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001017 // This is the normal case. Note that both image and flattend APEXes are
1018 // created. The image type is installed to the system partition, while the
1019 // flattened APEX is (optionally) installed to the system_ext partition.
1020 // This is mostly for GSI which has to support wide range of devices. If GSI
1021 // is installed on a newer (APEX-capable) device, the image APEX in the
1022 // system will be used. However, if the same GSI is installed on an old
1023 // device which can't support image APEX, the flattened APEX in the
1024 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001025 variants = append(variants, imageApexType, flattenedApexType)
1026 case "zip":
1027 variants = append(variants, zipApexType)
1028 case "both":
1029 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1030 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001031 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001032 return
1033 }
1034
1035 modules := mctx.CreateLocalVariations(variants...)
1036
1037 for i, v := range variants {
1038 switch v {
1039 case imageApexType:
1040 modules[i].(*apexBundle).properties.ApexType = imageApex
1041 case zipApexType:
1042 modules[i].(*apexBundle).properties.ApexType = zipApex
1043 case flattenedApexType:
1044 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001045 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001046 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001047 modules[i].(*apexBundle).MakeAsSystemExt()
1048 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001049 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001050 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001051 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001052 // payload_type is forcibly overridden to "image"
1053 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001054 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001055 }
1056}
1057
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001058// checkUseVendorProperty checks if the use of `use_vendor` property is allowed for the given APEX.
1059// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1060// which may cause compatibility issues. (e.g. libbinder) Even though libbinder restricts its
1061// availability via 'apex_available' property and relies on yet another macro
1062// __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules to avoid
1063// similar problems.
1064func checkUseVendorProperty(ctx android.BottomUpMutatorContext, a *apexBundle) {
1065 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
1066 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1067 }
1068}
1069
Jooyung Handc782442019-11-01 03:14:38 +09001070var (
Colin Cross440e0d02020-06-11 11:32:11 -07001071 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +09001072)
1073
Colin Cross440e0d02020-06-11 11:32:11 -07001074func useVendorAllowList(config android.Config) []string {
1075 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +09001076 return []string{
1077 // swcodec uses "vendor" variants for smaller size
1078 "com.android.media.swcodec",
1079 "test_com.android.media.swcodec",
1080 }
1081 }).([]string)
1082}
1083
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001084// setUseVendorAllowListForTest overrides useVendorAllowList and must be called before the first
1085// call to useVendorAllowList()
Colin Cross440e0d02020-06-11 11:32:11 -07001086func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1087 config.Once(useVendorAllowListKey, func() interface{} {
1088 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001089 })
1090}
1091
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001092var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001093
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001094// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001095func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1096 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001097 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001098 return true
1099}
1100
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001101var _ android.OutputFileProducer = (*apexBundle)(nil)
1102
1103// Implements android.OutputFileProducer
1104func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1105 switch tag {
1106 case "":
1107 return android.Paths{a.outputFile}, nil
1108 default:
1109 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1110 }
1111}
1112
1113var _ cc.Coverage = (*apexBundle)(nil)
1114
1115// Implements cc.Coverage
1116func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1117 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1118}
1119
1120// Implements cc.Coverage
1121func (a *apexBundle) PreventInstall() {
1122 a.properties.PreventInstall = true
1123}
1124
1125// Implements cc.Coverage
1126func (a *apexBundle) HideFromMake() {
1127 a.properties.HideFromMake = true
1128}
1129
1130// Implements cc.Coverage
1131func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1132 a.properties.IsCoverageVariant = coverage
1133}
1134
1135// Implements cc.Coverage
1136func (a *apexBundle) EnableCoverageIfNeeded() {}
1137
1138var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1139
1140// Implements android.ApexBudleDepsInfoIntf
1141func (a *apexBundle) Updatable() bool {
1142 return proptools.Bool(a.properties.Updatable)
1143}
1144
1145// getCertString returns the name of the cert that should be used to sign this APEX. This is
1146// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001147func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001148 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001149 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1150 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1151 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001152 if a.vndkApex {
1153 moduleName = vndkApexName
1154 }
1155 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001156 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001157 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001158 }
1159 return String(a.properties.Certificate)
1160}
1161
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001162// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001163func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001164 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001165}
1166
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001167// See the test_only_no_hashtree property
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001168func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1169 return proptools.Bool(a.properties.Test_only_no_hashtree)
1170}
1171
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001172// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001173func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1174 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1175}
1176
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001177// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1178// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1179// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001180
Jiyong Parkf97782b2019-02-13 20:28:58 +09001181func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1182 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1183 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1184 }
1185}
1186
Jiyong Park388ef3f2019-01-28 19:47:32 +09001187func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001188 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1189 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001190 }
1191
1192 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001193 globalSanitizerNames := []string{}
1194 if a.Host() {
1195 globalSanitizerNames = ctx.Config().SanitizeHost()
1196 } else {
1197 arches := ctx.Config().SanitizeDeviceArch()
1198 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1199 globalSanitizerNames = ctx.Config().SanitizeDevice()
1200 }
1201 }
1202 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001203}
1204
Jooyung Han8ce8db92020-05-15 19:05:05 +09001205func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001206 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1207 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001208 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001209 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001210 for _, target := range ctx.MultiTargets() {
1211 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001212 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1213 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1214 Tests: nil,
1215 Jni_libs: nil,
1216 Binaries: nil,
1217 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001218 break
1219 }
1220 }
1221 }
1222}
1223
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001224// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1225// returned apexFile saves information about the Soong module that will be used for creating the
1226// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001227func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001228 // Decide the APEX-local directory by the multilib of the library In the future, we may
1229 // query this to the module.
1230 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001231 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001232 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001233 case "lib32":
1234 dirInApex = "lib"
1235 case "lib64":
1236 dirInApex = "lib64"
1237 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001238 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001239 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001240 }
Jooyung Han35155c42020-02-06 17:33:20 +09001241 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001242 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001243 // Special case for Bionic libs and other libs installed with them. This is to
1244 // prevent those libs from being included in the search path
1245 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1246 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1247 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1248 // will be loaded into the default linker namespace (aka "platform" namespace). If
1249 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1250 // be loaded again into the runtime linker namespace, which will result in double
1251 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001252 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001253 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001254
Jiyong Parkf653b052019-11-18 15:39:01 +09001255 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001256 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1257 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001258}
1259
Jiyong Park1833cef2019-12-13 13:28:36 +09001260func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001261 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001262 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001263 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001264 }
Jooyung Han35155c42020-02-06 17:33:20 +09001265 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001266 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001267 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1268 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001269 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001270 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001271 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001272}
1273
Jiyong Park99644e92020-11-17 22:21:02 +09001274func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1275 dirInApex := "bin"
1276 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1277 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1278 }
1279 fileToCopy := rustm.OutputFile().Path()
1280 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1281 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm)
1282 return af
1283}
1284
1285func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
1286 // Decide the APEX-local directory by the multilib of the library
1287 // In the future, we may query this to the module.
1288 var dirInApex string
1289 switch rustm.Arch().ArchType.Multilib {
1290 case "lib32":
1291 dirInApex = "lib"
1292 case "lib64":
1293 dirInApex = "lib64"
1294 }
1295 if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
1296 dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
1297 }
1298 fileToCopy := rustm.OutputFile().Path()
1299 androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
1300 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
1301}
1302
Jiyong Park1833cef2019-12-13 13:28:36 +09001303func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001304 dirInApex := "bin"
1305 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001306 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001307}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001308
Jiyong Park1833cef2019-12-13 13:28:36 +09001309func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001310 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001311 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1312 if err != nil {
1313 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001314 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001315 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001316 fileToCopy := android.PathForOutput(ctx, s)
1317 // NB: Since go binaries are static we don't need the module for anything here, which is
1318 // good since the go tool is a blueprint.Module not an android.Module like we would
1319 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001320 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001321}
1322
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001323func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001324 dirInApex := filepath.Join("bin", sh.SubDir())
1325 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001326 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001327 af.symlinks = sh.Symlinks()
1328 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001329}
1330
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001331func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001332 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001333 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001334 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001335}
1336
atrost6e126252020-01-27 17:01:16 +00001337func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1338 dirInApex := filepath.Join("etc", config.SubDir())
1339 fileToCopy := config.CompatConfig()
1340 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1341}
1342
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001343// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1344// way.
1345type javaModule interface {
1346 android.Module
1347 BaseModuleName() string
1348 DexJarBuildPath() android.Path
1349 JacocoReportClassesFile() android.Path
1350 LintDepSets() java.LintDepSets
1351 Stem() string
1352}
1353
1354var _ javaModule = (*java.Library)(nil)
1355var _ javaModule = (*java.SdkLibrary)(nil)
1356var _ javaModule = (*java.DexImport)(nil)
1357var _ javaModule = (*java.SdkLibraryImport)(nil)
1358
1359func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
1360 dirInApex := "javalib"
1361 fileToCopy := module.DexJarBuildPath()
1362 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1363 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1364 af.lintDepSets = module.LintDepSets()
1365 af.customStem = module.Stem() + ".jar"
1366 return af
1367}
1368
1369// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1370// the same way.
1371type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001372 android.Module
1373 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001374 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001375 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001376 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001377 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001378 BaseModuleName() string
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001379}
1380
1381var _ androidApp = (*java.AndroidApp)(nil)
1382var _ androidApp = (*java.AndroidAppImport)(nil)
1383
1384func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001385 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001386 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001387 appDir = "priv-app"
1388 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001389 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001390 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001391 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001392 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001393 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001394
1395 if app, ok := aapp.(interface {
1396 OverriddenManifestPackageName() string
1397 }); ok {
1398 af.overriddenPackageName = app.OverriddenManifestPackageName()
1399 }
Jiyong Park618922e2020-01-08 13:35:43 +09001400 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001401}
1402
Jiyong Park69aeba92020-04-24 21:16:36 +09001403func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1404 rroDir := "overlay"
1405 dirInApex := filepath.Join(rroDir, rro.Theme())
1406 fileToCopy := rro.OutputFile()
1407 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1408 af.certificate = rro.Certificate()
1409
1410 if a, ok := rro.(interface {
1411 OverriddenManifestPackageName() string
1412 }); ok {
1413 af.overriddenPackageName = a.OverriddenManifestPackageName()
1414 }
1415 return af
1416}
1417
markchien2f59ec92020-09-02 16:23:38 +08001418func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1419 dirInApex := filepath.Join("etc", "bpf")
1420 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1421}
1422
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001423// WalyPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
1424// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1425// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1426// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001427func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001428 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001429 am, ok := child.(android.ApexModule)
1430 if !ok || !am.CanHaveApexVariants() {
1431 return false
1432 }
1433
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001434 // Filter-out unwanted depedendencies
1435 depTag := ctx.OtherModuleDependencyTag(child)
1436 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1437 return false
1438 }
1439 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001440 return false
1441 }
1442
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001443 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1444 externalDep := !android.InList(ctx.ModuleName(), ai.InApexes)
Jiyong Park0f80c182020-01-31 02:49:53 +09001445
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001446 // Visit actually
1447 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001448 })
1449}
1450
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001451// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1452type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001453
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001454const (
1455 ext4 fsType = iota
1456 f2fs
1457)
Artur Satayev849f8442020-04-28 14:57:42 +01001458
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001459func (f fsType) string() string {
1460 switch f {
1461 case ext4:
1462 return ext4FsType
1463 case f2fs:
1464 return f2fsFsType
1465 default:
1466 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001467 }
1468}
1469
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001470// Creates build rules for an APEX. It consists of the following major steps:
1471//
1472// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1473// 2) traverse the dependency tree to collect apexFile structs from them.
1474// 3) some fields in apexBundle struct are configured
1475// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001476func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001477 ////////////////////////////////////////////////////////////////////////////////////////////
1478 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001479 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001480 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001481 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001482 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001483 if len(a.properties.Tests) > 0 && !a.testApex {
1484 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1485 return
1486 }
Jiyong Park678c8812020-02-07 17:25:49 +09001487
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001488 ////////////////////////////////////////////////////////////////////////////////////////////
1489 // 2) traverse the dependency tree to collect apexFile structs from them.
1490
1491 // all the files that will be included in this APEX
1492 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001493
Jooyung Hane1633032019-08-01 17:41:43 +09001494 // native lib dependencies
1495 var provideNativeLibs []string
1496 var requireNativeLibs []string
1497
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001498 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1499
1500 // TODO(jiyong): do this using WalkPayloadDeps
1501 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001502 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001503 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001504 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1505 return false
1506 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001507 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001508 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001509 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001510 case sharedLibTag, jniLibTag:
1511 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001512 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001513 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1514 fi.isJniLib = isJniLib
1515 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001516 // Collect the list of stub-providing libs except:
1517 // - VNDK libs are only for vendors
1518 // - bootstrap bionic libs are treated as provided by system
1519 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001520 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001521 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001522 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001523 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001524 propertyName := "native_shared_libs"
1525 if isJniLib {
1526 propertyName = "jni_libs"
1527 }
1528 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001529 }
1530 case executableTag:
1531 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001532 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001533 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001534 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001535 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001536 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001537 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001538 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001539 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Park99644e92020-11-17 22:21:02 +09001540 } else if rust, ok := child.(*rust.Module); ok {
1541 filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust))
1542 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001543 } else {
Jiyong Park99644e92020-11-17 22:21:02 +09001544 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 +09001545 }
1546 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001547 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01001548 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001549 af := apexFileForJavaModule(ctx, child.(javaModule))
1550 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001551 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1552 return false
1553 }
1554 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001555 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001556 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001557 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001558 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001559 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001560 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001561 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001562 return true // track transitive dependencies
1563 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001564 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001565 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001566 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001567 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1568 appDir := "app"
1569 if ap.Privileged() {
1570 appDir = "priv-app"
1571 }
Yo Chiange8128052020-07-23 20:09:18 +08001572 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001573 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1574 af.certificate = java.PresignedCertificate
1575 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001576 } else {
1577 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1578 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001579 case rroTag:
1580 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1581 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1582 } else {
1583 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1584 }
markchien2f59ec92020-09-02 16:23:38 +08001585 case bpfTag:
1586 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1587 filesToCopy, _ := bpfProgram.OutputFiles("")
1588 for _, bpfFile := range filesToCopy {
1589 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1590 }
1591 } else {
1592 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1593 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001594 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001595 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001596 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001597 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1598 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001599 } else {
atrost6e126252020-01-27 17:01:16 +00001600 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001601 }
Roland Levillain630846d2019-06-26 12:48:34 +01001602 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001603 if ccTest, ok := child.(*cc.Module); ok {
1604 if ccTest.IsTestPerSrcAllTestsVariation() {
1605 // Multiple-output test module (where `test_per_src: true`).
1606 //
1607 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1608 // We do not add this variation to `filesInfo`, as it has no output;
1609 // however, we do add the other variations of this module as indirect
1610 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001611 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001612 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001613 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001614 af.class = nativeTest
1615 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001616 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001617 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001618 } else {
1619 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1620 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001621 case keyTag:
1622 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001623 a.private_key_file = key.private_key_file
1624 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001625 } else {
1626 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001627 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001628 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001629 case certificateTag:
1630 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001631 a.container_certificate_file = dep.Certificate.Pem
1632 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001633 } else {
1634 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1635 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001636 case android.PrebuiltDepTag:
1637 // If the prebuilt is force disabled, remember to delete the prebuilt file
1638 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001639 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001640 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1641 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001642 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001643 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001644 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001645 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001646 // We cannot use a switch statement on `depTag` here as the checked
1647 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001648 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001649 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001650 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001651 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001652 return false
1653 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001654 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1655 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07001656 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1657 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001658 // If the dependency is a stubs lib, don't include it in this APEX,
1659 // but make sure that the lib is installed on the device.
1660 // In case no APEX is having the lib, the lib is installed to the system
1661 // partition.
1662 //
1663 // Always include if we are a host-apex however since those won't have any
1664 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001665 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001666 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07001667 name := cc.ImplementationModuleName(ctx)
1668
1669 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001670 // we don't use subName(.vendor) for a "use_vendor: true" apex
1671 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07001672 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001673 }
1674 if !android.InList(name, a.requiredDeps) {
1675 a.requiredDeps = append(a.requiredDeps, name)
1676 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001677 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001678 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001679 // Don't track further
1680 return false
1681 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001682 filesInfo = append(filesInfo, af)
1683 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001684 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001685 } else if cc.IsTestPerSrcDepTag(depTag) {
1686 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001688 // Handle modules created as `test_per_src` variations of a single test module:
1689 // use the name of the generated test binary (`fileToCopy`) instead of the name
1690 // of the original test module (`depName`, shared by all `test_per_src`
1691 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001692 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001693 // these are not considered transitive dep
1694 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001695 filesInfo = append(filesInfo, af)
1696 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001697 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001698 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001699 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1700 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001701 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001702 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001703 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1704 }
Jiyong Park99644e92020-11-17 22:21:02 +09001705 } else if rust.IsDylibDepTag(depTag) {
1706 if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
1707 af := apexFileForRustLibrary(ctx, rustm)
1708 af.transitiveDep = true
1709 filesInfo = append(filesInfo, af)
1710 return true // track transitive dependencies
1711 }
Colin Cross56a83212020-09-15 18:30:11 -07001712 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
1713 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09001714 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09001715 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001716 }
1717 }
1718 }
1719 return false
1720 })
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001721 if a.private_key_file == nil {
1722 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1723 return
1724 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001725
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001726 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. Build rules are
1727 // generated by the dexpreopt singleton, and here we access build artifacts via the global
1728 // boot image config.
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001729 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00001730 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001731 dirInApex := filepath.Join("javalib", arch.String())
1732 for _, f := range files {
1733 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001734 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001735 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001736 }
1737 }
1738 }
1739
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001740 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09001741 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001742 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001743 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001744 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001745 if e, ok := encountered[dest]; !ok {
1746 encountered[dest] = f
1747 } else {
1748 // If a module is directly included and also transitively depended on
1749 // consider it as directly included.
1750 e.transitiveDep = e.transitiveDep && f.transitiveDep
1751 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001752 }
1753 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001754 var result []apexFile
1755 for _, v := range encountered {
1756 result = append(result, v)
1757 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001758 return result
1759 }
1760 filesInfo = removeDup(filesInfo)
1761
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001762 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09001763 sort.Slice(filesInfo, func(i, j int) bool {
1764 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1765 })
1766
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001767 ////////////////////////////////////////////////////////////////////////////////////////////
1768 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09001769 a.installDir = android.PathForModuleInstall(ctx, "apex")
1770 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001771
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001772 // Set suffix and primaryApexType depending on the ApexType
1773 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
1774 switch a.properties.ApexType {
1775 case imageApex:
1776 if buildFlattenedAsDefault {
1777 a.suffix = imageApexSuffix
1778 } else {
1779 a.suffix = ""
1780 a.primaryApexType = true
1781
1782 if ctx.Config().InstallExtraFlattenedApexes() {
1783 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
1784 }
1785 }
1786 case zipApex:
1787 if proptools.String(a.properties.Payload_type) == "zip" {
1788 a.suffix = ""
1789 a.primaryApexType = true
1790 } else {
1791 a.suffix = zipApexSuffix
1792 }
1793 case flattenedApex:
1794 if buildFlattenedAsDefault {
1795 a.suffix = ""
1796 a.primaryApexType = true
1797 } else {
1798 a.suffix = flattenedSuffix
1799 }
1800 }
1801
Theotime Combes4ba38c12020-06-12 12:46:59 +00001802 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
1803 case ext4FsType:
1804 a.payloadFsType = ext4
1805 case f2fsFsType:
1806 a.payloadFsType = f2fs
1807 default:
1808 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
1809 }
1810
Jiyong Park7cd10e32020-01-14 09:22:18 +09001811 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1812 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1813 // the same library in the system partition, thus effectively sharing the same libraries
1814 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1815 // in the APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001816 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() && !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001817
Jooyung Han85d61762020-06-24 23:50:26 +09001818 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
1819 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001820 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001821 a.linkToSystemLib = false
1822 }
1823
Jiyong Park9d677202020-02-19 16:29:35 +09001824 // We don't need the optimization for updatable APEXes, as it might give false signal
1825 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01001826 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09001827 a.linkToSystemLib = false
1828 }
1829
Jiyong Park638d30e2020-02-26 18:27:19 +09001830 // We also don't want the optimization for host APEXes, because it doesn't make sense.
1831 if ctx.Host() {
1832 a.linkToSystemLib = false
1833 }
1834
Jooyung Han01a3ee22019-11-02 02:52:25 +09001835 a.setCertificateAndPrivateKey(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001836
1837 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
1838
1839 ////////////////////////////////////////////////////////////////////////////////////////////
1840 // 4) generate the build rules to create the APEX. This is done in builder.go.
1841 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1842 a.buildFileContexts(ctx)
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)
Anton Hansson82d502a2020-11-11 12:33:14 +00001850 a.distFiles = a.GenerateTaggedDistFiles(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001851}
1852
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001853///////////////////////////////////////////////////////////////////////////////////////////////////
1854// Factory functions
1855//
1856
1857func newApexBundle() *apexBundle {
1858 module := &apexBundle{}
1859
1860 module.AddProperties(&module.properties)
1861 module.AddProperties(&module.targetProperties)
1862 module.AddProperties(&module.overridableProperties)
1863
1864 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1865 android.InitDefaultableModule(module)
1866 android.InitSdkAwareModule(module)
1867 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
1868 return module
1869}
1870
1871func ApexBundleFactory(testApex bool, artApex bool) android.Module {
1872 bundle := newApexBundle()
1873 bundle.testApex = testApex
1874 bundle.artApex = artApex
1875 return bundle
1876}
1877
1878// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
1879// certain compatibility checks such as apex_available are not done for apex_test.
1880func testApexBundleFactory() android.Module {
1881 bundle := newApexBundle()
1882 bundle.testApex = true
1883 return bundle
1884}
1885
1886// apex packages other modules into an APEX file which is a packaging format for system-level
1887// components like binaries, shared libraries, etc.
1888func BundleFactory() android.Module {
1889 return newApexBundle()
1890}
1891
1892type Defaults struct {
1893 android.ModuleBase
1894 android.DefaultsModuleBase
1895}
1896
1897// apex_defaults provides defaultable properties to other apex modules.
1898func defaultsFactory() android.Module {
1899 return DefaultsFactory()
1900}
1901
1902func DefaultsFactory(props ...interface{}) android.Module {
1903 module := &Defaults{}
1904
1905 module.AddProperties(props...)
1906 module.AddProperties(
1907 &apexBundleProperties{},
1908 &apexTargetBundleProperties{},
1909 &overridableProperties{},
1910 )
1911
1912 android.InitDefaultsModule(module)
1913 return module
1914}
1915
1916type OverrideApex struct {
1917 android.ModuleBase
1918 android.OverrideModuleBase
1919}
1920
1921func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1922 // All the overrides happen in the base module.
1923}
1924
1925// override_apex is used to create an apex module based on another apex module by overriding some of
1926// its properties.
1927func overrideApexFactory() android.Module {
1928 m := &OverrideApex{}
1929
1930 m.AddProperties(&overridableProperties{})
1931
1932 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1933 android.InitOverrideModule(m)
1934 return m
1935}
1936
1937///////////////////////////////////////////////////////////////////////////////////////////////////
1938// Vality check routines
1939//
1940// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
1941// certain conditions are not met.
1942//
1943// TODO(jiyong): move these checks to a separate go file.
1944
1945// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
1946// of this apexBundle.
1947func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1948 if a.testApex || a.vndkApex {
1949 return
1950 }
1951 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1952 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1953 return
1954 }
1955 // apexBundle::minSdkVersion reports its own errors.
1956 minSdkVersion := a.minSdkVersion(ctx)
1957 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
1958}
1959
1960func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
1961 ver := proptools.String(a.properties.Min_sdk_version)
1962 if ver == "" {
1963 return android.FutureApiLevel
1964 }
1965 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
1966 if err != nil {
1967 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
1968 return android.NoneApiLevel
1969 }
1970 if apiLevel.IsPreview() {
1971 // All codenames should build against "current".
1972 return android.FutureApiLevel
1973 }
1974 return apiLevel
1975}
1976
1977// Ensures that a lib providing stub isn't statically linked
1978func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1979 // Practically, we only care about regular APEXes on the device.
1980 if ctx.Host() || a.testApex || a.vndkApex {
1981 return
1982 }
1983
1984 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1985
1986 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1987 if ccm, ok := to.(*cc.Module); ok {
1988 apexName := ctx.ModuleName()
1989 fromName := ctx.OtherModuleName(from)
1990 toName := ctx.OtherModuleName(to)
1991
1992 // If `to` is not actually in the same APEX as `from` then it does not need
1993 // apex_available and neither do any of its dependencies.
1994 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1995 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1996 return false
1997 }
1998
1999 // The dynamic linker and crash_dump tool in the runtime APEX is the only
2000 // exception to this rule. It can't make the static dependencies dynamic
2001 // because it can't do the dynamic linking for itself.
2002 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
2003 return false
2004 }
2005
2006 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
2007 if isStubLibraryFromOtherApex && !externalDep {
2008 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2009 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2010 }
2011
2012 }
2013 return true
2014 })
2015}
2016
Artur Satayev8cf899a2020-04-15 17:29:42 +01002017// Enforce that Java deps of the apex are using stable SDKs to compile
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002018func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
2019 if a.Updatable() {
2020 if String(a.properties.Min_sdk_version) == "" {
2021 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2022 }
2023 a.checkJavaStableSdkVersion(ctx)
2024 }
2025}
2026
Artur Satayev8cf899a2020-04-15 17:29:42 +01002027func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002028 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2029 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002030 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2031 tag := ctx.OtherModuleDependencyTag(module)
2032 switch tag {
2033 case javaLibTag, androidAppTag:
2034 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2035 if err := m.CheckStableSdkVersion(); err != nil {
2036 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2037 }
2038 }
2039 }
2040 })
2041}
2042
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002043// Ensures that the all the dependencies are marked as available for this APEX
2044func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2045 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2046 if ctx.Host() || a.testApex || a.vndkApex {
2047 return
2048 }
2049
2050 // Because APEXes targeting other than system/system_ext partitions can't set
2051 // apex_available, we skip checks for these APEXes
2052 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2053 return
2054 }
2055
2056 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2057 // Requiring them and their transitive depencies with apex_available is not right
2058 // because they just add noise.
2059 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2060 return
2061 }
2062
2063 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2064 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2065 if externalDep {
2066 return false
2067 }
2068
2069 apexName := ctx.ModuleName()
2070 fromName := ctx.OtherModuleName(from)
2071 toName := ctx.OtherModuleName(to)
2072
2073 // If `to` is not actually in the same APEX as `from` then it does not need
2074 // apex_available and neither do any of its dependencies.
2075 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2076 // As soon as the dependency graph crosses the APEX boundary, don't go
2077 // further.
2078 return false
2079 }
2080
2081 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2082 return true
2083 }
2084 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'. Dependency path:%s",
2085 fromName, toName, ctx.GetPathString(true))
2086 // Visit this module's dependencies to check and report any issues with their availability.
2087 return true
2088 })
2089}
2090
2091var (
2092 apexAvailBaseline = makeApexAvailableBaseline()
2093 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2094)
2095
Colin Cross440e0d02020-06-11 11:32:11 -07002096func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002097 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002098 moduleName = normalizeModuleName(moduleName)
2099
Colin Cross440e0d02020-06-11 11:32:11 -07002100 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002101 return true
2102 }
2103
2104 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002105 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002106 return true
2107 }
2108
2109 return false
2110}
2111
2112func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002113 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2114 // system. Trim the prefix for the check since they are confusing
2115 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2116 if strings.HasPrefix(moduleName, "libclang_rt.") {
2117 // This module has many arch variants that depend on the product being built.
2118 // We don't want to list them all
2119 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002120 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002121 if strings.HasPrefix(moduleName, "androidx.") {
2122 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2123 moduleName = "androidx"
2124 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002125 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002126}
2127
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002128// Transform the map of apex -> modules to module -> apexes.
2129func invertApexBaseline(m map[string][]string) map[string][]string {
2130 r := make(map[string][]string)
2131 for apex, modules := range m {
2132 for _, module := range modules {
2133 r[module] = append(r[module], apex)
2134 }
2135 }
2136 return r
2137}
2138
2139// Retrieve the baseline of apexes to which the supplied module belongs.
2140func BaselineApexAvailable(moduleName string) []string {
2141 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2142}
2143
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002144// This is a map from apex to modules, which overrides the apex_available setting for that
2145// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002146// TODO(b/147364041): remove this
2147func makeApexAvailableBaseline() map[string][]string {
2148 // The "Module separator"s below are employed to minimize merge conflicts.
2149 m := make(map[string][]string)
2150 //
2151 // Module separator
2152 //
2153 m["com.android.appsearch"] = []string{
2154 "icing-java-proto-lite",
2155 "libprotobuf-java-lite",
2156 }
2157 //
2158 // Module separator
2159 //
2160 m["com.android.bluetooth.updatable"] = []string{
2161 "android.hardware.audio.common@5.0",
2162 "android.hardware.bluetooth.a2dp@1.0",
2163 "android.hardware.bluetooth.audio@2.0",
2164 "android.hardware.bluetooth@1.0",
2165 "android.hardware.bluetooth@1.1",
2166 "android.hardware.graphics.bufferqueue@1.0",
2167 "android.hardware.graphics.bufferqueue@2.0",
2168 "android.hardware.graphics.common@1.0",
2169 "android.hardware.graphics.common@1.1",
2170 "android.hardware.graphics.common@1.2",
2171 "android.hardware.media@1.0",
2172 "android.hidl.safe_union@1.0",
2173 "android.hidl.token@1.0",
2174 "android.hidl.token@1.0-utils",
2175 "avrcp-target-service",
2176 "avrcp_headers",
2177 "bluetooth-protos-lite",
2178 "bluetooth.mapsapi",
2179 "com.android.vcard",
2180 "dnsresolver_aidl_interface-V2-java",
2181 "ipmemorystore-aidl-interfaces-V5-java",
2182 "ipmemorystore-aidl-interfaces-java",
2183 "internal_include_headers",
2184 "lib-bt-packets",
2185 "lib-bt-packets-avrcp",
2186 "lib-bt-packets-base",
2187 "libFraunhoferAAC",
2188 "libaudio-a2dp-hw-utils",
2189 "libaudio-hearing-aid-hw-utils",
2190 "libbinder_headers",
2191 "libbluetooth",
2192 "libbluetooth-types",
2193 "libbluetooth-types-header",
2194 "libbluetooth_gd",
2195 "libbluetooth_headers",
2196 "libbluetooth_jni",
2197 "libbt-audio-hal-interface",
2198 "libbt-bta",
2199 "libbt-common",
2200 "libbt-hci",
2201 "libbt-platform-protos-lite",
2202 "libbt-protos-lite",
2203 "libbt-sbc-decoder",
2204 "libbt-sbc-encoder",
2205 "libbt-stack",
2206 "libbt-utils",
2207 "libbtcore",
2208 "libbtdevice",
2209 "libbte",
2210 "libbtif",
2211 "libchrome",
2212 "libevent",
2213 "libfmq",
2214 "libg722codec",
2215 "libgui_headers",
2216 "libmedia_headers",
2217 "libmodpb64",
2218 "libosi",
2219 "libstagefright_foundation_headers",
2220 "libstagefright_headers",
2221 "libstatslog",
2222 "libstatssocket",
2223 "libtinyxml2",
2224 "libudrv-uipc",
2225 "libz",
2226 "media_plugin_headers",
2227 "net-utils-services-common",
2228 "netd_aidl_interface-unstable-java",
2229 "netd_event_listener_interface-java",
2230 "netlink-client",
2231 "networkstack-client",
2232 "sap-api-java-static",
2233 "services.net",
2234 }
2235 //
2236 // Module separator
2237 //
2238 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2239 //
2240 // Module separator
2241 //
2242 m["com.android.extservices"] = []string{
2243 "error_prone_annotations",
2244 "ExtServices-core",
2245 "ExtServices",
2246 "libtextclassifier-java",
2247 "libz_current",
2248 "textclassifier-statsd",
2249 "TextClassifierNotificationLibNoManifest",
2250 "TextClassifierServiceLibNoManifest",
2251 }
2252 //
2253 // Module separator
2254 //
2255 m["com.android.neuralnetworks"] = []string{
2256 "android.hardware.neuralnetworks@1.0",
2257 "android.hardware.neuralnetworks@1.1",
2258 "android.hardware.neuralnetworks@1.2",
2259 "android.hardware.neuralnetworks@1.3",
2260 "android.hidl.allocator@1.0",
2261 "android.hidl.memory.token@1.0",
2262 "android.hidl.memory@1.0",
2263 "android.hidl.safe_union@1.0",
2264 "libarect",
2265 "libbuildversion",
2266 "libmath",
2267 "libprocpartition",
2268 "libsync",
2269 }
2270 //
2271 // Module separator
2272 //
2273 m["com.android.media"] = []string{
2274 "android.frameworks.bufferhub@1.0",
2275 "android.hardware.cas.native@1.0",
2276 "android.hardware.cas@1.0",
2277 "android.hardware.configstore-utils",
2278 "android.hardware.configstore@1.0",
2279 "android.hardware.configstore@1.1",
2280 "android.hardware.graphics.allocator@2.0",
2281 "android.hardware.graphics.allocator@3.0",
2282 "android.hardware.graphics.bufferqueue@1.0",
2283 "android.hardware.graphics.bufferqueue@2.0",
2284 "android.hardware.graphics.common@1.0",
2285 "android.hardware.graphics.common@1.1",
2286 "android.hardware.graphics.common@1.2",
2287 "android.hardware.graphics.mapper@2.0",
2288 "android.hardware.graphics.mapper@2.1",
2289 "android.hardware.graphics.mapper@3.0",
2290 "android.hardware.media.omx@1.0",
2291 "android.hardware.media@1.0",
2292 "android.hidl.allocator@1.0",
2293 "android.hidl.memory.token@1.0",
2294 "android.hidl.memory@1.0",
2295 "android.hidl.token@1.0",
2296 "android.hidl.token@1.0-utils",
2297 "bionic_libc_platform_headers",
2298 "exoplayer2-extractor",
2299 "exoplayer2-extractor-annotation-stubs",
2300 "gl_headers",
2301 "jsr305",
2302 "libEGL",
2303 "libEGL_blobCache",
2304 "libEGL_getProcAddress",
2305 "libFLAC",
2306 "libFLAC-config",
2307 "libFLAC-headers",
2308 "libGLESv2",
2309 "libaacextractor",
2310 "libamrextractor",
2311 "libarect",
2312 "libaudio_system_headers",
2313 "libaudioclient",
2314 "libaudioclient_headers",
2315 "libaudiofoundation",
2316 "libaudiofoundation_headers",
2317 "libaudiomanager",
2318 "libaudiopolicy",
2319 "libaudioutils",
2320 "libaudioutils_fixedfft",
2321 "libbinder_headers",
2322 "libbluetooth-types-header",
2323 "libbufferhub",
2324 "libbufferhub_headers",
2325 "libbufferhubqueue",
2326 "libc_malloc_debug_backtrace",
2327 "libcamera_client",
2328 "libcamera_metadata",
2329 "libdvr_headers",
2330 "libexpat",
2331 "libfifo",
2332 "libflacextractor",
2333 "libgrallocusage",
2334 "libgraphicsenv",
2335 "libgui",
2336 "libgui_headers",
2337 "libhardware_headers",
2338 "libinput",
2339 "liblzma",
2340 "libmath",
2341 "libmedia",
2342 "libmedia_codeclist",
2343 "libmedia_headers",
2344 "libmedia_helper",
2345 "libmedia_helper_headers",
2346 "libmedia_midiiowrapper",
2347 "libmedia_omx",
2348 "libmediautils",
2349 "libmidiextractor",
2350 "libmkvextractor",
2351 "libmp3extractor",
2352 "libmp4extractor",
2353 "libmpeg2extractor",
2354 "libnativebase_headers",
2355 "libnativewindow_headers",
2356 "libnblog",
2357 "liboggextractor",
2358 "libpackagelistparser",
2359 "libpdx",
2360 "libpdx_default_transport",
2361 "libpdx_headers",
2362 "libpdx_uds",
2363 "libprocinfo",
2364 "libspeexresampler",
2365 "libspeexresampler",
2366 "libstagefright_esds",
2367 "libstagefright_flacdec",
2368 "libstagefright_flacdec",
2369 "libstagefright_foundation",
2370 "libstagefright_foundation_headers",
2371 "libstagefright_foundation_without_imemory",
2372 "libstagefright_headers",
2373 "libstagefright_id3",
2374 "libstagefright_metadatautils",
2375 "libstagefright_mpeg2extractor",
2376 "libstagefright_mpeg2support",
2377 "libsync",
2378 "libui",
2379 "libui_headers",
2380 "libunwindstack",
2381 "libvibrator",
2382 "libvorbisidec",
2383 "libwavextractor",
2384 "libwebm",
2385 "media_ndk_headers",
2386 "media_plugin_headers",
2387 "updatable-media",
2388 }
2389 //
2390 // Module separator
2391 //
2392 m["com.android.media.swcodec"] = []string{
2393 "android.frameworks.bufferhub@1.0",
2394 "android.hardware.common-ndk_platform",
2395 "android.hardware.configstore-utils",
2396 "android.hardware.configstore@1.0",
2397 "android.hardware.configstore@1.1",
2398 "android.hardware.graphics.allocator@2.0",
2399 "android.hardware.graphics.allocator@3.0",
2400 "android.hardware.graphics.allocator@4.0",
2401 "android.hardware.graphics.bufferqueue@1.0",
2402 "android.hardware.graphics.bufferqueue@2.0",
2403 "android.hardware.graphics.common-ndk_platform",
2404 "android.hardware.graphics.common@1.0",
2405 "android.hardware.graphics.common@1.1",
2406 "android.hardware.graphics.common@1.2",
2407 "android.hardware.graphics.mapper@2.0",
2408 "android.hardware.graphics.mapper@2.1",
2409 "android.hardware.graphics.mapper@3.0",
2410 "android.hardware.graphics.mapper@4.0",
2411 "android.hardware.media.bufferpool@2.0",
2412 "android.hardware.media.c2@1.0",
2413 "android.hardware.media.c2@1.1",
2414 "android.hardware.media.omx@1.0",
2415 "android.hardware.media@1.0",
2416 "android.hardware.media@1.0",
2417 "android.hidl.memory.token@1.0",
2418 "android.hidl.memory@1.0",
2419 "android.hidl.safe_union@1.0",
2420 "android.hidl.token@1.0",
2421 "android.hidl.token@1.0-utils",
2422 "libEGL",
2423 "libFLAC",
2424 "libFLAC-config",
2425 "libFLAC-headers",
2426 "libFraunhoferAAC",
2427 "libLibGuiProperties",
2428 "libarect",
2429 "libaudio_system_headers",
2430 "libaudioutils",
2431 "libaudioutils",
2432 "libaudioutils_fixedfft",
2433 "libavcdec",
2434 "libavcenc",
2435 "libavservices_minijail",
2436 "libavservices_minijail",
2437 "libbinder_headers",
2438 "libbinderthreadstateutils",
2439 "libbluetooth-types-header",
2440 "libbufferhub_headers",
2441 "libcodec2",
2442 "libcodec2_headers",
2443 "libcodec2_hidl@1.0",
2444 "libcodec2_hidl@1.1",
2445 "libcodec2_internal",
2446 "libcodec2_soft_aacdec",
2447 "libcodec2_soft_aacenc",
2448 "libcodec2_soft_amrnbdec",
2449 "libcodec2_soft_amrnbenc",
2450 "libcodec2_soft_amrwbdec",
2451 "libcodec2_soft_amrwbenc",
2452 "libcodec2_soft_av1dec_gav1",
2453 "libcodec2_soft_avcdec",
2454 "libcodec2_soft_avcenc",
2455 "libcodec2_soft_common",
2456 "libcodec2_soft_flacdec",
2457 "libcodec2_soft_flacenc",
2458 "libcodec2_soft_g711alawdec",
2459 "libcodec2_soft_g711mlawdec",
2460 "libcodec2_soft_gsmdec",
2461 "libcodec2_soft_h263dec",
2462 "libcodec2_soft_h263enc",
2463 "libcodec2_soft_hevcdec",
2464 "libcodec2_soft_hevcenc",
2465 "libcodec2_soft_mp3dec",
2466 "libcodec2_soft_mpeg2dec",
2467 "libcodec2_soft_mpeg4dec",
2468 "libcodec2_soft_mpeg4enc",
2469 "libcodec2_soft_opusdec",
2470 "libcodec2_soft_opusenc",
2471 "libcodec2_soft_rawdec",
2472 "libcodec2_soft_vorbisdec",
2473 "libcodec2_soft_vp8dec",
2474 "libcodec2_soft_vp8enc",
2475 "libcodec2_soft_vp9dec",
2476 "libcodec2_soft_vp9enc",
2477 "libcodec2_vndk",
2478 "libdvr_headers",
2479 "libfmq",
2480 "libfmq",
2481 "libgav1",
2482 "libgralloctypes",
2483 "libgrallocusage",
2484 "libgraphicsenv",
2485 "libgsm",
2486 "libgui_bufferqueue_static",
2487 "libgui_headers",
2488 "libhardware",
2489 "libhardware_headers",
2490 "libhevcdec",
2491 "libhevcenc",
2492 "libion",
2493 "libjpeg",
2494 "liblzma",
2495 "libmath",
2496 "libmedia_codecserviceregistrant",
2497 "libmedia_headers",
2498 "libmpeg2dec",
2499 "libnativebase_headers",
2500 "libnativewindow_headers",
2501 "libpdx_headers",
2502 "libscudo_wrapper",
2503 "libsfplugin_ccodec_utils",
2504 "libspeexresampler",
2505 "libstagefright_amrnb_common",
2506 "libstagefright_amrnbdec",
2507 "libstagefright_amrnbenc",
2508 "libstagefright_amrwbdec",
2509 "libstagefright_amrwbenc",
2510 "libstagefright_bufferpool@2.0.1",
2511 "libstagefright_bufferqueue_helper",
2512 "libstagefright_enc_common",
2513 "libstagefright_flacdec",
2514 "libstagefright_foundation",
2515 "libstagefright_foundation_headers",
2516 "libstagefright_headers",
2517 "libstagefright_m4vh263dec",
2518 "libstagefright_m4vh263enc",
2519 "libstagefright_mp3dec",
2520 "libsync",
2521 "libui",
2522 "libui_headers",
2523 "libunwindstack",
2524 "libvorbisidec",
2525 "libvpx",
2526 "libyuv",
2527 "libyuv_static",
2528 "media_ndk_headers",
2529 "media_plugin_headers",
2530 "mediaswcodec",
2531 }
2532 //
2533 // Module separator
2534 //
2535 m["com.android.mediaprovider"] = []string{
2536 "MediaProvider",
2537 "MediaProviderGoogle",
2538 "fmtlib_ndk",
2539 "libbase_ndk",
2540 "libfuse",
2541 "libfuse_jni",
2542 }
2543 //
2544 // Module separator
2545 //
2546 m["com.android.permission"] = []string{
2547 "car-ui-lib",
2548 "iconloader",
2549 "kotlin-annotations",
2550 "kotlin-stdlib",
2551 "kotlin-stdlib-jdk7",
2552 "kotlin-stdlib-jdk8",
2553 "kotlinx-coroutines-android",
2554 "kotlinx-coroutines-android-nodeps",
2555 "kotlinx-coroutines-core",
2556 "kotlinx-coroutines-core-nodeps",
2557 "permissioncontroller-statsd",
2558 "GooglePermissionController",
2559 "PermissionController",
2560 "SettingsLibActionBarShadow",
2561 "SettingsLibAppPreference",
2562 "SettingsLibBarChartPreference",
2563 "SettingsLibLayoutPreference",
2564 "SettingsLibProgressBar",
2565 "SettingsLibSearchWidget",
2566 "SettingsLibSettingsTheme",
2567 "SettingsLibRestrictedLockUtils",
2568 "SettingsLibHelpUtils",
2569 }
2570 //
2571 // Module separator
2572 //
2573 m["com.android.runtime"] = []string{
2574 "bionic_libc_platform_headers",
2575 "libarm-optimized-routines-math",
2576 "libc_aeabi",
2577 "libc_bionic",
2578 "libc_bionic_ndk",
2579 "libc_bootstrap",
2580 "libc_common",
2581 "libc_common_shared",
2582 "libc_common_static",
2583 "libc_dns",
2584 "libc_dynamic_dispatch",
2585 "libc_fortify",
2586 "libc_freebsd",
2587 "libc_freebsd_large_stack",
2588 "libc_gdtoa",
2589 "libc_init_dynamic",
2590 "libc_init_static",
2591 "libc_jemalloc_wrapper",
2592 "libc_netbsd",
2593 "libc_nomalloc",
2594 "libc_nopthread",
2595 "libc_openbsd",
2596 "libc_openbsd_large_stack",
2597 "libc_openbsd_ndk",
2598 "libc_pthread",
2599 "libc_static_dispatch",
2600 "libc_syscalls",
2601 "libc_tzcode",
2602 "libc_unwind_static",
2603 "libdebuggerd",
2604 "libdebuggerd_common_headers",
2605 "libdebuggerd_handler_core",
2606 "libdebuggerd_handler_fallback",
2607 "libdl_static",
2608 "libjemalloc5",
2609 "liblinker_main",
2610 "liblinker_malloc",
2611 "liblz4",
2612 "liblzma",
2613 "libprocinfo",
2614 "libpropertyinfoparser",
2615 "libscudo",
2616 "libstdc++",
2617 "libsystemproperties",
2618 "libtombstoned_client_static",
2619 "libunwindstack",
2620 "libz",
2621 "libziparchive",
2622 }
2623 //
2624 // Module separator
2625 //
2626 m["com.android.tethering"] = []string{
2627 "android.hardware.tetheroffload.config-V1.0-java",
2628 "android.hardware.tetheroffload.control-V1.0-java",
2629 "android.hidl.base-V1.0-java",
2630 "libcgrouprc",
2631 "libcgrouprc_format",
2632 "libtetherutilsjni",
2633 "libvndksupport",
2634 "net-utils-framework-common",
2635 "netd_aidl_interface-V3-java",
2636 "netlink-client",
2637 "networkstack-aidl-interfaces-java",
2638 "tethering-aidl-interfaces-java",
2639 "TetheringApiCurrentLib",
2640 }
2641 //
2642 // Module separator
2643 //
2644 m["com.android.wifi"] = []string{
2645 "PlatformProperties",
2646 "android.hardware.wifi-V1.0-java",
2647 "android.hardware.wifi-V1.0-java-constants",
2648 "android.hardware.wifi-V1.1-java",
2649 "android.hardware.wifi-V1.2-java",
2650 "android.hardware.wifi-V1.3-java",
2651 "android.hardware.wifi-V1.4-java",
2652 "android.hardware.wifi.hostapd-V1.0-java",
2653 "android.hardware.wifi.hostapd-V1.1-java",
2654 "android.hardware.wifi.hostapd-V1.2-java",
2655 "android.hardware.wifi.supplicant-V1.0-java",
2656 "android.hardware.wifi.supplicant-V1.1-java",
2657 "android.hardware.wifi.supplicant-V1.2-java",
2658 "android.hardware.wifi.supplicant-V1.3-java",
2659 "android.hidl.base-V1.0-java",
2660 "android.hidl.manager-V1.0-java",
2661 "android.hidl.manager-V1.1-java",
2662 "android.hidl.manager-V1.2-java",
2663 "bouncycastle-unbundled",
2664 "dnsresolver_aidl_interface-V2-java",
2665 "error_prone_annotations",
2666 "framework-wifi-pre-jarjar",
2667 "framework-wifi-util-lib",
2668 "ipmemorystore-aidl-interfaces-V3-java",
2669 "ipmemorystore-aidl-interfaces-java",
2670 "ksoap2",
2671 "libnanohttpd",
2672 "libwifi-jni",
2673 "net-utils-services-common",
2674 "netd_aidl_interface-V2-java",
2675 "netd_aidl_interface-unstable-java",
2676 "netd_event_listener_interface-java",
2677 "netlink-client",
2678 "networkstack-client",
2679 "services.net",
2680 "wifi-lite-protos",
2681 "wifi-nano-protos",
2682 "wifi-service-pre-jarjar",
2683 "wifi-service-resources",
2684 }
2685 //
2686 // Module separator
2687 //
2688 m["com.android.sdkext"] = []string{
2689 "fmtlib_ndk",
2690 "libbase_ndk",
2691 "libprotobuf-cpp-lite-ndk",
2692 }
2693 //
2694 // Module separator
2695 //
2696 m["com.android.os.statsd"] = []string{
2697 "libstatssocket",
2698 }
2699 //
2700 // Module separator
2701 //
2702 m[android.AvailableToAnyApex] = []string{
2703 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
2704 "androidx",
2705 "androidx-constraintlayout_constraintlayout",
2706 "androidx-constraintlayout_constraintlayout-nodeps",
2707 "androidx-constraintlayout_constraintlayout-solver",
2708 "androidx-constraintlayout_constraintlayout-solver-nodeps",
2709 "com.google.android.material_material",
2710 "com.google.android.material_material-nodeps",
2711
2712 "libatomic",
2713 "libclang_rt",
2714 "libgcc_stripped",
2715 "libprofile-clang-extras",
2716 "libprofile-clang-extras_ndk",
2717 "libprofile-extras",
2718 "libprofile-extras_ndk",
2719 "libunwind_llvm",
2720 }
2721 return m
2722}
2723
2724func init() {
2725 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
2726 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
2727}
2728
2729func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
2730 rules := make([]android.Rule, 0, len(modules_packages))
2731 for module_name, module_packages := range modules_packages {
2732 permitted_packages_rule := android.NeverAllow().
2733 BootclasspathJar().
2734 With("apex_available", module_name).
2735 WithMatcher("permitted_packages", android.NotInList(module_packages)).
2736 Because("jars that are part of the " + module_name +
2737 " module may only allow these packages: " + strings.Join(module_packages, ",") +
2738 ". Please jarjar or move code around.")
2739 rules = append(rules, permitted_packages_rule)
2740 }
2741 return rules
2742}
2743
2744// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2745// Adding code to the bootclasspath in new packages will cause issues on module update.
2746func qModulesPackages() map[string][]string {
2747 return map[string][]string{
2748 "com.android.conscrypt": []string{
2749 "android.net.ssl",
2750 "com.android.org.conscrypt",
2751 },
2752 "com.android.media": []string{
2753 "android.media",
2754 },
2755 }
2756}
2757
2758// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2759// Adding code to the bootclasspath in new packages will cause issues on module update.
2760func rModulesPackages() map[string][]string {
2761 return map[string][]string{
2762 "com.android.mediaprovider": []string{
2763 "android.provider",
2764 },
2765 "com.android.permission": []string{
2766 "android.permission",
2767 "android.app.role",
2768 "com.android.permission",
2769 "com.android.role",
2770 },
2771 "com.android.sdkext": []string{
2772 "android.os.ext",
2773 },
2774 "com.android.os.statsd": []string{
2775 "android.app",
2776 "android.os",
2777 "android.util",
2778 "com.android.internal.statsd",
2779 "com.android.server.stats",
2780 },
2781 "com.android.wifi": []string{
2782 "com.android.server.wifi",
2783 "com.android.wifi.x",
2784 "android.hardware.wifi",
2785 "android.net.wifi",
2786 },
2787 "com.android.tethering": []string{
2788 "android.net",
2789 },
2790 }
2791}