blob: df639328e1de48070f6b35161f82a3dc0c422694 [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"
35 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090036)
37
Jiyong Park8e6d52f2020-11-19 14:37:47 +090038func init() {
39 android.RegisterModuleType("apex", BundleFactory)
40 android.RegisterModuleType("apex_test", testApexBundleFactory)
41 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
42 android.RegisterModuleType("apex_defaults", defaultsFactory)
43 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
44 android.RegisterModuleType("override_apex", overrideApexFactory)
45 android.RegisterModuleType("apex_set", apexSetFactory)
46
47 android.PreDepsMutators(RegisterPreDepsMutators)
48 android.PostDepsMutators(RegisterPostDepsMutators)
49}
50
51func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
52 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
53 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
54}
55
56func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
57 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
58 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
59 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
60 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
61 ctx.BottomUp("apex", apexMutator).Parallel()
62 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
63 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
64 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
65}
66
67type apexBundleProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090068 // Json manifest file describing meta info of this APEX bundle. Refer to
69 // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json"
Jiyong Park8e6d52f2020-11-19 14:37:47 +090070 Manifest *string `android:"path"`
71
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090072 // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified,
73 // a default one is automatically generated.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090074 AndroidManifest *string `android:"path"`
75
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090076 // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on
77 // device (/apex/<apex_name>). If unspecified, follows the name property.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090078 Apex_name *string
79
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090080 // Determines the file contexts file for setting the security contexts to files in this APEX
81 // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default:
82 // /system/sepolicy/apex/<module_name>_file_contexts.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090083 File_contexts *string `android:"path"`
84
85 ApexNativeDependencies
86
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090087 Multilib apexMultilibProperties
88
89 // List of java libraries that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090090 Java_libs []string
91
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090092 // List of prebuilt files that are embedded inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090093 Prebuilts []string
94
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090095 // List of BPF programs inside this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090096 Bpfs []string
97
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090098 // Name of the apex_key module that provides the private key to sign this APEX bundle.
Jiyong Park8e6d52f2020-11-19 14:37:47 +090099 Key *string
100
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900101 // Specifies the certificate and the private key to sign the zip container of this APEX. If
102 // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used
103 // as the certificate and the private key, respectively. If this is ":module", then the
104 // certificate and the private key are provided from the android_app_certificate module
105 // named "module".
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900106 Certificate *string
107
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900108 // The minimum SDK version that this APEX must support at minimum. This is usually set to
109 // the SDK version that the APEX was first introduced.
110 Min_sdk_version *string
111
112 // Whether this APEX is considered updatable or not. When set to true, this will enforce
113 // additional rules for making sure that the APEX is truly updatable. To be updatable,
114 // min_sdk_version should be set as well. This will also disable the size optimizations like
115 // symlinking to the system libs. Default is false.
116 Updatable *bool
117
118 // Whether this APEX is installable to one of the partitions like system, vendor, etc.
119 // Default: true.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900120 Installable *bool
121
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900122 // For native libraries and binaries, use the vendor variant instead of the core (platform)
123 // variant. Default is false. DO NOT use this for APEXes that are installed to the system or
124 // system_ext partition.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900125 Use_vendor *bool
126
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900127 // If set true, VNDK libs are considered as stable libs and are not included in this APEX.
128 // Should be only used in non-system apexes (e.g. vendor: true). Default is false.
129 Use_vndk_as_stable *bool
130
131 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
132 // `name#version` or `name` which is an alias for `name#current`. If left empty,
133 // `platform#current` is implied. This value affects all modules included in this APEX. In
134 // other words, they are also built with the SDKs specified here.
135 Uses_sdks []string
136
137 // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or
138 // 'both'. When set to image, contents are stored in a filesystem image inside a zip
139 // container. When set to zip, contents are stored in a zip container directly. This type is
140 // mostly for host-side debugging. When set to both, the two types are both built. Default
141 // is 'image'.
142 Payload_type *string
143
144 // The type of filesystem to use when the payload_type is 'image'. Either 'ext4' or 'f2fs'.
145 // Default 'ext4'.
146 Payload_fs_type *string
147
148 // For telling the APEX to ignore special handling for system libraries such as bionic.
149 // Default is false.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900150 Ignore_system_library_special_case *bool
151
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900152 // Whenever apex_payload.img of the APEX should include dm-verity hashtree. Should be only
153 // used in tests.
154 Test_only_no_hashtree *bool
155
156 // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only
157 // used in tests.
158 Test_only_unsigned_payload *bool
159
160 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900161
162 // List of sanitizer names that this APEX is enabled for
163 SanitizerNames []string `blueprint:"mutated"`
164
165 PreventInstall bool `blueprint:"mutated"`
166
167 HideFromMake bool `blueprint:"mutated"`
168
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900169 // Internal package method for this APEX. When payload_type is image, this can be either
170 // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip,
171 // this becomes zipApex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900172 ApexType apexPackaging `blueprint:"mutated"`
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900173}
174
175type ApexNativeDependencies struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900176 // List of native libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900177 Native_shared_libs []string
178
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900179 // List of JNI libraries that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900180 Jni_libs []string
181
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900182 // List of native executables that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900183 Binaries []string
184
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900185 // List of native tests that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900186 Tests []string
187}
188
189type apexMultilibProperties struct {
190 // Native dependencies whose compile_multilib is "first"
191 First ApexNativeDependencies
192
193 // Native dependencies whose compile_multilib is "both"
194 Both ApexNativeDependencies
195
196 // Native dependencies whose compile_multilib is "prefer32"
197 Prefer32 ApexNativeDependencies
198
199 // Native dependencies whose compile_multilib is "32"
200 Lib32 ApexNativeDependencies
201
202 // Native dependencies whose compile_multilib is "64"
203 Lib64 ApexNativeDependencies
204}
205
206type apexTargetBundleProperties struct {
207 Target struct {
208 // Multilib properties only for android.
209 Android struct {
210 Multilib apexMultilibProperties
211 }
212
213 // Multilib properties only for host.
214 Host struct {
215 Multilib apexMultilibProperties
216 }
217
218 // Multilib properties only for host linux_bionic.
219 Linux_bionic struct {
220 Multilib apexMultilibProperties
221 }
222
223 // Multilib properties only for host linux_glibc.
224 Linux_glibc struct {
225 Multilib apexMultilibProperties
226 }
227 }
228}
229
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900230// These properties can be used in override_apex to override the corresponding properties in the
231// base apex.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900232type overridableProperties struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900233 // List of APKs that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900234 Apps []string
235
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900236 // List of runtime resource overlays (RROs) that are embedded inside this APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900237 Rros []string
238
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900239 // Names of modules to be overridden. Listed modules can only be other binaries (in Make or
240 // Soong). This does not completely prevent installation of the overridden binaries, but if
241 // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will
242 // be removed from PRODUCT_PACKAGES.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900243 Overrides []string
244
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900245 // Logging parent value.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900246 Logging_parent string
247
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900248 // Apex Container package name. Override value for attribute package:name in
249 // AndroidManifest.xml
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900250 Package_name string
251
252 // A txt file containing list of files that are allowed to be included in this APEX.
253 Allowed_files *string `android:"path"`
254}
255
256type apexBundle struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900257 // Inherited structs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900258 android.ModuleBase
259 android.DefaultableModuleBase
260 android.OverridableModuleBase
261 android.SdkBase
262
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900263 // Properties
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900264 properties apexBundleProperties
265 targetProperties apexTargetBundleProperties
266 overridableProperties overridableProperties
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900267 vndkProperties apexVndkProperties // only for apex_vndk modules
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900268
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900269 ///////////////////////////////////////////////////////////////////////////////////////////
270 // Inputs
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900271
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900272 // Keys for apex_paylaod.img
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900273 public_key_file android.Path
274 private_key_file android.Path
275
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900276 // Cert/priv-key for the zip container
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900277 container_certificate_file android.Path
278 container_private_key_file android.Path
279
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900280 // Flags for special variants of APEX
281 testApex bool
282 vndkApex bool
283 artApex bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900284
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900285 // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary
286 // one gets installed to the device.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900287 primaryApexType bool
288
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900289 // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or ""
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900290 suffix string
291
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900292 // File system type of apex_payload.img
293 payloadFsType fsType
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900294
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900295 // Whether to create symlink to the system file instead of having a file inside the apex or
296 // not
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900297 linkToSystemLib bool
298
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900299 // List of files to be included in this APEX. This is filled in the first part of
300 // GenerateAndroidBuildActions.
301 filesInfo []apexFile
302
303 // List of other module names that should be installed when this APEX gets installed.
304 requiredDeps []string
305
306 ///////////////////////////////////////////////////////////////////////////////////////////
307 // Outputs (final and intermediates)
308
309 // Processed apex manifest in JSONson format (for Q)
310 manifestJsonOut android.WritablePath
311
312 // Processed apex manifest in PB format (for R+)
313 manifestPbOut android.WritablePath
314
315 // Processed file_contexts files
316 fileContexts android.WritablePath
317
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900318 // Struct holding the merged notice file paths in different formats
319 mergedNotices android.NoticeOutputs
320
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900321 // The built APEX file. This is the main product.
322 outputFile android.WritablePath
323
324 // The built APEX file in app bundle format. This file is not directly installed to the
325 // device. For an APEX, multiple app bundles are created each of which is for a specific ABI
326 // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build
327 // system) to be merged into a single app bundle file that Play accepts. See
328 // vendor/google/build/build_unbundled_mainline_module.sh for more detail.
329 bundleModuleFile android.WritablePath
330
331 // Target path to install this APEX. Usually out/target/product/<device>/<partition>/apex.
332 installDir android.InstallPath
333
334 // List of commands to create symlinks for backward compatibility. These commands will be
335 // attached as LOCAL_POST_INSTALL_CMD to apex package itself (for unflattened build) or
336 // apex_manifest (for flattened build) so that compat symlinks are always installed
337 // regardless of TARGET_FLATTEN_APEX setting.
338 compatSymlinks []string
339
340 // Text file having the list of individual files that are included in this APEX. Used for
341 // debugging purpose.
342 installedFilesFile android.WritablePath
343
344 // List of module names that this APEX is including (to be shown via *-deps-info target).
345 // Used for debugging purpose.
346 android.ApexBundleDepsInfo
347
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900348 // Optional list of lint report zip files for apexes that contain java or app modules
349 lintReports android.Paths
350
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900351 prebuiltFileToDelete string
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900352}
353
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900354// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900355type apexFileClass int
356
Jooyung Han72bd2f82019-10-23 16:46:38 +0900357const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900358 app apexFileClass = iota
359 appSet
360 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900361 goBinary
362 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900363 nativeExecutable
364 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900365 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900366 pyBinary
367 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900368)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900369
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900370// apexFile represents a file in an APEX bundle. This is created during the first half of
371// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
372// of the function, this is used to create commands that copies the files into a staging directory,
373// where they are packaged into the APEX file. This struct is also used for creating Make modules
374// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900375type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900376 // buildFile is put in the installDir inside the APEX.
377 builtFile android.Path
378 noticeFiles android.Paths
379 installDir string
380 customStem string
381 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900382
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900383 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
384 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
385 // suffix>]
386 androidMkModuleName string // becomes LOCAL_MODULE
387 class apexFileClass // becomes LOCAL_MODULE_CLASS
388 moduleDir string // becomes LOCAL_PATH
389 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
390 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
391 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
392 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900393
394 jacocoReportClassesFile android.Path // only for javalibs and apps
395 lintDepSets java.LintDepSets // only for javalibs and apps
396 certificate java.Certificate // only for apps
397 overriddenPackageName string // only for apps
398
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900399 transitiveDep bool
400 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900401
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900402 // TODO(jiyong): remove this
403 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900404}
405
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900406// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900407func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
408 ret := apexFile{
409 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900410 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900411 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900412 class: class,
413 module: module,
414 }
415 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900416 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900417 ret.moduleDir = ctx.OtherModuleDir(module)
418 ret.requiredModuleNames = module.RequiredModuleNames()
419 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
420 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900421 }
422 return ret
423}
424
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900425func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900426 return af.builtFile != nil && af.builtFile.String() != ""
427}
428
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900429// apexRelativePath returns the relative path of the given path from the install directory of this
430// apexFile.
431// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900432func (af *apexFile) apexRelativePath(path string) string {
433 return filepath.Join(af.installDir, path)
434}
435
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900436// path returns path of this apex file relative to the APEX root
437func (af *apexFile) path() string {
438 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900439}
440
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900441// stem returns the base filename of this apex file
442func (af *apexFile) stem() string {
443 if af.customStem != "" {
444 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900445 }
446 return af.builtFile.Base()
447}
448
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900449// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
450func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900451 var ret []string
452 for _, symlink := range af.symlinks {
453 ret = append(ret, af.apexRelativePath(symlink))
454 }
455 return ret
456}
457
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900458// availableToPlatform tests whether this apexFile is from a module that can be installed to the
459// platform.
460func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900461 if af.module == nil {
462 return false
463 }
464 if am, ok := af.module.(android.ApexModule); ok {
465 return am.AvailableFor(android.AvailableToPlatform)
466 }
467 return false
468}
469
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900470////////////////////////////////////////////////////////////////////////////////////////////////////
471// Mutators
472//
473// Brief description about mutators for APEX. The following three mutators are the most important
474// ones.
475//
476// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
477// to the (direct) dependencies of this APEX bundle.
478//
479// 2) apexDepsMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
480// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
481// modules are marked as being included in the APEX via BuildForApex().
482//
483// 3) apexMutator: this is a post-deps mutator that runs after apexDepsMutator. For each module that
484// are marked by the apexDepsMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900485
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900486type dependencyTag struct {
487 blueprint.BaseDependencyTag
488 name string
489
490 // Determines if the dependent will be part of the APEX payload. Can be false for the
491 // dependencies to the signing key module, etc.
492 payload bool
493}
494
495var (
496 androidAppTag = dependencyTag{name: "androidApp", payload: true}
497 bpfTag = dependencyTag{name: "bpf", payload: true}
498 certificateTag = dependencyTag{name: "certificate"}
499 executableTag = dependencyTag{name: "executable", payload: true}
500 javaLibTag = dependencyTag{name: "javaLib", payload: true}
501 jniLibTag = dependencyTag{name: "jniLib", payload: true}
502 keyTag = dependencyTag{name: "key"}
503 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
504 rroTag = dependencyTag{name: "rro", payload: true}
505 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
506 testForTag = dependencyTag{name: "test for"}
507 testTag = dependencyTag{name: "test", payload: true}
508)
509
510// TODO(jiyong): shorten this function signature
511func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900512 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900513 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900514
515 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900516 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900517 libVariations = append(libVariations,
518 blueprint.Variation{Mutator: "image", Variation: imageVariation},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900519 blueprint.Variation{Mutator: "version", Variation: ""}, // "" is the non-stub variant
520 )
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900521 }
522
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900523 // Use *FarVariation* to be able to depend on modules having conflicting variations with
524 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
525 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900526 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900527 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900528 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
529 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900530}
531
532func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900533 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900534 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
535 } else {
536 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
537 if ctx.Os().Bionic() {
538 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
539 } else {
540 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
541 }
542 }
543}
544
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900545// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
546// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
547func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
548 deviceConfig := ctx.DeviceConfig()
549 if a.vndkApex {
550 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900551 }
552
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900553 var prefix string
554 var vndkVersion string
555 if deviceConfig.VndkVersion() != "" {
556 if proptools.Bool(a.properties.Use_vendor) {
557 prefix = cc.VendorVariationPrefix
558 vndkVersion = deviceConfig.PlatformVndkVersion()
559 } else if a.SocSpecific() || a.DeviceSpecific() {
560 prefix = cc.VendorVariationPrefix
561 vndkVersion = deviceConfig.VndkVersion()
562 } else if a.ProductSpecific() {
563 prefix = cc.ProductVariationPrefix
564 vndkVersion = deviceConfig.ProductVndkVersion()
565 }
566 }
567 if vndkVersion == "current" {
568 vndkVersion = deviceConfig.PlatformVndkVersion()
569 }
570 if vndkVersion != "" {
571 return prefix + vndkVersion
572 }
573
574 return android.CoreVariation // The usual case
575}
576
577func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
578 // TODO(jiyong): move this kind of checks to GenerateAndroidBuildActions?
579 checkUseVendorProperty(ctx, a)
580
581 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
582 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
583 // each target os/architectures, appropriate dependencies are selected by their
584 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900585 targets := ctx.MultiTargets()
586 config := ctx.DeviceConfig()
587 imageVariation := a.getImageVariation(ctx)
588
589 a.combineProperties(ctx)
590
591 has32BitTarget := false
592 for _, target := range targets {
593 if target.Arch.ArchType.Multilib == "lib32" {
594 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000595 }
596 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900597 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900598 // Don't include artifacts for the host cross targets because there is no way for us
599 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900600 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900601 continue
602 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000603
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900604 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000605
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900606 // Add native modules targeting both ABIs. When multilib.* is omitted for
607 // native_shared_libs/jni_libs/tests, it implies multilib.both
608 depsList = append(depsList, a.properties.Multilib.Both)
609 depsList = append(depsList, ApexNativeDependencies{
610 Native_shared_libs: a.properties.Native_shared_libs,
611 Tests: a.properties.Tests,
612 Jni_libs: a.properties.Jni_libs,
613 Binaries: nil,
614 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900615
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900616 // Add native modules targeting the first ABI When multilib.* is omitted for
617 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900618 isPrimaryAbi := i == 0
619 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900620 depsList = append(depsList, a.properties.Multilib.First)
621 depsList = append(depsList, ApexNativeDependencies{
622 Native_shared_libs: nil,
623 Tests: nil,
624 Jni_libs: nil,
625 Binaries: a.properties.Binaries,
626 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900627 }
628
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900629 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900630 switch target.Arch.ArchType.Multilib {
631 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900632 depsList = append(depsList, a.properties.Multilib.Lib32)
633 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900634 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900635 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900636 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900637 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900638 }
639 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900640
641 for _, d := range depsList {
642 addDependenciesForNativeModules(ctx, d, target, imageVariation)
643 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900644 }
645
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900646 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
647 // regardless of the TARGET_PREFER_* setting. See b/144532908
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900648 archForPrebuiltEtc := config.Arches()[0]
649 for _, arch := range config.Arches() {
650 // Prefer 64-bit arch if there is any
651 if arch.ArchType.Multilib == "lib64" {
652 archForPrebuiltEtc = arch
653 break
654 }
655 }
656 ctx.AddFarVariationDependencies([]blueprint.Variation{
657 {Mutator: "os", Variation: ctx.Os().String()},
658 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
659 }, prebuiltTag, a.properties.Prebuilts...)
660
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900661 // Common-arch dependencies come next
662 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
663 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
664 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900665
666 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
667 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900668 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900669 }
670
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900671 // Dependencies for signing
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900672 if String(a.properties.Key) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900673 ctx.PropertyErrorf("key", "missing")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900674 return
675 }
676 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
677
678 cert := android.SrcIsModule(a.getCertString(ctx))
679 if cert != "" {
680 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900681 // empty cert is not an error. Cert and private keys will be directly found under
682 // PRODUCT_DEFAULT_DEV_CERTIFICATE
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900683 }
684
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900685 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
686 // This field currently isn't used.
687 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900688 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
689 if len(a.properties.Uses_sdks) > 0 {
690 sdkRefs := []android.SdkRef{}
691 for _, str := range a.properties.Uses_sdks {
692 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
693 sdkRefs = append(sdkRefs, parsed)
694 }
695 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100696 }
697}
698
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900699// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900700func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
701 if a.overridableProperties.Allowed_files != nil {
702 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100703 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900704
705 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
706 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
707 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100708}
709
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900710type ApexBundleInfo struct {
711 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100712}
713
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900714var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900715
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900716// apexDepsMutator is responsible for collecting modules that need to have apex variants. They are
717// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
718// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
719// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
720// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900721func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900722 if !mctx.Module().Enabled() {
723 return
724 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900725
Jooyung Han698dd9f2020-07-22 15:17:19 +0900726 a, ok := mctx.Module().(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900727 if !ok {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900728 return
729 }
Jooyung Handf78e212020-07-22 15:54:47 +0900730
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900731 // The VNDK APEX is special. For the APEX, the membership is described in a very different
732 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
733 // libraries are self-identified by their vndk.enabled properties. There is no need to run
734 // this mutator for the APEX as nothing will be collected. So, let's return fast.
735 if a.vndkApex {
736 return
737 }
738
739 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
740 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
741 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
742 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
743 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900744 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
745 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
746 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
747 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
748 return
749 }
750
Colin Cross56a83212020-09-15 18:30:11 -0700751 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900752 am, ok := child.(android.ApexModule)
753 if !ok || !am.CanHaveApexVariants() {
754 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900755 }
Paul Duffina37eca22020-07-22 13:00:54 +0100756 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900757 return false
758 }
Jooyung Handf78e212020-07-22 15:54:47 +0900759 if excludeVndkLibs {
760 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
761 return false
762 }
763 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900764 // By default, all the transitive dependencies are collected, unless filtered out
765 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700766 return true
767 }
768
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900769 // Records whether a certain module is included in this apexBundle via direct dependency or
770 // inndirect dependency.
771 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700772 mctx.WalkDeps(func(child, parent android.Module) bool {
773 if !continueApexDepsWalk(child, parent) {
774 return false
775 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900776 // If the parent is apexBundle, this child is directly depended.
777 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900778 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700779 contents[depName] = contents[depName].Add(directDep)
780 return true
781 })
782
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900783 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900784 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700785 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
786 Contents: apexContents,
787 })
788
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900789 // This is the main part of this mutator. Mark the collected dependencies that they need to
790 // be built for this apexBundle.
Colin Cross56a83212020-09-15 18:30:11 -0700791 apexInfo := android.ApexInfo{
792 ApexVariationName: mctx.ModuleName(),
793 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
794 RequiredSdks: a.RequiredSdks(),
795 Updatable: a.Updatable(),
796 InApexes: []string{mctx.ModuleName()},
797 ApexContents: []*android.ApexContents{apexContents},
798 }
Colin Cross56a83212020-09-15 18:30:11 -0700799 mctx.WalkDeps(func(child, parent android.Module) bool {
800 if !continueApexDepsWalk(child, parent) {
801 return false
802 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900803 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900804 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900805 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900806}
807
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900808// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
809// unique apex variations for this module. See android/apex.go for more about unique apex variant.
810// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700811func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
812 if !mctx.Module().Enabled() {
813 return
814 }
815 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700816 android.UpdateUniqueApexVariationsForDeps(mctx, am)
817 }
818}
819
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900820// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
821// the apex in order to retrieve its contents later.
822// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700823func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
824 if !mctx.Module().Enabled() {
825 return
826 }
Colin Cross56a83212020-09-15 18:30:11 -0700827 if am, ok := mctx.Module().(android.ApexModule); ok {
828 if testFor := am.TestFor(); len(testFor) > 0 {
829 mctx.AddFarVariationDependencies([]blueprint.Variation{
830 {Mutator: "os", Variation: am.Target().OsVariation()},
831 {"arch", "common"},
832 }, testForTag, testFor...)
833 }
834 }
835}
836
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900837// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700838func apexTestForMutator(mctx android.BottomUpMutatorContext) {
839 if !mctx.Module().Enabled() {
840 return
841 }
Colin Cross56a83212020-09-15 18:30:11 -0700842 if _, ok := mctx.Module().(android.ApexModule); ok {
843 var contents []*android.ApexContents
844 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
845 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
846 contents = append(contents, abInfo.Contents)
847 }
848 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
849 ApexContents: contents,
850 })
Colin Crossaede88c2020-08-11 12:17:01 -0700851 }
852}
853
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900854// markPlatformAvailability marks whether or not a module can be available to platform. A module
855// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
856// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
857// be) available to platform
858// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +0900859func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
860 // Host and recovery are not considered as platform
861 if mctx.Host() || mctx.Module().InstallInRecovery() {
862 return
863 }
864
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900865 am, ok := mctx.Module().(android.ApexModule)
866 if !ok {
867 return
868 }
Jiyong Park89e850a2020-04-07 16:37:39 +0900869
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900870 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +0900871
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900872 // If any of the dep is not available to platform, this module is also considered as being
873 // not available to platform even if it has "//apex_available:platform"
874 mctx.VisitDirectDeps(func(child android.Module) {
875 if !am.DepIsInSameApex(mctx, child) {
876 // if the dependency crosses apex boundary, don't consider it
877 return
Jiyong Park89e850a2020-04-07 16:37:39 +0900878 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900879 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
880 availableToPlatform = false
881 // TODO(b/154889534) trigger an error when 'am' has
882 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +0900883 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900884 })
Jiyong Park89e850a2020-04-07 16:37:39 +0900885
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900886 // Exception 1: stub libraries and native bridge libraries are always available to platform
887 if cc, ok := mctx.Module().(*cc.Module); ok &&
888 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
889 availableToPlatform = true
890 }
891
892 // Exception 2: bootstrap bionic libraries are also always available to platform
893 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
894 availableToPlatform = true
895 }
896
897 if !availableToPlatform {
898 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900899 }
900}
901
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900902// apexMutator visits each module and creates apex variations if the module was marked in the
903// previous run of apexDepsMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900904func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900905 if !mctx.Module().Enabled() {
906 return
907 }
Colin Cross56a83212020-09-15 18:30:11 -0700908
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900909 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900910 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700911 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900912 return
913 }
914
915 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
916 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
917 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900918 apexBundleName := mctx.ModuleName()
919 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900920 } else if o, ok := mctx.Module().(*OverrideApex); ok {
921 apexBundleName := o.GetOverriddenModuleName()
922 if apexBundleName == "" {
923 mctx.ModuleErrorf("base property is not set")
924 return
925 }
926 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900927 }
928}
Sundong Ahne9b55722019-09-06 17:37:42 +0900929
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900930// See android.UpdateDirectlyInAnyApex
931// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700932func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
933 if !mctx.Module().Enabled() {
934 return
935 }
936 if am, ok := mctx.Module().(android.ApexModule); ok {
937 android.UpdateDirectlyInAnyApex(mctx, am)
938 }
939}
940
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900941// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900942type apexPackaging int
943
944const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900945 // imageApex is a packaging method where contents are included in a filesystem image which
946 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900947 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900948
949 // zipApex is a packaging method where contents are directly included in the zip container.
950 // This is used for host-side testing - because the contents are easily accessible by
951 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900952 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900953
954 // flattendApex is a packaging method where contents are not included in the APEX file, but
955 // installed to /apex/<apexname> directory on the device. This packaging method is used for
956 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900957 flattenedApex
958)
959
960const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900961 // File extensions of an APEX for different packaging methods
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900962 imageApexSuffix = ".apex"
963 zipApexSuffix = ".zipapex"
964 flattenedSuffix = ".flattened"
965
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900966 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900967 imageApexType = "image"
968 zipApexType = "zip"
969 flattenedApexType = "flattened"
970
971 ext4FsType = "ext4"
972 f2fsFsType = "f2fs"
973)
974
975// The suffix for the output "file", not the module
976func (a apexPackaging) suffix() string {
977 switch a {
978 case imageApex:
979 return imageApexSuffix
980 case zipApex:
981 return zipApexSuffix
982 default:
983 panic(fmt.Errorf("unknown APEX type %d", a))
984 }
985}
986
987func (a apexPackaging) name() string {
988 switch a {
989 case imageApex:
990 return imageApexType
991 case zipApex:
992 return zipApexType
993 default:
994 panic(fmt.Errorf("unknown APEX type %d", a))
995 }
996}
997
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900998// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
999// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001000func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001001 if !mctx.Module().Enabled() {
1002 return
1003 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001004 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001005 var variants []string
1006 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1007 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001008 // This is the normal case. Note that both image and flattend APEXes are
1009 // created. The image type is installed to the system partition, while the
1010 // flattened APEX is (optionally) installed to the system_ext partition.
1011 // This is mostly for GSI which has to support wide range of devices. If GSI
1012 // is installed on a newer (APEX-capable) device, the image APEX in the
1013 // system will be used. However, if the same GSI is installed on an old
1014 // device which can't support image APEX, the flattened APEX in the
1015 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001016 variants = append(variants, imageApexType, flattenedApexType)
1017 case "zip":
1018 variants = append(variants, zipApexType)
1019 case "both":
1020 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1021 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001022 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001023 return
1024 }
1025
1026 modules := mctx.CreateLocalVariations(variants...)
1027
1028 for i, v := range variants {
1029 switch v {
1030 case imageApexType:
1031 modules[i].(*apexBundle).properties.ApexType = imageApex
1032 case zipApexType:
1033 modules[i].(*apexBundle).properties.ApexType = zipApex
1034 case flattenedApexType:
1035 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001036 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001037 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001038 modules[i].(*apexBundle).MakeAsSystemExt()
1039 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001040 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001041 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001042 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001043 // payload_type is forcibly overridden to "image"
1044 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001045 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001046 }
1047}
1048
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001049// checkUseVendorProperty checks if the use of `use_vendor` property is allowed for the given APEX.
1050// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1051// which may cause compatibility issues. (e.g. libbinder) Even though libbinder restricts its
1052// availability via 'apex_available' property and relies on yet another macro
1053// __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules to avoid
1054// similar problems.
1055func checkUseVendorProperty(ctx android.BottomUpMutatorContext, a *apexBundle) {
1056 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
1057 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1058 }
1059}
1060
Jooyung Handc782442019-11-01 03:14:38 +09001061var (
Colin Cross440e0d02020-06-11 11:32:11 -07001062 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +09001063)
1064
Colin Cross440e0d02020-06-11 11:32:11 -07001065func useVendorAllowList(config android.Config) []string {
1066 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +09001067 return []string{
1068 // swcodec uses "vendor" variants for smaller size
1069 "com.android.media.swcodec",
1070 "test_com.android.media.swcodec",
1071 }
1072 }).([]string)
1073}
1074
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001075// setUseVendorAllowListForTest overrides useVendorAllowList and must be called before the first
1076// call to useVendorAllowList()
Colin Cross440e0d02020-06-11 11:32:11 -07001077func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1078 config.Once(useVendorAllowListKey, func() interface{} {
1079 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001080 })
1081}
1082
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001083var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001084
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001085// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001086func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1087 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001088 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001089 return true
1090}
1091
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001092var _ android.OutputFileProducer = (*apexBundle)(nil)
1093
1094// Implements android.OutputFileProducer
1095func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1096 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001097 case "", android.DefaultDistTag:
1098 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001099 return android.Paths{a.outputFile}, nil
1100 default:
1101 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1102 }
1103}
1104
1105var _ cc.Coverage = (*apexBundle)(nil)
1106
1107// Implements cc.Coverage
1108func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1109 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1110}
1111
1112// Implements cc.Coverage
1113func (a *apexBundle) PreventInstall() {
1114 a.properties.PreventInstall = true
1115}
1116
1117// Implements cc.Coverage
1118func (a *apexBundle) HideFromMake() {
1119 a.properties.HideFromMake = true
1120}
1121
1122// Implements cc.Coverage
1123func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1124 a.properties.IsCoverageVariant = coverage
1125}
1126
1127// Implements cc.Coverage
1128func (a *apexBundle) EnableCoverageIfNeeded() {}
1129
1130var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1131
1132// Implements android.ApexBudleDepsInfoIntf
1133func (a *apexBundle) Updatable() bool {
1134 return proptools.Bool(a.properties.Updatable)
1135}
1136
1137// getCertString returns the name of the cert that should be used to sign this APEX. This is
1138// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001139func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001140 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001141 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1142 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1143 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001144 if a.vndkApex {
1145 moduleName = vndkApexName
1146 }
1147 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001148 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001149 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001150 }
1151 return String(a.properties.Certificate)
1152}
1153
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001154// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001155func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001156 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001157}
1158
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001159// See the test_only_no_hashtree property
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001160func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1161 return proptools.Bool(a.properties.Test_only_no_hashtree)
1162}
1163
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001164// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001165func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1166 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1167}
1168
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001169// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1170// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1171// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001172
Jiyong Parkf97782b2019-02-13 20:28:58 +09001173func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1174 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1175 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1176 }
1177}
1178
Jiyong Park388ef3f2019-01-28 19:47:32 +09001179func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001180 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1181 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001182 }
1183
1184 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001185 globalSanitizerNames := []string{}
1186 if a.Host() {
1187 globalSanitizerNames = ctx.Config().SanitizeHost()
1188 } else {
1189 arches := ctx.Config().SanitizeDeviceArch()
1190 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1191 globalSanitizerNames = ctx.Config().SanitizeDevice()
1192 }
1193 }
1194 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001195}
1196
Jooyung Han8ce8db92020-05-15 19:05:05 +09001197func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001198 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1199 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001200 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001201 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001202 for _, target := range ctx.MultiTargets() {
1203 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001204 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1205 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1206 Tests: nil,
1207 Jni_libs: nil,
1208 Binaries: nil,
1209 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001210 break
1211 }
1212 }
1213 }
1214}
1215
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001216// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1217// returned apexFile saves information about the Soong module that will be used for creating the
1218// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001219func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001220 // Decide the APEX-local directory by the multilib of the library In the future, we may
1221 // query this to the module.
1222 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001223 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001224 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001225 case "lib32":
1226 dirInApex = "lib"
1227 case "lib64":
1228 dirInApex = "lib64"
1229 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001230 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001231 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001232 }
Jooyung Han35155c42020-02-06 17:33:20 +09001233 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001234 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001235 // Special case for Bionic libs and other libs installed with them. This is to
1236 // prevent those libs from being included in the search path
1237 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1238 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1239 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1240 // will be loaded into the default linker namespace (aka "platform" namespace). If
1241 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1242 // be loaded again into the runtime linker namespace, which will result in double
1243 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001244 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001245 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001246
Jiyong Parkf653b052019-11-18 15:39:01 +09001247 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001248 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1249 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001250}
1251
Jiyong Park1833cef2019-12-13 13:28:36 +09001252func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001253 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001254 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001255 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001256 }
Jooyung Han35155c42020-02-06 17:33:20 +09001257 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001258 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001259 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1260 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001261 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001262 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001263 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001264}
1265
Jiyong Park1833cef2019-12-13 13:28:36 +09001266func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001267 dirInApex := "bin"
1268 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001269 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001270}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001271
Jiyong Park1833cef2019-12-13 13:28:36 +09001272func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001273 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001274 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1275 if err != nil {
1276 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001277 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001278 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001279 fileToCopy := android.PathForOutput(ctx, s)
1280 // NB: Since go binaries are static we don't need the module for anything here, which is
1281 // good since the go tool is a blueprint.Module not an android.Module like we would
1282 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001283 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001284}
1285
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001286func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001287 dirInApex := filepath.Join("bin", sh.SubDir())
1288 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001289 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001290 af.symlinks = sh.Symlinks()
1291 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001292}
1293
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001294func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001295 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001296 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001297 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001298}
1299
atrost6e126252020-01-27 17:01:16 +00001300func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1301 dirInApex := filepath.Join("etc", config.SubDir())
1302 fileToCopy := config.CompatConfig()
1303 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1304}
1305
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001306// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1307// way.
1308type javaModule interface {
1309 android.Module
1310 BaseModuleName() string
1311 DexJarBuildPath() android.Path
1312 JacocoReportClassesFile() android.Path
1313 LintDepSets() java.LintDepSets
1314 Stem() string
1315}
1316
1317var _ javaModule = (*java.Library)(nil)
1318var _ javaModule = (*java.SdkLibrary)(nil)
1319var _ javaModule = (*java.DexImport)(nil)
1320var _ javaModule = (*java.SdkLibraryImport)(nil)
1321
1322func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
1323 dirInApex := "javalib"
1324 fileToCopy := module.DexJarBuildPath()
1325 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1326 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1327 af.lintDepSets = module.LintDepSets()
1328 af.customStem = module.Stem() + ".jar"
1329 return af
1330}
1331
1332// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1333// the same way.
1334type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001335 android.Module
1336 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001337 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001338 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001339 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001340 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001341 BaseModuleName() string
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001342}
1343
1344var _ androidApp = (*java.AndroidApp)(nil)
1345var _ androidApp = (*java.AndroidAppImport)(nil)
1346
1347func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001348 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001349 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001350 appDir = "priv-app"
1351 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001352 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001353 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001354 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001355 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001356 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001357
1358 if app, ok := aapp.(interface {
1359 OverriddenManifestPackageName() string
1360 }); ok {
1361 af.overriddenPackageName = app.OverriddenManifestPackageName()
1362 }
Jiyong Park618922e2020-01-08 13:35:43 +09001363 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001364}
1365
Jiyong Park69aeba92020-04-24 21:16:36 +09001366func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1367 rroDir := "overlay"
1368 dirInApex := filepath.Join(rroDir, rro.Theme())
1369 fileToCopy := rro.OutputFile()
1370 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1371 af.certificate = rro.Certificate()
1372
1373 if a, ok := rro.(interface {
1374 OverriddenManifestPackageName() string
1375 }); ok {
1376 af.overriddenPackageName = a.OverriddenManifestPackageName()
1377 }
1378 return af
1379}
1380
markchien2f59ec92020-09-02 16:23:38 +08001381func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1382 dirInApex := filepath.Join("etc", "bpf")
1383 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1384}
1385
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001386// WalyPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
1387// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1388// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1389// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001390func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001391 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001392 am, ok := child.(android.ApexModule)
1393 if !ok || !am.CanHaveApexVariants() {
1394 return false
1395 }
1396
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001397 // Filter-out unwanted depedendencies
1398 depTag := ctx.OtherModuleDependencyTag(child)
1399 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1400 return false
1401 }
1402 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001403 return false
1404 }
1405
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001406 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1407 externalDep := !android.InList(ctx.ModuleName(), ai.InApexes)
Jiyong Park0f80c182020-01-31 02:49:53 +09001408
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001409 // Visit actually
1410 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001411 })
1412}
1413
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001414// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1415type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001416
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001417const (
1418 ext4 fsType = iota
1419 f2fs
1420)
Artur Satayev849f8442020-04-28 14:57:42 +01001421
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001422func (f fsType) string() string {
1423 switch f {
1424 case ext4:
1425 return ext4FsType
1426 case f2fs:
1427 return f2fsFsType
1428 default:
1429 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001430 }
1431}
1432
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001433// Creates build rules for an APEX. It consists of the following major steps:
1434//
1435// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1436// 2) traverse the dependency tree to collect apexFile structs from them.
1437// 3) some fields in apexBundle struct are configured
1438// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001439func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001440 ////////////////////////////////////////////////////////////////////////////////////////////
1441 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001442 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001443 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001444 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001445 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001446 if len(a.properties.Tests) > 0 && !a.testApex {
1447 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1448 return
1449 }
Jiyong Park678c8812020-02-07 17:25:49 +09001450
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001451 ////////////////////////////////////////////////////////////////////////////////////////////
1452 // 2) traverse the dependency tree to collect apexFile structs from them.
1453
1454 // all the files that will be included in this APEX
1455 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001456
Jooyung Hane1633032019-08-01 17:41:43 +09001457 // native lib dependencies
1458 var provideNativeLibs []string
1459 var requireNativeLibs []string
1460
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001461 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1462
1463 // TODO(jiyong): do this using WalkPayloadDeps
1464 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001465 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001466 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001467 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1468 return false
1469 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001470 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001471 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001472 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001473 case sharedLibTag, jniLibTag:
1474 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001475 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001476 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1477 fi.isJniLib = isJniLib
1478 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001479 // Collect the list of stub-providing libs except:
1480 // - VNDK libs are only for vendors
1481 // - bootstrap bionic libs are treated as provided by system
1482 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001483 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001484 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001485 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001486 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001487 propertyName := "native_shared_libs"
1488 if isJniLib {
1489 propertyName = "jni_libs"
1490 }
1491 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001492 }
1493 case executableTag:
1494 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001495 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001496 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001497 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001498 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001499 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001500 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001501 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001502 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001503 } else {
Alex Light778127a2019-02-27 14:19:50 -08001504 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001505 }
1506 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001507 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01001508 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001509 af := apexFileForJavaModule(ctx, child.(javaModule))
1510 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001511 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1512 return false
1513 }
1514 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001515 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001516 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001517 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001518 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001519 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001520 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001521 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001522 return true // track transitive dependencies
1523 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001524 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001525 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001526 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001527 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1528 appDir := "app"
1529 if ap.Privileged() {
1530 appDir = "priv-app"
1531 }
Yo Chiange8128052020-07-23 20:09:18 +08001532 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001533 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1534 af.certificate = java.PresignedCertificate
1535 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001536 } else {
1537 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1538 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001539 case rroTag:
1540 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1541 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1542 } else {
1543 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1544 }
markchien2f59ec92020-09-02 16:23:38 +08001545 case bpfTag:
1546 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1547 filesToCopy, _ := bpfProgram.OutputFiles("")
1548 for _, bpfFile := range filesToCopy {
1549 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1550 }
1551 } else {
1552 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1553 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001554 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001555 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001556 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001557 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1558 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001559 } else {
atrost6e126252020-01-27 17:01:16 +00001560 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001561 }
Roland Levillain630846d2019-06-26 12:48:34 +01001562 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001563 if ccTest, ok := child.(*cc.Module); ok {
1564 if ccTest.IsTestPerSrcAllTestsVariation() {
1565 // Multiple-output test module (where `test_per_src: true`).
1566 //
1567 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1568 // We do not add this variation to `filesInfo`, as it has no output;
1569 // however, we do add the other variations of this module as indirect
1570 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001571 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001572 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001573 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001574 af.class = nativeTest
1575 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001576 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001577 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001578 } else {
1579 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1580 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001581 case keyTag:
1582 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001583 a.private_key_file = key.private_key_file
1584 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001585 } else {
1586 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001587 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001588 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001589 case certificateTag:
1590 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001591 a.container_certificate_file = dep.Certificate.Pem
1592 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001593 } else {
1594 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1595 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001596 case android.PrebuiltDepTag:
1597 // If the prebuilt is force disabled, remember to delete the prebuilt file
1598 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001599 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001600 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1601 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001602 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001603 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001604 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001605 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001606 // We cannot use a switch statement on `depTag` here as the checked
1607 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001608 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001609 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001610 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001611 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001612 return false
1613 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001614 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1615 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07001616 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1617 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001618 // If the dependency is a stubs lib, don't include it in this APEX,
1619 // but make sure that the lib is installed on the device.
1620 // In case no APEX is having the lib, the lib is installed to the system
1621 // partition.
1622 //
1623 // Always include if we are a host-apex however since those won't have any
1624 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001625 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001626 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07001627 name := cc.ImplementationModuleName(ctx)
1628
1629 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001630 // we don't use subName(.vendor) for a "use_vendor: true" apex
1631 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07001632 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001633 }
1634 if !android.InList(name, a.requiredDeps) {
1635 a.requiredDeps = append(a.requiredDeps, name)
1636 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001637 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001638 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001639 // Don't track further
1640 return false
1641 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001642 filesInfo = append(filesInfo, af)
1643 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001644 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001645 } else if cc.IsTestPerSrcDepTag(depTag) {
1646 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001647 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001648 // Handle modules created as `test_per_src` variations of a single test module:
1649 // use the name of the generated test binary (`fileToCopy`) instead of the name
1650 // of the original test module (`depName`, shared by all `test_per_src`
1651 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001652 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001653 // these are not considered transitive dep
1654 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001655 filesInfo = append(filesInfo, af)
1656 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001657 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001658 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001659 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1660 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001661 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001662 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001663 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1664 }
Colin Cross56a83212020-09-15 18:30:11 -07001665 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
1666 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09001667 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09001668 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001669 }
1670 }
1671 }
1672 return false
1673 })
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001674 if a.private_key_file == nil {
1675 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1676 return
1677 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001678
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001679 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. Build rules are
1680 // generated by the dexpreopt singleton, and here we access build artifacts via the global
1681 // boot image config.
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001682 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00001683 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001684 dirInApex := filepath.Join("javalib", arch.String())
1685 for _, f := range files {
1686 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001689 }
1690 }
1691 }
1692
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001693 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09001694 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001695 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001696 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001697 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001698 if e, ok := encountered[dest]; !ok {
1699 encountered[dest] = f
1700 } else {
1701 // If a module is directly included and also transitively depended on
1702 // consider it as directly included.
1703 e.transitiveDep = e.transitiveDep && f.transitiveDep
1704 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001705 }
1706 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001707 var result []apexFile
1708 for _, v := range encountered {
1709 result = append(result, v)
1710 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001711 return result
1712 }
1713 filesInfo = removeDup(filesInfo)
1714
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001715 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09001716 sort.Slice(filesInfo, func(i, j int) bool {
1717 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1718 })
1719
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001720 ////////////////////////////////////////////////////////////////////////////////////////////
1721 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09001722 a.installDir = android.PathForModuleInstall(ctx, "apex")
1723 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001724
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001725 // Set suffix and primaryApexType depending on the ApexType
1726 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
1727 switch a.properties.ApexType {
1728 case imageApex:
1729 if buildFlattenedAsDefault {
1730 a.suffix = imageApexSuffix
1731 } else {
1732 a.suffix = ""
1733 a.primaryApexType = true
1734
1735 if ctx.Config().InstallExtraFlattenedApexes() {
1736 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
1737 }
1738 }
1739 case zipApex:
1740 if proptools.String(a.properties.Payload_type) == "zip" {
1741 a.suffix = ""
1742 a.primaryApexType = true
1743 } else {
1744 a.suffix = zipApexSuffix
1745 }
1746 case flattenedApex:
1747 if buildFlattenedAsDefault {
1748 a.suffix = ""
1749 a.primaryApexType = true
1750 } else {
1751 a.suffix = flattenedSuffix
1752 }
1753 }
1754
Theotime Combes4ba38c12020-06-12 12:46:59 +00001755 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
1756 case ext4FsType:
1757 a.payloadFsType = ext4
1758 case f2fsFsType:
1759 a.payloadFsType = f2fs
1760 default:
1761 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
1762 }
1763
Jiyong Park7cd10e32020-01-14 09:22:18 +09001764 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1765 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1766 // the same library in the system partition, thus effectively sharing the same libraries
1767 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1768 // in the APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001769 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() && !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001770
Jooyung Han85d61762020-06-24 23:50:26 +09001771 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
1772 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001773 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001774 a.linkToSystemLib = false
1775 }
1776
Jiyong Park9d677202020-02-19 16:29:35 +09001777 // We don't need the optimization for updatable APEXes, as it might give false signal
1778 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01001779 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09001780 a.linkToSystemLib = false
1781 }
1782
Jiyong Park638d30e2020-02-26 18:27:19 +09001783 // We also don't want the optimization for host APEXes, because it doesn't make sense.
1784 if ctx.Host() {
1785 a.linkToSystemLib = false
1786 }
1787
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001788 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
1789
1790 ////////////////////////////////////////////////////////////////////////////////////////////
1791 // 4) generate the build rules to create the APEX. This is done in builder.go.
1792 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001793 if a.properties.ApexType == flattenedApex {
1794 a.buildFlattenedApex(ctx)
1795 } else {
1796 a.buildUnflattenedApex(ctx)
1797 }
Jiyong Park956305c2020-01-09 12:32:06 +09001798 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07001799 a.buildLintReports(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09001800
1801 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
1802 if a.installable() {
1803 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
1804 // along with other ordinary files. (Note that this is done by apexer for
1805 // non-flattened APEXes)
1806 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
1807
1808 // Place the public key as apex_pubkey. This is also done by apexer for
1809 // non-flattened APEXes case.
1810 // TODO(jiyong): Why do we need this CP rule?
1811 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1812 ctx.Build(pctx, android.BuildParams{
1813 Rule: android.Cp,
1814 Input: a.public_key_file,
1815 Output: copiedPubkey,
1816 })
1817 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
1818 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09001819}
1820
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001821///////////////////////////////////////////////////////////////////////////////////////////////////
1822// Factory functions
1823//
1824
1825func newApexBundle() *apexBundle {
1826 module := &apexBundle{}
1827
1828 module.AddProperties(&module.properties)
1829 module.AddProperties(&module.targetProperties)
1830 module.AddProperties(&module.overridableProperties)
1831
1832 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1833 android.InitDefaultableModule(module)
1834 android.InitSdkAwareModule(module)
1835 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
1836 return module
1837}
1838
1839func ApexBundleFactory(testApex bool, artApex bool) android.Module {
1840 bundle := newApexBundle()
1841 bundle.testApex = testApex
1842 bundle.artApex = artApex
1843 return bundle
1844}
1845
1846// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
1847// certain compatibility checks such as apex_available are not done for apex_test.
1848func testApexBundleFactory() android.Module {
1849 bundle := newApexBundle()
1850 bundle.testApex = true
1851 return bundle
1852}
1853
1854// apex packages other modules into an APEX file which is a packaging format for system-level
1855// components like binaries, shared libraries, etc.
1856func BundleFactory() android.Module {
1857 return newApexBundle()
1858}
1859
1860type Defaults struct {
1861 android.ModuleBase
1862 android.DefaultsModuleBase
1863}
1864
1865// apex_defaults provides defaultable properties to other apex modules.
1866func defaultsFactory() android.Module {
1867 return DefaultsFactory()
1868}
1869
1870func DefaultsFactory(props ...interface{}) android.Module {
1871 module := &Defaults{}
1872
1873 module.AddProperties(props...)
1874 module.AddProperties(
1875 &apexBundleProperties{},
1876 &apexTargetBundleProperties{},
1877 &overridableProperties{},
1878 )
1879
1880 android.InitDefaultsModule(module)
1881 return module
1882}
1883
1884type OverrideApex struct {
1885 android.ModuleBase
1886 android.OverrideModuleBase
1887}
1888
1889func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1890 // All the overrides happen in the base module.
1891}
1892
1893// override_apex is used to create an apex module based on another apex module by overriding some of
1894// its properties.
1895func overrideApexFactory() android.Module {
1896 m := &OverrideApex{}
1897
1898 m.AddProperties(&overridableProperties{})
1899
1900 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1901 android.InitOverrideModule(m)
1902 return m
1903}
1904
1905///////////////////////////////////////////////////////////////////////////////////////////////////
1906// Vality check routines
1907//
1908// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
1909// certain conditions are not met.
1910//
1911// TODO(jiyong): move these checks to a separate go file.
1912
1913// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
1914// of this apexBundle.
1915func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1916 if a.testApex || a.vndkApex {
1917 return
1918 }
1919 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1920 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1921 return
1922 }
1923 // apexBundle::minSdkVersion reports its own errors.
1924 minSdkVersion := a.minSdkVersion(ctx)
1925 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
1926}
1927
1928func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
1929 ver := proptools.String(a.properties.Min_sdk_version)
1930 if ver == "" {
1931 return android.FutureApiLevel
1932 }
1933 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
1934 if err != nil {
1935 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
1936 return android.NoneApiLevel
1937 }
1938 if apiLevel.IsPreview() {
1939 // All codenames should build against "current".
1940 return android.FutureApiLevel
1941 }
1942 return apiLevel
1943}
1944
1945// Ensures that a lib providing stub isn't statically linked
1946func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1947 // Practically, we only care about regular APEXes on the device.
1948 if ctx.Host() || a.testApex || a.vndkApex {
1949 return
1950 }
1951
1952 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1953
1954 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1955 if ccm, ok := to.(*cc.Module); ok {
1956 apexName := ctx.ModuleName()
1957 fromName := ctx.OtherModuleName(from)
1958 toName := ctx.OtherModuleName(to)
1959
1960 // If `to` is not actually in the same APEX as `from` then it does not need
1961 // apex_available and neither do any of its dependencies.
1962 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1963 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1964 return false
1965 }
1966
1967 // The dynamic linker and crash_dump tool in the runtime APEX is the only
1968 // exception to this rule. It can't make the static dependencies dynamic
1969 // because it can't do the dynamic linking for itself.
1970 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1971 return false
1972 }
1973
1974 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
1975 if isStubLibraryFromOtherApex && !externalDep {
1976 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1977 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1978 }
1979
1980 }
1981 return true
1982 })
1983}
1984
Artur Satayev8cf899a2020-04-15 17:29:42 +01001985// Enforce that Java deps of the apex are using stable SDKs to compile
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001986func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1987 if a.Updatable() {
1988 if String(a.properties.Min_sdk_version) == "" {
1989 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1990 }
1991 a.checkJavaStableSdkVersion(ctx)
1992 }
1993}
1994
Artur Satayev8cf899a2020-04-15 17:29:42 +01001995func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001996 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
1997 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01001998 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
1999 tag := ctx.OtherModuleDependencyTag(module)
2000 switch tag {
2001 case javaLibTag, androidAppTag:
2002 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2003 if err := m.CheckStableSdkVersion(); err != nil {
2004 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2005 }
2006 }
2007 }
2008 })
2009}
2010
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002011// Ensures that the all the dependencies are marked as available for this APEX
2012func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2013 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2014 if ctx.Host() || a.testApex || a.vndkApex {
2015 return
2016 }
2017
2018 // Because APEXes targeting other than system/system_ext partitions can't set
2019 // apex_available, we skip checks for these APEXes
2020 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2021 return
2022 }
2023
2024 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2025 // Requiring them and their transitive depencies with apex_available is not right
2026 // because they just add noise.
2027 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2028 return
2029 }
2030
2031 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2032 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2033 if externalDep {
2034 return false
2035 }
2036
2037 apexName := ctx.ModuleName()
2038 fromName := ctx.OtherModuleName(from)
2039 toName := ctx.OtherModuleName(to)
2040
2041 // If `to` is not actually in the same APEX as `from` then it does not need
2042 // apex_available and neither do any of its dependencies.
2043 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2044 // As soon as the dependency graph crosses the APEX boundary, don't go
2045 // further.
2046 return false
2047 }
2048
2049 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2050 return true
2051 }
2052 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'. Dependency path:%s",
2053 fromName, toName, ctx.GetPathString(true))
2054 // Visit this module's dependencies to check and report any issues with their availability.
2055 return true
2056 })
2057}
2058
2059var (
2060 apexAvailBaseline = makeApexAvailableBaseline()
2061 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2062)
2063
Colin Cross440e0d02020-06-11 11:32:11 -07002064func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002065 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002066 moduleName = normalizeModuleName(moduleName)
2067
Colin Cross440e0d02020-06-11 11:32:11 -07002068 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002069 return true
2070 }
2071
2072 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002073 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002074 return true
2075 }
2076
2077 return false
2078}
2079
2080func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002081 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2082 // system. Trim the prefix for the check since they are confusing
2083 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2084 if strings.HasPrefix(moduleName, "libclang_rt.") {
2085 // This module has many arch variants that depend on the product being built.
2086 // We don't want to list them all
2087 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002088 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002089 if strings.HasPrefix(moduleName, "androidx.") {
2090 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2091 moduleName = "androidx"
2092 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002093 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002094}
2095
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002096// Transform the map of apex -> modules to module -> apexes.
2097func invertApexBaseline(m map[string][]string) map[string][]string {
2098 r := make(map[string][]string)
2099 for apex, modules := range m {
2100 for _, module := range modules {
2101 r[module] = append(r[module], apex)
2102 }
2103 }
2104 return r
2105}
2106
2107// Retrieve the baseline of apexes to which the supplied module belongs.
2108func BaselineApexAvailable(moduleName string) []string {
2109 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2110}
2111
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002112// This is a map from apex to modules, which overrides the apex_available setting for that
2113// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002114// TODO(b/147364041): remove this
2115func makeApexAvailableBaseline() map[string][]string {
2116 // The "Module separator"s below are employed to minimize merge conflicts.
2117 m := make(map[string][]string)
2118 //
2119 // Module separator
2120 //
2121 m["com.android.appsearch"] = []string{
2122 "icing-java-proto-lite",
2123 "libprotobuf-java-lite",
2124 }
2125 //
2126 // Module separator
2127 //
2128 m["com.android.bluetooth.updatable"] = []string{
2129 "android.hardware.audio.common@5.0",
2130 "android.hardware.bluetooth.a2dp@1.0",
2131 "android.hardware.bluetooth.audio@2.0",
2132 "android.hardware.bluetooth@1.0",
2133 "android.hardware.bluetooth@1.1",
2134 "android.hardware.graphics.bufferqueue@1.0",
2135 "android.hardware.graphics.bufferqueue@2.0",
2136 "android.hardware.graphics.common@1.0",
2137 "android.hardware.graphics.common@1.1",
2138 "android.hardware.graphics.common@1.2",
2139 "android.hardware.media@1.0",
2140 "android.hidl.safe_union@1.0",
2141 "android.hidl.token@1.0",
2142 "android.hidl.token@1.0-utils",
2143 "avrcp-target-service",
2144 "avrcp_headers",
2145 "bluetooth-protos-lite",
2146 "bluetooth.mapsapi",
2147 "com.android.vcard",
2148 "dnsresolver_aidl_interface-V2-java",
2149 "ipmemorystore-aidl-interfaces-V5-java",
2150 "ipmemorystore-aidl-interfaces-java",
2151 "internal_include_headers",
2152 "lib-bt-packets",
2153 "lib-bt-packets-avrcp",
2154 "lib-bt-packets-base",
2155 "libFraunhoferAAC",
2156 "libaudio-a2dp-hw-utils",
2157 "libaudio-hearing-aid-hw-utils",
2158 "libbinder_headers",
2159 "libbluetooth",
2160 "libbluetooth-types",
2161 "libbluetooth-types-header",
2162 "libbluetooth_gd",
2163 "libbluetooth_headers",
2164 "libbluetooth_jni",
2165 "libbt-audio-hal-interface",
2166 "libbt-bta",
2167 "libbt-common",
2168 "libbt-hci",
2169 "libbt-platform-protos-lite",
2170 "libbt-protos-lite",
2171 "libbt-sbc-decoder",
2172 "libbt-sbc-encoder",
2173 "libbt-stack",
2174 "libbt-utils",
2175 "libbtcore",
2176 "libbtdevice",
2177 "libbte",
2178 "libbtif",
2179 "libchrome",
2180 "libevent",
2181 "libfmq",
2182 "libg722codec",
2183 "libgui_headers",
2184 "libmedia_headers",
2185 "libmodpb64",
2186 "libosi",
2187 "libstagefright_foundation_headers",
2188 "libstagefright_headers",
2189 "libstatslog",
2190 "libstatssocket",
2191 "libtinyxml2",
2192 "libudrv-uipc",
2193 "libz",
2194 "media_plugin_headers",
2195 "net-utils-services-common",
2196 "netd_aidl_interface-unstable-java",
2197 "netd_event_listener_interface-java",
2198 "netlink-client",
2199 "networkstack-client",
2200 "sap-api-java-static",
2201 "services.net",
2202 }
2203 //
2204 // Module separator
2205 //
2206 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2207 //
2208 // Module separator
2209 //
2210 m["com.android.extservices"] = []string{
2211 "error_prone_annotations",
2212 "ExtServices-core",
2213 "ExtServices",
2214 "libtextclassifier-java",
2215 "libz_current",
2216 "textclassifier-statsd",
2217 "TextClassifierNotificationLibNoManifest",
2218 "TextClassifierServiceLibNoManifest",
2219 }
2220 //
2221 // Module separator
2222 //
2223 m["com.android.neuralnetworks"] = []string{
2224 "android.hardware.neuralnetworks@1.0",
2225 "android.hardware.neuralnetworks@1.1",
2226 "android.hardware.neuralnetworks@1.2",
2227 "android.hardware.neuralnetworks@1.3",
2228 "android.hidl.allocator@1.0",
2229 "android.hidl.memory.token@1.0",
2230 "android.hidl.memory@1.0",
2231 "android.hidl.safe_union@1.0",
2232 "libarect",
2233 "libbuildversion",
2234 "libmath",
2235 "libprocpartition",
2236 "libsync",
2237 }
2238 //
2239 // Module separator
2240 //
2241 m["com.android.media"] = []string{
2242 "android.frameworks.bufferhub@1.0",
2243 "android.hardware.cas.native@1.0",
2244 "android.hardware.cas@1.0",
2245 "android.hardware.configstore-utils",
2246 "android.hardware.configstore@1.0",
2247 "android.hardware.configstore@1.1",
2248 "android.hardware.graphics.allocator@2.0",
2249 "android.hardware.graphics.allocator@3.0",
2250 "android.hardware.graphics.bufferqueue@1.0",
2251 "android.hardware.graphics.bufferqueue@2.0",
2252 "android.hardware.graphics.common@1.0",
2253 "android.hardware.graphics.common@1.1",
2254 "android.hardware.graphics.common@1.2",
2255 "android.hardware.graphics.mapper@2.0",
2256 "android.hardware.graphics.mapper@2.1",
2257 "android.hardware.graphics.mapper@3.0",
2258 "android.hardware.media.omx@1.0",
2259 "android.hardware.media@1.0",
2260 "android.hidl.allocator@1.0",
2261 "android.hidl.memory.token@1.0",
2262 "android.hidl.memory@1.0",
2263 "android.hidl.token@1.0",
2264 "android.hidl.token@1.0-utils",
2265 "bionic_libc_platform_headers",
2266 "exoplayer2-extractor",
2267 "exoplayer2-extractor-annotation-stubs",
2268 "gl_headers",
2269 "jsr305",
2270 "libEGL",
2271 "libEGL_blobCache",
2272 "libEGL_getProcAddress",
2273 "libFLAC",
2274 "libFLAC-config",
2275 "libFLAC-headers",
2276 "libGLESv2",
2277 "libaacextractor",
2278 "libamrextractor",
2279 "libarect",
2280 "libaudio_system_headers",
2281 "libaudioclient",
2282 "libaudioclient_headers",
2283 "libaudiofoundation",
2284 "libaudiofoundation_headers",
2285 "libaudiomanager",
2286 "libaudiopolicy",
2287 "libaudioutils",
2288 "libaudioutils_fixedfft",
2289 "libbinder_headers",
2290 "libbluetooth-types-header",
2291 "libbufferhub",
2292 "libbufferhub_headers",
2293 "libbufferhubqueue",
2294 "libc_malloc_debug_backtrace",
2295 "libcamera_client",
2296 "libcamera_metadata",
2297 "libdvr_headers",
2298 "libexpat",
2299 "libfifo",
2300 "libflacextractor",
2301 "libgrallocusage",
2302 "libgraphicsenv",
2303 "libgui",
2304 "libgui_headers",
2305 "libhardware_headers",
2306 "libinput",
2307 "liblzma",
2308 "libmath",
2309 "libmedia",
2310 "libmedia_codeclist",
2311 "libmedia_headers",
2312 "libmedia_helper",
2313 "libmedia_helper_headers",
2314 "libmedia_midiiowrapper",
2315 "libmedia_omx",
2316 "libmediautils",
2317 "libmidiextractor",
2318 "libmkvextractor",
2319 "libmp3extractor",
2320 "libmp4extractor",
2321 "libmpeg2extractor",
2322 "libnativebase_headers",
2323 "libnativewindow_headers",
2324 "libnblog",
2325 "liboggextractor",
2326 "libpackagelistparser",
2327 "libpdx",
2328 "libpdx_default_transport",
2329 "libpdx_headers",
2330 "libpdx_uds",
2331 "libprocinfo",
2332 "libspeexresampler",
2333 "libspeexresampler",
2334 "libstagefright_esds",
2335 "libstagefright_flacdec",
2336 "libstagefright_flacdec",
2337 "libstagefright_foundation",
2338 "libstagefright_foundation_headers",
2339 "libstagefright_foundation_without_imemory",
2340 "libstagefright_headers",
2341 "libstagefright_id3",
2342 "libstagefright_metadatautils",
2343 "libstagefright_mpeg2extractor",
2344 "libstagefright_mpeg2support",
2345 "libsync",
2346 "libui",
2347 "libui_headers",
2348 "libunwindstack",
2349 "libvibrator",
2350 "libvorbisidec",
2351 "libwavextractor",
2352 "libwebm",
2353 "media_ndk_headers",
2354 "media_plugin_headers",
2355 "updatable-media",
2356 }
2357 //
2358 // Module separator
2359 //
2360 m["com.android.media.swcodec"] = []string{
2361 "android.frameworks.bufferhub@1.0",
2362 "android.hardware.common-ndk_platform",
2363 "android.hardware.configstore-utils",
2364 "android.hardware.configstore@1.0",
2365 "android.hardware.configstore@1.1",
2366 "android.hardware.graphics.allocator@2.0",
2367 "android.hardware.graphics.allocator@3.0",
2368 "android.hardware.graphics.allocator@4.0",
2369 "android.hardware.graphics.bufferqueue@1.0",
2370 "android.hardware.graphics.bufferqueue@2.0",
2371 "android.hardware.graphics.common-ndk_platform",
2372 "android.hardware.graphics.common@1.0",
2373 "android.hardware.graphics.common@1.1",
2374 "android.hardware.graphics.common@1.2",
2375 "android.hardware.graphics.mapper@2.0",
2376 "android.hardware.graphics.mapper@2.1",
2377 "android.hardware.graphics.mapper@3.0",
2378 "android.hardware.graphics.mapper@4.0",
2379 "android.hardware.media.bufferpool@2.0",
2380 "android.hardware.media.c2@1.0",
2381 "android.hardware.media.c2@1.1",
2382 "android.hardware.media.omx@1.0",
2383 "android.hardware.media@1.0",
2384 "android.hardware.media@1.0",
2385 "android.hidl.memory.token@1.0",
2386 "android.hidl.memory@1.0",
2387 "android.hidl.safe_union@1.0",
2388 "android.hidl.token@1.0",
2389 "android.hidl.token@1.0-utils",
2390 "libEGL",
2391 "libFLAC",
2392 "libFLAC-config",
2393 "libFLAC-headers",
2394 "libFraunhoferAAC",
2395 "libLibGuiProperties",
2396 "libarect",
2397 "libaudio_system_headers",
2398 "libaudioutils",
2399 "libaudioutils",
2400 "libaudioutils_fixedfft",
2401 "libavcdec",
2402 "libavcenc",
2403 "libavservices_minijail",
2404 "libavservices_minijail",
2405 "libbinder_headers",
2406 "libbinderthreadstateutils",
2407 "libbluetooth-types-header",
2408 "libbufferhub_headers",
2409 "libcodec2",
2410 "libcodec2_headers",
2411 "libcodec2_hidl@1.0",
2412 "libcodec2_hidl@1.1",
2413 "libcodec2_internal",
2414 "libcodec2_soft_aacdec",
2415 "libcodec2_soft_aacenc",
2416 "libcodec2_soft_amrnbdec",
2417 "libcodec2_soft_amrnbenc",
2418 "libcodec2_soft_amrwbdec",
2419 "libcodec2_soft_amrwbenc",
2420 "libcodec2_soft_av1dec_gav1",
2421 "libcodec2_soft_avcdec",
2422 "libcodec2_soft_avcenc",
2423 "libcodec2_soft_common",
2424 "libcodec2_soft_flacdec",
2425 "libcodec2_soft_flacenc",
2426 "libcodec2_soft_g711alawdec",
2427 "libcodec2_soft_g711mlawdec",
2428 "libcodec2_soft_gsmdec",
2429 "libcodec2_soft_h263dec",
2430 "libcodec2_soft_h263enc",
2431 "libcodec2_soft_hevcdec",
2432 "libcodec2_soft_hevcenc",
2433 "libcodec2_soft_mp3dec",
2434 "libcodec2_soft_mpeg2dec",
2435 "libcodec2_soft_mpeg4dec",
2436 "libcodec2_soft_mpeg4enc",
2437 "libcodec2_soft_opusdec",
2438 "libcodec2_soft_opusenc",
2439 "libcodec2_soft_rawdec",
2440 "libcodec2_soft_vorbisdec",
2441 "libcodec2_soft_vp8dec",
2442 "libcodec2_soft_vp8enc",
2443 "libcodec2_soft_vp9dec",
2444 "libcodec2_soft_vp9enc",
2445 "libcodec2_vndk",
2446 "libdvr_headers",
2447 "libfmq",
2448 "libfmq",
2449 "libgav1",
2450 "libgralloctypes",
2451 "libgrallocusage",
2452 "libgraphicsenv",
2453 "libgsm",
2454 "libgui_bufferqueue_static",
2455 "libgui_headers",
2456 "libhardware",
2457 "libhardware_headers",
2458 "libhevcdec",
2459 "libhevcenc",
2460 "libion",
2461 "libjpeg",
2462 "liblzma",
2463 "libmath",
2464 "libmedia_codecserviceregistrant",
2465 "libmedia_headers",
2466 "libmpeg2dec",
2467 "libnativebase_headers",
2468 "libnativewindow_headers",
2469 "libpdx_headers",
2470 "libscudo_wrapper",
2471 "libsfplugin_ccodec_utils",
2472 "libspeexresampler",
2473 "libstagefright_amrnb_common",
2474 "libstagefright_amrnbdec",
2475 "libstagefright_amrnbenc",
2476 "libstagefright_amrwbdec",
2477 "libstagefright_amrwbenc",
2478 "libstagefright_bufferpool@2.0.1",
2479 "libstagefright_bufferqueue_helper",
2480 "libstagefright_enc_common",
2481 "libstagefright_flacdec",
2482 "libstagefright_foundation",
2483 "libstagefright_foundation_headers",
2484 "libstagefright_headers",
2485 "libstagefright_m4vh263dec",
2486 "libstagefright_m4vh263enc",
2487 "libstagefright_mp3dec",
2488 "libsync",
2489 "libui",
2490 "libui_headers",
2491 "libunwindstack",
2492 "libvorbisidec",
2493 "libvpx",
2494 "libyuv",
2495 "libyuv_static",
2496 "media_ndk_headers",
2497 "media_plugin_headers",
2498 "mediaswcodec",
2499 }
2500 //
2501 // Module separator
2502 //
2503 m["com.android.mediaprovider"] = []string{
2504 "MediaProvider",
2505 "MediaProviderGoogle",
2506 "fmtlib_ndk",
2507 "libbase_ndk",
2508 "libfuse",
2509 "libfuse_jni",
2510 }
2511 //
2512 // Module separator
2513 //
2514 m["com.android.permission"] = []string{
2515 "car-ui-lib",
2516 "iconloader",
2517 "kotlin-annotations",
2518 "kotlin-stdlib",
2519 "kotlin-stdlib-jdk7",
2520 "kotlin-stdlib-jdk8",
2521 "kotlinx-coroutines-android",
2522 "kotlinx-coroutines-android-nodeps",
2523 "kotlinx-coroutines-core",
2524 "kotlinx-coroutines-core-nodeps",
2525 "permissioncontroller-statsd",
2526 "GooglePermissionController",
2527 "PermissionController",
2528 "SettingsLibActionBarShadow",
2529 "SettingsLibAppPreference",
2530 "SettingsLibBarChartPreference",
2531 "SettingsLibLayoutPreference",
2532 "SettingsLibProgressBar",
2533 "SettingsLibSearchWidget",
2534 "SettingsLibSettingsTheme",
2535 "SettingsLibRestrictedLockUtils",
2536 "SettingsLibHelpUtils",
2537 }
2538 //
2539 // Module separator
2540 //
2541 m["com.android.runtime"] = []string{
2542 "bionic_libc_platform_headers",
2543 "libarm-optimized-routines-math",
2544 "libc_aeabi",
2545 "libc_bionic",
2546 "libc_bionic_ndk",
2547 "libc_bootstrap",
2548 "libc_common",
2549 "libc_common_shared",
2550 "libc_common_static",
2551 "libc_dns",
2552 "libc_dynamic_dispatch",
2553 "libc_fortify",
2554 "libc_freebsd",
2555 "libc_freebsd_large_stack",
2556 "libc_gdtoa",
2557 "libc_init_dynamic",
2558 "libc_init_static",
2559 "libc_jemalloc_wrapper",
2560 "libc_netbsd",
2561 "libc_nomalloc",
2562 "libc_nopthread",
2563 "libc_openbsd",
2564 "libc_openbsd_large_stack",
2565 "libc_openbsd_ndk",
2566 "libc_pthread",
2567 "libc_static_dispatch",
2568 "libc_syscalls",
2569 "libc_tzcode",
2570 "libc_unwind_static",
2571 "libdebuggerd",
2572 "libdebuggerd_common_headers",
2573 "libdebuggerd_handler_core",
2574 "libdebuggerd_handler_fallback",
2575 "libdl_static",
2576 "libjemalloc5",
2577 "liblinker_main",
2578 "liblinker_malloc",
2579 "liblz4",
2580 "liblzma",
2581 "libprocinfo",
2582 "libpropertyinfoparser",
2583 "libscudo",
2584 "libstdc++",
2585 "libsystemproperties",
2586 "libtombstoned_client_static",
2587 "libunwindstack",
2588 "libz",
2589 "libziparchive",
2590 }
2591 //
2592 // Module separator
2593 //
2594 m["com.android.tethering"] = []string{
2595 "android.hardware.tetheroffload.config-V1.0-java",
2596 "android.hardware.tetheroffload.control-V1.0-java",
2597 "android.hidl.base-V1.0-java",
2598 "libcgrouprc",
2599 "libcgrouprc_format",
2600 "libtetherutilsjni",
2601 "libvndksupport",
2602 "net-utils-framework-common",
2603 "netd_aidl_interface-V3-java",
2604 "netlink-client",
2605 "networkstack-aidl-interfaces-java",
2606 "tethering-aidl-interfaces-java",
2607 "TetheringApiCurrentLib",
2608 }
2609 //
2610 // Module separator
2611 //
2612 m["com.android.wifi"] = []string{
2613 "PlatformProperties",
2614 "android.hardware.wifi-V1.0-java",
2615 "android.hardware.wifi-V1.0-java-constants",
2616 "android.hardware.wifi-V1.1-java",
2617 "android.hardware.wifi-V1.2-java",
2618 "android.hardware.wifi-V1.3-java",
2619 "android.hardware.wifi-V1.4-java",
2620 "android.hardware.wifi.hostapd-V1.0-java",
2621 "android.hardware.wifi.hostapd-V1.1-java",
2622 "android.hardware.wifi.hostapd-V1.2-java",
2623 "android.hardware.wifi.supplicant-V1.0-java",
2624 "android.hardware.wifi.supplicant-V1.1-java",
2625 "android.hardware.wifi.supplicant-V1.2-java",
2626 "android.hardware.wifi.supplicant-V1.3-java",
2627 "android.hidl.base-V1.0-java",
2628 "android.hidl.manager-V1.0-java",
2629 "android.hidl.manager-V1.1-java",
2630 "android.hidl.manager-V1.2-java",
2631 "bouncycastle-unbundled",
2632 "dnsresolver_aidl_interface-V2-java",
2633 "error_prone_annotations",
2634 "framework-wifi-pre-jarjar",
2635 "framework-wifi-util-lib",
2636 "ipmemorystore-aidl-interfaces-V3-java",
2637 "ipmemorystore-aidl-interfaces-java",
2638 "ksoap2",
2639 "libnanohttpd",
2640 "libwifi-jni",
2641 "net-utils-services-common",
2642 "netd_aidl_interface-V2-java",
2643 "netd_aidl_interface-unstable-java",
2644 "netd_event_listener_interface-java",
2645 "netlink-client",
2646 "networkstack-client",
2647 "services.net",
2648 "wifi-lite-protos",
2649 "wifi-nano-protos",
2650 "wifi-service-pre-jarjar",
2651 "wifi-service-resources",
2652 }
2653 //
2654 // Module separator
2655 //
2656 m["com.android.sdkext"] = []string{
2657 "fmtlib_ndk",
2658 "libbase_ndk",
2659 "libprotobuf-cpp-lite-ndk",
2660 }
2661 //
2662 // Module separator
2663 //
2664 m["com.android.os.statsd"] = []string{
2665 "libstatssocket",
2666 }
2667 //
2668 // Module separator
2669 //
2670 m[android.AvailableToAnyApex] = []string{
2671 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
2672 "androidx",
2673 "androidx-constraintlayout_constraintlayout",
2674 "androidx-constraintlayout_constraintlayout-nodeps",
2675 "androidx-constraintlayout_constraintlayout-solver",
2676 "androidx-constraintlayout_constraintlayout-solver-nodeps",
2677 "com.google.android.material_material",
2678 "com.google.android.material_material-nodeps",
2679
2680 "libatomic",
2681 "libclang_rt",
2682 "libgcc_stripped",
2683 "libprofile-clang-extras",
2684 "libprofile-clang-extras_ndk",
2685 "libprofile-extras",
2686 "libprofile-extras_ndk",
2687 "libunwind_llvm",
2688 }
2689 return m
2690}
2691
2692func init() {
2693 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
2694 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
2695}
2696
2697func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
2698 rules := make([]android.Rule, 0, len(modules_packages))
2699 for module_name, module_packages := range modules_packages {
2700 permitted_packages_rule := android.NeverAllow().
2701 BootclasspathJar().
2702 With("apex_available", module_name).
2703 WithMatcher("permitted_packages", android.NotInList(module_packages)).
2704 Because("jars that are part of the " + module_name +
2705 " module may only allow these packages: " + strings.Join(module_packages, ",") +
2706 ". Please jarjar or move code around.")
2707 rules = append(rules, permitted_packages_rule)
2708 }
2709 return rules
2710}
2711
2712// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2713// Adding code to the bootclasspath in new packages will cause issues on module update.
2714func qModulesPackages() map[string][]string {
2715 return map[string][]string{
2716 "com.android.conscrypt": []string{
2717 "android.net.ssl",
2718 "com.android.org.conscrypt",
2719 },
2720 "com.android.media": []string{
2721 "android.media",
2722 },
2723 }
2724}
2725
2726// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2727// Adding code to the bootclasspath in new packages will cause issues on module update.
2728func rModulesPackages() map[string][]string {
2729 return map[string][]string{
2730 "com.android.mediaprovider": []string{
2731 "android.provider",
2732 },
2733 "com.android.permission": []string{
2734 "android.permission",
2735 "android.app.role",
2736 "com.android.permission",
2737 "com.android.role",
2738 },
2739 "com.android.sdkext": []string{
2740 "android.os.ext",
2741 },
2742 "com.android.os.statsd": []string{
2743 "android.app",
2744 "android.os",
2745 "android.util",
2746 "com.android.internal.statsd",
2747 "com.android.server.stats",
2748 },
2749 "com.android.wifi": []string{
2750 "com.android.server.wifi",
2751 "com.android.wifi.x",
2752 "android.hardware.wifi",
2753 "android.net.wifi",
2754 },
2755 "com.android.tethering": []string{
2756 "android.net",
2757 },
2758 }
2759}