blob: ffc29b7abf9922b003af3f6fd2b83b839df77c7c [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 distFiles android.TaggedDistFiles
354}
355
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900356// apexFileClass represents a type of file that can be included in APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900357type apexFileClass int
358
Jooyung Han72bd2f82019-10-23 16:46:38 +0900359const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900360 app apexFileClass = iota
361 appSet
362 etc
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900363 goBinary
364 javaSharedLib
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900365 nativeExecutable
366 nativeSharedLib
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900367 nativeTest
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900368 pyBinary
369 shBinary
Jooyung Han72bd2f82019-10-23 16:46:38 +0900370)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900371
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900372// apexFile represents a file in an APEX bundle. This is created during the first half of
373// GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half
374// of the function, this is used to create commands that copies the files into a staging directory,
375// where they are packaged into the APEX file. This struct is also used for creating Make modules
376// for each of the files in case when the APEX is flattened.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900377type apexFile struct {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900378 // buildFile is put in the installDir inside the APEX.
379 builtFile android.Path
380 noticeFiles android.Paths
381 installDir string
382 customStem string
383 symlinks []string // additional symlinks
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900384
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900385 // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk
386 // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex
387 // suffix>]
388 androidMkModuleName string // becomes LOCAL_MODULE
389 class apexFileClass // becomes LOCAL_MODULE_CLASS
390 moduleDir string // becomes LOCAL_PATH
391 requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES
392 targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES
393 hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES
394 dataPaths []android.DataPath // becomes LOCAL_TEST_DATA
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900395
396 jacocoReportClassesFile android.Path // only for javalibs and apps
397 lintDepSets java.LintDepSets // only for javalibs and apps
398 certificate java.Certificate // only for apps
399 overriddenPackageName string // only for apps
400
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900401 transitiveDep bool
402 isJniLib bool
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900403
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900404 // TODO(jiyong): remove this
405 module android.Module
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900406}
407
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900408// TODO(jiyong): shorten the arglist using an option struct
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900409func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
410 ret := apexFile{
411 builtFile: builtFile,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900412 installDir: installDir,
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900413 androidMkModuleName: androidMkModuleName,
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900414 class: class,
415 module: module,
416 }
417 if module != nil {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900418 ret.noticeFiles = module.NoticeFiles()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900419 ret.moduleDir = ctx.OtherModuleDir(module)
420 ret.requiredModuleNames = module.RequiredModuleNames()
421 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
422 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900423 }
424 return ret
425}
426
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900427func (af *apexFile) ok() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900428 return af.builtFile != nil && af.builtFile.String() != ""
429}
430
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900431// apexRelativePath returns the relative path of the given path from the install directory of this
432// apexFile.
433// TODO(jiyong): rename this
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900434func (af *apexFile) apexRelativePath(path string) string {
435 return filepath.Join(af.installDir, path)
436}
437
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900438// path returns path of this apex file relative to the APEX root
439func (af *apexFile) path() string {
440 return af.apexRelativePath(af.stem())
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900441}
442
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900443// stem returns the base filename of this apex file
444func (af *apexFile) stem() string {
445 if af.customStem != "" {
446 return af.customStem
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900447 }
448 return af.builtFile.Base()
449}
450
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900451// symlinkPaths returns paths of the symlinks (if any) relative to the APEX root
452func (af *apexFile) symlinkPaths() []string {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900453 var ret []string
454 for _, symlink := range af.symlinks {
455 ret = append(ret, af.apexRelativePath(symlink))
456 }
457 return ret
458}
459
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900460// availableToPlatform tests whether this apexFile is from a module that can be installed to the
461// platform.
462func (af *apexFile) availableToPlatform() bool {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900463 if af.module == nil {
464 return false
465 }
466 if am, ok := af.module.(android.ApexModule); ok {
467 return am.AvailableFor(android.AvailableToPlatform)
468 }
469 return false
470}
471
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900472////////////////////////////////////////////////////////////////////////////////////////////////////
473// Mutators
474//
475// Brief description about mutators for APEX. The following three mutators are the most important
476// ones.
477//
478// 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added
479// to the (direct) dependencies of this APEX bundle.
480//
481// 2) apexDepsMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to
482// collect modules that are direct and transitive dependencies of each APEX bundle. The collected
483// modules are marked as being included in the APEX via BuildForApex().
484//
485// 3) apexMutator: this is a post-deps mutator that runs after apexDepsMutator. For each module that
486// are marked by the apexDepsMutator, apex variations are created using CreateApexVariations().
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900487
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900488type dependencyTag struct {
489 blueprint.BaseDependencyTag
490 name string
491
492 // Determines if the dependent will be part of the APEX payload. Can be false for the
493 // dependencies to the signing key module, etc.
494 payload bool
495}
496
497var (
498 androidAppTag = dependencyTag{name: "androidApp", payload: true}
499 bpfTag = dependencyTag{name: "bpf", payload: true}
500 certificateTag = dependencyTag{name: "certificate"}
501 executableTag = dependencyTag{name: "executable", payload: true}
502 javaLibTag = dependencyTag{name: "javaLib", payload: true}
503 jniLibTag = dependencyTag{name: "jniLib", payload: true}
504 keyTag = dependencyTag{name: "key"}
505 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
506 rroTag = dependencyTag{name: "rro", payload: true}
507 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
508 testForTag = dependencyTag{name: "test for"}
509 testTag = dependencyTag{name: "test", payload: true}
510)
511
512// TODO(jiyong): shorten this function signature
513func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900514 binVariations := target.Variations()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900515 libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900516
517 if ctx.Device() {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900518 binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900519 libVariations = append(libVariations,
520 blueprint.Variation{Mutator: "image", Variation: imageVariation},
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900521 blueprint.Variation{Mutator: "version", Variation: ""}, // "" is the non-stub variant
522 )
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900523 }
524
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900525 // Use *FarVariation* to be able to depend on modules having conflicting variations with
526 // this module. This is required since arch variant of an APEX bundle is 'common' but it is
527 // 'arm' or 'arm64' for native shared libs.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900528 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900529 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900530 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
531 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900532}
533
534func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900535 if ctx.Device() {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900536 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
537 } else {
538 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
539 if ctx.Os().Bionic() {
540 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
541 } else {
542 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
543 }
544 }
545}
546
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900547// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply
548// android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX.
549func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
550 deviceConfig := ctx.DeviceConfig()
551 if a.vndkApex {
552 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900553 }
554
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900555 var prefix string
556 var vndkVersion string
557 if deviceConfig.VndkVersion() != "" {
558 if proptools.Bool(a.properties.Use_vendor) {
559 prefix = cc.VendorVariationPrefix
560 vndkVersion = deviceConfig.PlatformVndkVersion()
561 } else if a.SocSpecific() || a.DeviceSpecific() {
562 prefix = cc.VendorVariationPrefix
563 vndkVersion = deviceConfig.VndkVersion()
564 } else if a.ProductSpecific() {
565 prefix = cc.ProductVariationPrefix
566 vndkVersion = deviceConfig.ProductVndkVersion()
567 }
568 }
569 if vndkVersion == "current" {
570 vndkVersion = deviceConfig.PlatformVndkVersion()
571 }
572 if vndkVersion != "" {
573 return prefix + vndkVersion
574 }
575
576 return android.CoreVariation // The usual case
577}
578
579func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
580 // TODO(jiyong): move this kind of checks to GenerateAndroidBuildActions?
581 checkUseVendorProperty(ctx, a)
582
583 // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'.
584 // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For
585 // each target os/architectures, appropriate dependencies are selected by their
586 // target.<os>.multilib.<type> groups and are added as (direct) dependencies.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900587 targets := ctx.MultiTargets()
588 config := ctx.DeviceConfig()
589 imageVariation := a.getImageVariation(ctx)
590
591 a.combineProperties(ctx)
592
593 has32BitTarget := false
594 for _, target := range targets {
595 if target.Arch.ArchType.Multilib == "lib32" {
596 has32BitTarget = true
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000597 }
598 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900599 for i, target := range targets {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900600 // Don't include artifacts for the host cross targets because there is no way for us
601 // to run those artifacts natively on host
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900602 if target.HostCross {
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900603 continue
604 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000605
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900606 var depsList []ApexNativeDependencies
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000607
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900608 // Add native modules targeting both ABIs. When multilib.* is omitted for
609 // native_shared_libs/jni_libs/tests, it implies multilib.both
610 depsList = append(depsList, a.properties.Multilib.Both)
611 depsList = append(depsList, ApexNativeDependencies{
612 Native_shared_libs: a.properties.Native_shared_libs,
613 Tests: a.properties.Tests,
614 Jni_libs: a.properties.Jni_libs,
615 Binaries: nil,
616 })
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900617
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900618 // Add native modules targeting the first ABI When multilib.* is omitted for
619 // binaries, it implies multilib.first
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900620 isPrimaryAbi := i == 0
621 if isPrimaryAbi {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900622 depsList = append(depsList, a.properties.Multilib.First)
623 depsList = append(depsList, ApexNativeDependencies{
624 Native_shared_libs: nil,
625 Tests: nil,
626 Jni_libs: nil,
627 Binaries: a.properties.Binaries,
628 })
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900629 }
630
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900631 // Add native modules targeting either 32-bit or 64-bit ABI
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900632 switch target.Arch.ArchType.Multilib {
633 case "lib32":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900634 depsList = append(depsList, a.properties.Multilib.Lib32)
635 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900636 case "lib64":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900637 depsList = append(depsList, a.properties.Multilib.Lib64)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900638 if !has32BitTarget {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900639 depsList = append(depsList, a.properties.Multilib.Prefer32)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900640 }
641 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900642
643 for _, d := range depsList {
644 addDependenciesForNativeModules(ctx, d, target, imageVariation)
645 }
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900646 }
647
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900648 // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device)
649 // regardless of the TARGET_PREFER_* setting. See b/144532908
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900650 archForPrebuiltEtc := config.Arches()[0]
651 for _, arch := range config.Arches() {
652 // Prefer 64-bit arch if there is any
653 if arch.ArchType.Multilib == "lib64" {
654 archForPrebuiltEtc = arch
655 break
656 }
657 }
658 ctx.AddFarVariationDependencies([]blueprint.Variation{
659 {Mutator: "os", Variation: ctx.Os().String()},
660 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
661 }, prebuiltTag, a.properties.Prebuilts...)
662
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900663 // Common-arch dependencies come next
664 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
665 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
666 ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...)
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900667
668 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
669 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900670 ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900671 }
672
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900673 // Dependencies for signing
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900674 if String(a.properties.Key) == "" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900675 ctx.PropertyErrorf("key", "missing")
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900676 return
677 }
678 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
679
680 cert := android.SrcIsModule(a.getCertString(ctx))
681 if cert != "" {
682 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900683 // empty cert is not an error. Cert and private keys will be directly found under
684 // PRODUCT_DEFAULT_DEV_CERTIFICATE
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900685 }
686
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900687 // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs.
688 // This field currently isn't used.
689 // TODO(jiyong): consider dropping this feature
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900690 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
691 if len(a.properties.Uses_sdks) > 0 {
692 sdkRefs := []android.SdkRef{}
693 for _, str := range a.properties.Uses_sdks {
694 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
695 sdkRefs = append(sdkRefs, parsed)
696 }
697 a.BuildWithSdks(sdkRefs)
Andrei Onea115e7e72020-06-05 21:14:03 +0100698 }
699}
700
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900701// DepsMutator for the overridden properties.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900702func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
703 if a.overridableProperties.Allowed_files != nil {
704 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
Andrei Onea115e7e72020-06-05 21:14:03 +0100705 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900706
707 commonVariation := ctx.Config().AndroidCommonTarget.Variations()
708 ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...)
709 ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...)
Andrei Onea115e7e72020-06-05 21:14:03 +0100710}
711
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900712type ApexBundleInfo struct {
713 Contents *android.ApexContents
Andrei Onea115e7e72020-06-05 21:14:03 +0100714}
715
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900716var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900717
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900718// apexDepsMutator is responsible for collecting modules that need to have apex variants. They are
719// identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and
720// indirect) dependencies are collected. But a few types of modules that shouldn't be included in
721// the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended
722// on by multiple apexBundles. In that case, the module is collected for all of the apexBundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900723func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900724 if !mctx.Module().Enabled() {
725 return
726 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900727
Jooyung Han698dd9f2020-07-22 15:17:19 +0900728 a, ok := mctx.Module().(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900729 if !ok {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900730 return
731 }
Jooyung Handf78e212020-07-22 15:54:47 +0900732
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900733 // The VNDK APEX is special. For the APEX, the membership is described in a very different
734 // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK
735 // libraries are self-identified by their vndk.enabled properties. There is no need to run
736 // this mutator for the APEX as nothing will be collected. So, let's return fast.
737 if a.vndkApex {
738 return
739 }
740
741 // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are
742 // provided with a property named use_vndk_as_stable, which when set to true doesn't collect
743 // VNDK libraries as transitive dependencies. This option is useful for reducing the size of
744 // the non-system APEXes because the VNDK libraries won't be included (and duped) in the
745 // APEX, but shared across APEXes via the VNDK APEX.
Jooyung Handf78e212020-07-22 15:54:47 +0900746 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
747 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
748 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
749 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
750 return
751 }
752
Colin Cross56a83212020-09-15 18:30:11 -0700753 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900754 am, ok := child.(android.ApexModule)
755 if !ok || !am.CanHaveApexVariants() {
756 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900757 }
Paul Duffina37eca22020-07-22 13:00:54 +0100758 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900759 return false
760 }
Jooyung Handf78e212020-07-22 15:54:47 +0900761 if excludeVndkLibs {
762 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
763 return false
764 }
765 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900766 // By default, all the transitive dependencies are collected, unless filtered out
767 // above.
Colin Cross56a83212020-09-15 18:30:11 -0700768 return true
769 }
770
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900771 // Records whether a certain module is included in this apexBundle via direct dependency or
772 // inndirect dependency.
773 contents := make(map[string]android.ApexMembership)
Colin Cross56a83212020-09-15 18:30:11 -0700774 mctx.WalkDeps(func(child, parent android.Module) bool {
775 if !continueApexDepsWalk(child, parent) {
776 return false
777 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900778 // If the parent is apexBundle, this child is directly depended.
779 _, directDep := parent.(*apexBundle)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900780 depName := mctx.OtherModuleName(child)
Colin Cross56a83212020-09-15 18:30:11 -0700781 contents[depName] = contents[depName].Add(directDep)
782 return true
783 })
784
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900785 // The membership information is saved for later access
Jiyong Parke4758ed2020-11-18 01:34:22 +0900786 apexContents := android.NewApexContents(contents)
Colin Cross56a83212020-09-15 18:30:11 -0700787 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
788 Contents: apexContents,
789 })
790
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900791 // This is the main part of this mutator. Mark the collected dependencies that they need to
792 // be built for this apexBundle.
Colin Cross56a83212020-09-15 18:30:11 -0700793 apexInfo := android.ApexInfo{
794 ApexVariationName: mctx.ModuleName(),
795 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
796 RequiredSdks: a.RequiredSdks(),
797 Updatable: a.Updatable(),
798 InApexes: []string{mctx.ModuleName()},
799 ApexContents: []*android.ApexContents{apexContents},
800 }
Colin Cross56a83212020-09-15 18:30:11 -0700801 mctx.WalkDeps(func(child, parent android.Module) bool {
802 if !continueApexDepsWalk(child, parent) {
803 return false
804 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900805 child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark!
Jooyung Han698dd9f2020-07-22 15:17:19 +0900806 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900807 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900808}
809
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900810// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
811// unique apex variations for this module. See android/apex.go for more about unique apex variant.
812// TODO(jiyong): move this to android/apex.go?
Colin Crossaede88c2020-08-11 12:17:01 -0700813func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
814 if !mctx.Module().Enabled() {
815 return
816 }
817 if am, ok := mctx.Module().(android.ApexModule); ok {
Colin Cross56a83212020-09-15 18:30:11 -0700818 android.UpdateUniqueApexVariationsForDeps(mctx, am)
819 }
820}
821
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900822// apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on
823// the apex in order to retrieve its contents later.
824// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700825func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
826 if !mctx.Module().Enabled() {
827 return
828 }
Colin Cross56a83212020-09-15 18:30:11 -0700829 if am, ok := mctx.Module().(android.ApexModule); ok {
830 if testFor := am.TestFor(); len(testFor) > 0 {
831 mctx.AddFarVariationDependencies([]blueprint.Variation{
832 {Mutator: "os", Variation: am.Target().OsVariation()},
833 {"arch", "common"},
834 }, testForTag, testFor...)
835 }
836 }
837}
838
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900839// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700840func apexTestForMutator(mctx android.BottomUpMutatorContext) {
841 if !mctx.Module().Enabled() {
842 return
843 }
Colin Cross56a83212020-09-15 18:30:11 -0700844 if _, ok := mctx.Module().(android.ApexModule); ok {
845 var contents []*android.ApexContents
846 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
847 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
848 contents = append(contents, abInfo.Contents)
849 }
850 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
851 ApexContents: contents,
852 })
Colin Crossaede88c2020-08-11 12:17:01 -0700853 }
854}
855
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900856// markPlatformAvailability marks whether or not a module can be available to platform. A module
857// cannot be available to platform if 1) it is explicitly marked as not available (i.e.
858// "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't
859// be) available to platform
860// TODO(jiyong): move this to android/apex.go?
Jiyong Park89e850a2020-04-07 16:37:39 +0900861func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
862 // Host and recovery are not considered as platform
863 if mctx.Host() || mctx.Module().InstallInRecovery() {
864 return
865 }
866
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900867 am, ok := mctx.Module().(android.ApexModule)
868 if !ok {
869 return
870 }
Jiyong Park89e850a2020-04-07 16:37:39 +0900871
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900872 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
Jiyong Park89e850a2020-04-07 16:37:39 +0900873
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900874 // If any of the dep is not available to platform, this module is also considered as being
875 // not available to platform even if it has "//apex_available:platform"
876 mctx.VisitDirectDeps(func(child android.Module) {
877 if !am.DepIsInSameApex(mctx, child) {
878 // if the dependency crosses apex boundary, don't consider it
879 return
Jiyong Park89e850a2020-04-07 16:37:39 +0900880 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900881 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
882 availableToPlatform = false
883 // TODO(b/154889534) trigger an error when 'am' has
884 // "//apex_available:platform"
Jiyong Park89e850a2020-04-07 16:37:39 +0900885 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900886 })
Jiyong Park89e850a2020-04-07 16:37:39 +0900887
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900888 // Exception 1: stub libraries and native bridge libraries are always available to platform
889 if cc, ok := mctx.Module().(*cc.Module); ok &&
890 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
891 availableToPlatform = true
892 }
893
894 // Exception 2: bootstrap bionic libraries are also always available to platform
895 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
896 availableToPlatform = true
897 }
898
899 if !availableToPlatform {
900 am.SetNotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900901 }
902}
903
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900904// apexMutator visits each module and creates apex variations if the module was marked in the
905// previous run of apexDepsMutator.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900906func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900907 if !mctx.Module().Enabled() {
908 return
909 }
Colin Cross56a83212020-09-15 18:30:11 -0700910
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900911 // This is the usual path.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900912 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700913 android.CreateApexVariations(mctx, am)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900914 return
915 }
916
917 // apexBundle itself is mutated so that it and its dependencies have the same apex variant.
918 // TODO(jiyong): document the reason why the VNDK APEX is an exception here.
919 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900920 apexBundleName := mctx.ModuleName()
921 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900922 } else if o, ok := mctx.Module().(*OverrideApex); ok {
923 apexBundleName := o.GetOverriddenModuleName()
924 if apexBundleName == "" {
925 mctx.ModuleErrorf("base property is not set")
926 return
927 }
928 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900929 }
930}
Sundong Ahne9b55722019-09-06 17:37:42 +0900931
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900932// See android.UpdateDirectlyInAnyApex
933// TODO(jiyong): move this to android/apex.go?
Colin Cross56a83212020-09-15 18:30:11 -0700934func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
935 if !mctx.Module().Enabled() {
936 return
937 }
938 if am, ok := mctx.Module().(android.ApexModule); ok {
939 android.UpdateDirectlyInAnyApex(mctx, am)
940 }
941}
942
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900943// apexPackaging represents a specific packaging method for an APEX.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900944type apexPackaging int
945
946const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900947 // imageApex is a packaging method where contents are included in a filesystem image which
948 // is then included in a zip container. This is the most typical way of packaging.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900949 imageApex apexPackaging = iota
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900950
951 // zipApex is a packaging method where contents are directly included in the zip container.
952 // This is used for host-side testing - because the contents are easily accessible by
953 // unzipping the container.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900954 zipApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900955
956 // flattendApex is a packaging method where contents are not included in the APEX file, but
957 // installed to /apex/<apexname> directory on the device. This packaging method is used for
958 // old devices where the filesystem-based APEX file can't be supported.
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900959 flattenedApex
960)
961
962const (
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900963 // File extensions of an APEX for different packaging methods
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900964 imageApexSuffix = ".apex"
965 zipApexSuffix = ".zipapex"
966 flattenedSuffix = ".flattened"
967
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900968 // variant names each of which is for a packaging method
Jiyong Park8e6d52f2020-11-19 14:37:47 +0900969 imageApexType = "image"
970 zipApexType = "zip"
971 flattenedApexType = "flattened"
972
973 ext4FsType = "ext4"
974 f2fsFsType = "f2fs"
975)
976
977// The suffix for the output "file", not the module
978func (a apexPackaging) suffix() string {
979 switch a {
980 case imageApex:
981 return imageApexSuffix
982 case zipApex:
983 return zipApexSuffix
984 default:
985 panic(fmt.Errorf("unknown APEX type %d", a))
986 }
987}
988
989func (a apexPackaging) name() string {
990 switch a {
991 case imageApex:
992 return imageApexType
993 case zipApex:
994 return zipApexType
995 default:
996 panic(fmt.Errorf("unknown APEX type %d", a))
997 }
998}
999
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001000// apexFlattenedMutator creates one or more variations each of which is for a packaging method.
1001// TODO(jiyong): give a better name to this mutator
Sundong Ahne9b55722019-09-06 17:37:42 +09001002func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +09001003 if !mctx.Module().Enabled() {
1004 return
1005 }
Sundong Ahne8fb7242019-09-17 13:50:45 +09001006 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001007 var variants []string
1008 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1009 case "image":
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001010 // This is the normal case. Note that both image and flattend APEXes are
1011 // created. The image type is installed to the system partition, while the
1012 // flattened APEX is (optionally) installed to the system_ext partition.
1013 // This is mostly for GSI which has to support wide range of devices. If GSI
1014 // is installed on a newer (APEX-capable) device, the image APEX in the
1015 // system will be used. However, if the same GSI is installed on an old
1016 // device which can't support image APEX, the flattened APEX in the
1017 // system_ext partion (which still is part of GSI) is used instead.
Sundong Ahnabb64432019-10-22 13:58:29 +09001018 variants = append(variants, imageApexType, flattenedApexType)
1019 case "zip":
1020 variants = append(variants, zipApexType)
1021 case "both":
1022 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1023 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001024 mctx.PropertyErrorf("payload_type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001025 return
1026 }
1027
1028 modules := mctx.CreateLocalVariations(variants...)
1029
1030 for i, v := range variants {
1031 switch v {
1032 case imageApexType:
1033 modules[i].(*apexBundle).properties.ApexType = imageApex
1034 case zipApexType:
1035 modules[i].(*apexBundle).properties.ApexType = zipApex
1036 case flattenedApexType:
1037 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001038 // See the comment above for why system_ext.
Jooyung Han91df2082019-11-20 01:49:42 +09001039 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001040 modules[i].(*apexBundle).MakeAsSystemExt()
1041 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001042 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001043 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001044 } else if _, ok := mctx.Module().(*OverrideApex); ok {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001045 // payload_type is forcibly overridden to "image"
1046 // TODO(jiyong): is this the right decision?
Jiyong Park5d790c32019-11-15 18:40:32 +09001047 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001048 }
1049}
1050
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001051// checkUseVendorProperty checks if the use of `use_vendor` property is allowed for the given APEX.
1052// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1053// which may cause compatibility issues. (e.g. libbinder) Even though libbinder restricts its
1054// availability via 'apex_available' property and relies on yet another macro
1055// __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules to avoid
1056// similar problems.
1057func checkUseVendorProperty(ctx android.BottomUpMutatorContext, a *apexBundle) {
1058 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
1059 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1060 }
1061}
1062
Jooyung Handc782442019-11-01 03:14:38 +09001063var (
Colin Cross440e0d02020-06-11 11:32:11 -07001064 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +09001065)
1066
Colin Cross440e0d02020-06-11 11:32:11 -07001067func useVendorAllowList(config android.Config) []string {
1068 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +09001069 return []string{
1070 // swcodec uses "vendor" variants for smaller size
1071 "com.android.media.swcodec",
1072 "test_com.android.media.swcodec",
1073 }
1074 }).([]string)
1075}
1076
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001077// setUseVendorAllowListForTest overrides useVendorAllowList and must be called before the first
1078// call to useVendorAllowList()
Colin Cross440e0d02020-06-11 11:32:11 -07001079func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1080 config.Once(useVendorAllowListKey, func() interface{} {
1081 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001082 })
1083}
1084
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001085var _ android.DepIsInSameApex = (*apexBundle)(nil)
Theotime Combes4ba38c12020-06-12 12:46:59 +00001086
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001087// Implements android.DepInInSameApex
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001088func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1089 // direct deps of an APEX bundle are all part of the APEX bundle
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001090 // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag?
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001091 return true
1092}
1093
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001094var _ android.OutputFileProducer = (*apexBundle)(nil)
1095
1096// Implements android.OutputFileProducer
1097func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1098 switch tag {
Paul Duffin74f05592020-11-25 16:37:46 +00001099 case "", android.DefaultDistTag:
1100 // This is the default dist path.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001101 return android.Paths{a.outputFile}, nil
1102 default:
1103 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1104 }
1105}
1106
1107var _ cc.Coverage = (*apexBundle)(nil)
1108
1109// Implements cc.Coverage
1110func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
1111 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
1112}
1113
1114// Implements cc.Coverage
1115func (a *apexBundle) PreventInstall() {
1116 a.properties.PreventInstall = true
1117}
1118
1119// Implements cc.Coverage
1120func (a *apexBundle) HideFromMake() {
1121 a.properties.HideFromMake = true
1122}
1123
1124// Implements cc.Coverage
1125func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1126 a.properties.IsCoverageVariant = coverage
1127}
1128
1129// Implements cc.Coverage
1130func (a *apexBundle) EnableCoverageIfNeeded() {}
1131
1132var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1133
1134// Implements android.ApexBudleDepsInfoIntf
1135func (a *apexBundle) Updatable() bool {
1136 return proptools.Bool(a.properties.Updatable)
1137}
1138
1139// getCertString returns the name of the cert that should be used to sign this APEX. This is
1140// basically from the "certificate" property, but could be overridden by the device config.
Colin Cross0ea8ba82019-06-06 14:33:29 -07001141func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001142 moduleName := ctx.ModuleName()
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001143 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the
1144 // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is
1145 // overridden.
Jooyung Han27151d92019-12-16 17:45:32 +09001146 if a.vndkApex {
1147 moduleName = vndkApexName
1148 }
1149 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001150 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001151 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001152 }
1153 return String(a.properties.Certificate)
1154}
1155
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001156// See the installable property
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001157func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001158 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001159}
1160
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001161// See the test_only_no_hashtree property
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001162func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1163 return proptools.Bool(a.properties.Test_only_no_hashtree)
1164}
1165
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001166// See the test_only_unsigned_payload property
Dario Frenica913392020-04-27 18:21:11 +01001167func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1168 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1169}
1170
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001171// These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its
1172// members) can be sanitized, either forcibly, or by the global configuration. For some of the
1173// sanitizers, extra dependencies can be forcibly added as well.
Jiyong Parkda6eb592018-12-19 17:12:36 +09001174
Jiyong Parkf97782b2019-02-13 20:28:58 +09001175func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1176 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1177 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1178 }
1179}
1180
Jiyong Park388ef3f2019-01-28 19:47:32 +09001181func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001182 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1183 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001184 }
1185
1186 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001187 globalSanitizerNames := []string{}
1188 if a.Host() {
1189 globalSanitizerNames = ctx.Config().SanitizeHost()
1190 } else {
1191 arches := ctx.Config().SanitizeDeviceArch()
1192 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1193 globalSanitizerNames = ctx.Config().SanitizeDevice()
1194 }
1195 }
1196 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001197}
1198
Jooyung Han8ce8db92020-05-15 19:05:05 +09001199func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001200 // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go
1201 // Keep only the mechanism here.
Jooyung Han8ce8db92020-05-15 19:05:05 +09001202 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001203 imageVariation := a.getImageVariation(ctx)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001204 for _, target := range ctx.MultiTargets() {
1205 if target.Arch.ArchType.Multilib == "lib64" {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001206 addDependenciesForNativeModules(ctx, ApexNativeDependencies{
1207 Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"},
1208 Tests: nil,
1209 Jni_libs: nil,
1210 Binaries: nil,
1211 }, target, imageVariation)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001212 break
1213 }
1214 }
1215 }
1216}
1217
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001218// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
1219// returned apexFile saves information about the Soong module that will be used for creating the
1220// build rules.
Jiyong Park1833cef2019-12-13 13:28:36 +09001221func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001222 // Decide the APEX-local directory by the multilib of the library In the future, we may
1223 // query this to the module.
1224 // TODO(jiyong): use the new PackagingSpec
Jiyong Parkf653b052019-11-18 15:39:01 +09001225 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001226 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001227 case "lib32":
1228 dirInApex = "lib"
1229 case "lib64":
1230 dirInApex = "lib64"
1231 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001232 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001233 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001234 }
Jooyung Han35155c42020-02-06 17:33:20 +09001235 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001236 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001237 // Special case for Bionic libs and other libs installed with them. This is to
1238 // prevent those libs from being included in the search path
1239 // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs
1240 // in the Runtime APEX are available via the legacy paths in /system/lib/. By the
1241 // init process, the libs in the APEX are bind-mounted to the legacy paths and thus
1242 // will be loaded into the default linker namespace (aka "platform" namespace). If
1243 // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will
1244 // be loaded again into the runtime linker namespace, which will result in double
1245 // loading of them, which isn't supported.
Martin Stjernholm279de572019-09-10 23:18:20 +01001246 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001247 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001248
Jiyong Parkf653b052019-11-18 15:39:01 +09001249 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001250 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1251 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001252}
1253
Jiyong Park1833cef2019-12-13 13:28:36 +09001254func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001255 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001256 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001257 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001258 }
Jooyung Han35155c42020-02-06 17:33:20 +09001259 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001260 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001261 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1262 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001263 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001264 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001265 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001266}
1267
Jiyong Park1833cef2019-12-13 13:28:36 +09001268func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001269 dirInApex := "bin"
1270 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001271 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001272}
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001273
Jiyong Park1833cef2019-12-13 13:28:36 +09001274func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001275 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001276 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1277 if err != nil {
1278 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001279 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001280 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001281 fileToCopy := android.PathForOutput(ctx, s)
1282 // NB: Since go binaries are static we don't need the module for anything here, which is
1283 // good since the go tool is a blueprint.Module not an android.Module like we would
1284 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001285 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001286}
1287
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001288func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001289 dirInApex := filepath.Join("bin", sh.SubDir())
1290 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001291 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001292 af.symlinks = sh.Symlinks()
1293 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001294}
1295
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001296func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001297 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001298 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001299 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001300}
1301
atrost6e126252020-01-27 17:01:16 +00001302func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1303 dirInApex := filepath.Join("etc", config.SubDir())
1304 fileToCopy := config.CompatConfig()
1305 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1306}
1307
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001308// javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same
1309// way.
1310type javaModule interface {
1311 android.Module
1312 BaseModuleName() string
1313 DexJarBuildPath() android.Path
1314 JacocoReportClassesFile() android.Path
1315 LintDepSets() java.LintDepSets
1316 Stem() string
1317}
1318
1319var _ javaModule = (*java.Library)(nil)
1320var _ javaModule = (*java.SdkLibrary)(nil)
1321var _ javaModule = (*java.DexImport)(nil)
1322var _ javaModule = (*java.SdkLibraryImport)(nil)
1323
1324func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
1325 dirInApex := "javalib"
1326 fileToCopy := module.DexJarBuildPath()
1327 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1328 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1329 af.lintDepSets = module.LintDepSets()
1330 af.customStem = module.Stem() + ".jar"
1331 return af
1332}
1333
1334// androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in
1335// the same way.
1336type androidApp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001337 android.Module
1338 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001339 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001340 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001341 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001342 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001343 BaseModuleName() string
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001344}
1345
1346var _ androidApp = (*java.AndroidApp)(nil)
1347var _ androidApp = (*java.AndroidAppImport)(nil)
1348
1349func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001350 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001351 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001352 appDir = "priv-app"
1353 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001354 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001355 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001356 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001357 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001358 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001359
1360 if app, ok := aapp.(interface {
1361 OverriddenManifestPackageName() string
1362 }); ok {
1363 af.overriddenPackageName = app.OverriddenManifestPackageName()
1364 }
Jiyong Park618922e2020-01-08 13:35:43 +09001365 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001366}
1367
Jiyong Park69aeba92020-04-24 21:16:36 +09001368func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1369 rroDir := "overlay"
1370 dirInApex := filepath.Join(rroDir, rro.Theme())
1371 fileToCopy := rro.OutputFile()
1372 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1373 af.certificate = rro.Certificate()
1374
1375 if a, ok := rro.(interface {
1376 OverriddenManifestPackageName() string
1377 }); ok {
1378 af.overriddenPackageName = a.OverriddenManifestPackageName()
1379 }
1380 return af
1381}
1382
markchien2f59ec92020-09-02 16:23:38 +08001383func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1384 dirInApex := filepath.Join("etc", "bpf")
1385 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1386}
1387
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001388// WalyPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
1389// visited module, the `do` callback is executed. Returning true in the callback continues the visit
1390// to the child modules. Returning false makes the visit to continue in the sibling or the parent
1391// modules. This is used in check* functions below.
Jooyung Han749dc692020-04-15 11:03:39 +09001392func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001393 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001394 am, ok := child.(android.ApexModule)
1395 if !ok || !am.CanHaveApexVariants() {
1396 return false
1397 }
1398
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001399 // Filter-out unwanted depedendencies
1400 depTag := ctx.OtherModuleDependencyTag(child)
1401 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1402 return false
1403 }
1404 if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001405 return false
1406 }
1407
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001408 ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1409 externalDep := !android.InList(ctx.ModuleName(), ai.InApexes)
Jiyong Park0f80c182020-01-31 02:49:53 +09001410
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001411 // Visit actually
1412 return do(ctx, parent, am, externalDep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001413 })
1414}
1415
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001416// filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported.
1417type fsType int
Jooyung Han03b51852020-02-26 22:45:42 +09001418
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001419const (
1420 ext4 fsType = iota
1421 f2fs
1422)
Artur Satayev849f8442020-04-28 14:57:42 +01001423
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001424func (f fsType) string() string {
1425 switch f {
1426 case ext4:
1427 return ext4FsType
1428 case f2fs:
1429 return f2fsFsType
1430 default:
1431 panic(fmt.Errorf("unknown APEX payload type %d", f))
Jooyung Han548640b2020-04-27 12:10:30 +09001432 }
1433}
1434
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001435// Creates build rules for an APEX. It consists of the following major steps:
1436//
1437// 1) do some validity checks such as apex_available, min_sdk_version, etc.
1438// 2) traverse the dependency tree to collect apexFile structs from them.
1439// 3) some fields in apexBundle struct are configured
1440// 4) generate the build rules to create the APEX. This is mostly done in builder.go.
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001441func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001442 ////////////////////////////////////////////////////////////////////////////////////////////
1443 // 1) do some validity checks such as apex_available, min_sdk_version, etc.
Jiyong Park0f80c182020-01-31 02:49:53 +09001444 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001445 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09001446 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001447 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001448 if len(a.properties.Tests) > 0 && !a.testApex {
1449 ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
1450 return
1451 }
Jiyong Park678c8812020-02-07 17:25:49 +09001452
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001453 ////////////////////////////////////////////////////////////////////////////////////////////
1454 // 2) traverse the dependency tree to collect apexFile structs from them.
1455
1456 // all the files that will be included in this APEX
1457 var filesInfo []apexFile
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001458
Jooyung Hane1633032019-08-01 17:41:43 +09001459 // native lib dependencies
1460 var provideNativeLibs []string
1461 var requireNativeLibs []string
1462
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001463 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1464
1465 // TODO(jiyong): do this using WalkPayloadDeps
1466 // TODO(jiyong): make this clean!!!
Alex Light778127a2019-02-27 14:19:50 -08001467 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001468 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001469 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1470 return false
1471 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001472 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001473 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001474 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001475 case sharedLibTag, jniLibTag:
1476 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001477 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001478 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1479 fi.isJniLib = isJniLib
1480 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09001481 // Collect the list of stub-providing libs except:
1482 // - VNDK libs are only for vendors
1483 // - bootstrap bionic libs are treated as provided by system
1484 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001485 provideNativeLibs = append(provideNativeLibs, fi.stem())
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001486 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001487 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001488 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001489 propertyName := "native_shared_libs"
1490 if isJniLib {
1491 propertyName = "jni_libs"
1492 }
1493 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001494 }
1495 case executableTag:
1496 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001497 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001498 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001499 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001500 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001501 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001502 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001503 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001504 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001505 } else {
Alex Light778127a2019-02-27 14:19:50 -08001506 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 +09001507 }
1508 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001509 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01001510 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001511 af := apexFileForJavaModule(ctx, child.(javaModule))
1512 if !af.ok() {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001513 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1514 return false
1515 }
1516 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001517 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001518 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001519 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001520 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001521 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001522 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001523 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001524 return true // track transitive dependencies
1525 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001526 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001527 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001528 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001529 } else if ap, ok := child.(*java.AndroidAppSet); ok {
1530 appDir := "app"
1531 if ap.Privileged() {
1532 appDir = "priv-app"
1533 }
Yo Chiange8128052020-07-23 20:09:18 +08001534 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001535 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
1536 af.certificate = java.PresignedCertificate
1537 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09001538 } else {
1539 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1540 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001541 case rroTag:
1542 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1543 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1544 } else {
1545 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1546 }
markchien2f59ec92020-09-02 16:23:38 +08001547 case bpfTag:
1548 if bpfProgram, ok := child.(bpf.BpfModule); ok {
1549 filesToCopy, _ := bpfProgram.OutputFiles("")
1550 for _, bpfFile := range filesToCopy {
1551 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
1552 }
1553 } else {
1554 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
1555 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001556 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001557 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001558 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001559 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1560 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001561 } else {
atrost6e126252020-01-27 17:01:16 +00001562 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001563 }
Roland Levillain630846d2019-06-26 12:48:34 +01001564 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001565 if ccTest, ok := child.(*cc.Module); ok {
1566 if ccTest.IsTestPerSrcAllTestsVariation() {
1567 // Multiple-output test module (where `test_per_src: true`).
1568 //
1569 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1570 // We do not add this variation to `filesInfo`, as it has no output;
1571 // however, we do add the other variations of this module as indirect
1572 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01001573 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001574 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001575 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001576 af.class = nativeTest
1577 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001578 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09001579 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01001580 } else {
1581 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1582 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001583 case keyTag:
1584 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001585 a.private_key_file = key.private_key_file
1586 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001587 } else {
1588 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001589 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001590 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001591 case certificateTag:
1592 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001593 a.container_certificate_file = dep.Certificate.Pem
1594 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001595 } else {
1596 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1597 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001598 case android.PrebuiltDepTag:
1599 // If the prebuilt is force disabled, remember to delete the prebuilt file
1600 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09001601 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09001602 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1603 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001604 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001605 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001606 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001607 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001608 // We cannot use a switch statement on `depTag` here as the checked
1609 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001610 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001611 if cc, ok := child.(*cc.Module); ok {
Jooyung Handf78e212020-07-22 15:54:47 +09001612 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09001613 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09001614 return false
1615 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001616 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
1617 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07001618 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1619 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001620 // If the dependency is a stubs lib, don't include it in this APEX,
1621 // but make sure that the lib is installed on the device.
1622 // In case no APEX is having the lib, the lib is installed to the system
1623 // partition.
1624 //
1625 // Always include if we are a host-apex however since those won't have any
1626 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07001627 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001628 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07001629 name := cc.ImplementationModuleName(ctx)
1630
1631 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09001632 // we don't use subName(.vendor) for a "use_vendor: true" apex
1633 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07001634 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09001635 }
1636 if !android.InList(name, a.requiredDeps) {
1637 a.requiredDeps = append(a.requiredDeps, name)
1638 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001639 }
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001640 requireNativeLibs = append(requireNativeLibs, af.stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01001641 // Don't track further
1642 return false
1643 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001644 filesInfo = append(filesInfo, af)
1645 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001646 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001647 } else if cc.IsTestPerSrcDepTag(depTag) {
1648 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001649 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001650 // Handle modules created as `test_per_src` variations of a single test module:
1651 // use the name of the generated test binary (`fileToCopy`) instead of the name
1652 // of the original test module (`depName`, shared by all `test_per_src`
1653 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08001654 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001655 // these are not considered transitive dep
1656 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001657 filesInfo = append(filesInfo, af)
1658 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001659 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001660 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09001661 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
1662 return false
Jiyong Parke3833882020-02-17 17:28:10 +09001663 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001664 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09001665 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
1666 }
Colin Cross56a83212020-09-15 18:30:11 -07001667 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
1668 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09001669 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09001670 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001671 }
1672 }
1673 }
1674 return false
1675 })
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001676 if a.private_key_file == nil {
1677 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1678 return
1679 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001680
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001681 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. Build rules are
1682 // generated by the dexpreopt singleton, and here we access build artifacts via the global
1683 // boot image config.
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001684 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00001685 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001686 dirInApex := filepath.Join("javalib", arch.String())
1687 for _, f := range files {
1688 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001689 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001690 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001691 }
1692 }
1693 }
1694
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001695 // Remove duplicates in filesInfo
Jiyong Park8fd61922018-11-08 02:50:25 +09001696 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001697 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001698 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001699 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001700 if e, ok := encountered[dest]; !ok {
1701 encountered[dest] = f
1702 } else {
1703 // If a module is directly included and also transitively depended on
1704 // consider it as directly included.
1705 e.transitiveDep = e.transitiveDep && f.transitiveDep
1706 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001707 }
1708 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001709 var result []apexFile
1710 for _, v := range encountered {
1711 result = append(result, v)
1712 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001713 return result
1714 }
1715 filesInfo = removeDup(filesInfo)
1716
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001717 // Sort to have consistent build rules
Jiyong Park8fd61922018-11-08 02:50:25 +09001718 sort.Slice(filesInfo, func(i, j int) bool {
1719 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1720 })
1721
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001722 ////////////////////////////////////////////////////////////////////////////////////////////
1723 // 3) some fields in apexBundle struct are configured
Jiyong Park8fd61922018-11-08 02:50:25 +09001724 a.installDir = android.PathForModuleInstall(ctx, "apex")
1725 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001726
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001727 // Set suffix and primaryApexType depending on the ApexType
1728 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
1729 switch a.properties.ApexType {
1730 case imageApex:
1731 if buildFlattenedAsDefault {
1732 a.suffix = imageApexSuffix
1733 } else {
1734 a.suffix = ""
1735 a.primaryApexType = true
1736
1737 if ctx.Config().InstallExtraFlattenedApexes() {
1738 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
1739 }
1740 }
1741 case zipApex:
1742 if proptools.String(a.properties.Payload_type) == "zip" {
1743 a.suffix = ""
1744 a.primaryApexType = true
1745 } else {
1746 a.suffix = zipApexSuffix
1747 }
1748 case flattenedApex:
1749 if buildFlattenedAsDefault {
1750 a.suffix = ""
1751 a.primaryApexType = true
1752 } else {
1753 a.suffix = flattenedSuffix
1754 }
1755 }
1756
Theotime Combes4ba38c12020-06-12 12:46:59 +00001757 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
1758 case ext4FsType:
1759 a.payloadFsType = ext4
1760 case f2fsFsType:
1761 a.payloadFsType = f2fs
1762 default:
1763 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
1764 }
1765
Jiyong Park7cd10e32020-01-14 09:22:18 +09001766 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1767 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1768 // the same library in the system partition, thus effectively sharing the same libraries
1769 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1770 // in the APEX.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001771 a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() && !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001772
Jooyung Han85d61762020-06-24 23:50:26 +09001773 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
1774 // So we can't link them to /system/lib libs which are core variants.
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001775 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001776 a.linkToSystemLib = false
1777 }
1778
Jiyong Park9d677202020-02-19 16:29:35 +09001779 // We don't need the optimization for updatable APEXes, as it might give false signal
1780 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01001781 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09001782 a.linkToSystemLib = false
1783 }
1784
Jiyong Park638d30e2020-02-26 18:27:19 +09001785 // We also don't want the optimization for host APEXes, because it doesn't make sense.
1786 if ctx.Host() {
1787 a.linkToSystemLib = false
1788 }
1789
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001790 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
1791
1792 ////////////////////////////////////////////////////////////////////////////////////////////
1793 // 4) generate the build rules to create the APEX. This is done in builder.go.
1794 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001795 if a.properties.ApexType == flattenedApex {
1796 a.buildFlattenedApex(ctx)
1797 } else {
1798 a.buildUnflattenedApex(ctx)
1799 }
Jiyong Park956305c2020-01-09 12:32:06 +09001800 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07001801 a.buildLintReports(ctx)
Anton Hansson82d502a2020-11-11 12:33:14 +00001802 a.distFiles = a.GenerateTaggedDistFiles(ctx)
Jiyong Parkb81b9902020-11-24 19:51:18 +09001803
1804 // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well.
1805 if a.installable() {
1806 // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied
1807 // along with other ordinary files. (Note that this is done by apexer for
1808 // non-flattened APEXes)
1809 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
1810
1811 // Place the public key as apex_pubkey. This is also done by apexer for
1812 // non-flattened APEXes case.
1813 // TODO(jiyong): Why do we need this CP rule?
1814 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1815 ctx.Build(pctx, android.BuildParams{
1816 Rule: android.Cp,
1817 Input: a.public_key_file,
1818 Output: copiedPubkey,
1819 })
1820 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
1821 }
Jooyung Han01a3ee22019-11-02 02:52:25 +09001822}
1823
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001824///////////////////////////////////////////////////////////////////////////////////////////////////
1825// Factory functions
1826//
1827
1828func newApexBundle() *apexBundle {
1829 module := &apexBundle{}
1830
1831 module.AddProperties(&module.properties)
1832 module.AddProperties(&module.targetProperties)
1833 module.AddProperties(&module.overridableProperties)
1834
1835 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
1836 android.InitDefaultableModule(module)
1837 android.InitSdkAwareModule(module)
1838 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
1839 return module
1840}
1841
1842func ApexBundleFactory(testApex bool, artApex bool) android.Module {
1843 bundle := newApexBundle()
1844 bundle.testApex = testApex
1845 bundle.artApex = artApex
1846 return bundle
1847}
1848
1849// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
1850// certain compatibility checks such as apex_available are not done for apex_test.
1851func testApexBundleFactory() android.Module {
1852 bundle := newApexBundle()
1853 bundle.testApex = true
1854 return bundle
1855}
1856
1857// apex packages other modules into an APEX file which is a packaging format for system-level
1858// components like binaries, shared libraries, etc.
1859func BundleFactory() android.Module {
1860 return newApexBundle()
1861}
1862
1863type Defaults struct {
1864 android.ModuleBase
1865 android.DefaultsModuleBase
1866}
1867
1868// apex_defaults provides defaultable properties to other apex modules.
1869func defaultsFactory() android.Module {
1870 return DefaultsFactory()
1871}
1872
1873func DefaultsFactory(props ...interface{}) android.Module {
1874 module := &Defaults{}
1875
1876 module.AddProperties(props...)
1877 module.AddProperties(
1878 &apexBundleProperties{},
1879 &apexTargetBundleProperties{},
1880 &overridableProperties{},
1881 )
1882
1883 android.InitDefaultsModule(module)
1884 return module
1885}
1886
1887type OverrideApex struct {
1888 android.ModuleBase
1889 android.OverrideModuleBase
1890}
1891
1892func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1893 // All the overrides happen in the base module.
1894}
1895
1896// override_apex is used to create an apex module based on another apex module by overriding some of
1897// its properties.
1898func overrideApexFactory() android.Module {
1899 m := &OverrideApex{}
1900
1901 m.AddProperties(&overridableProperties{})
1902
1903 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1904 android.InitOverrideModule(m)
1905 return m
1906}
1907
1908///////////////////////////////////////////////////////////////////////////////////////////////////
1909// Vality check routines
1910//
1911// These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when
1912// certain conditions are not met.
1913//
1914// TODO(jiyong): move these checks to a separate go file.
1915
1916// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
1917// of this apexBundle.
1918func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1919 if a.testApex || a.vndkApex {
1920 return
1921 }
1922 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1923 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1924 return
1925 }
1926 // apexBundle::minSdkVersion reports its own errors.
1927 minSdkVersion := a.minSdkVersion(ctx)
1928 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
1929}
1930
1931func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
1932 ver := proptools.String(a.properties.Min_sdk_version)
1933 if ver == "" {
1934 return android.FutureApiLevel
1935 }
1936 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
1937 if err != nil {
1938 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
1939 return android.NoneApiLevel
1940 }
1941 if apiLevel.IsPreview() {
1942 // All codenames should build against "current".
1943 return android.FutureApiLevel
1944 }
1945 return apiLevel
1946}
1947
1948// Ensures that a lib providing stub isn't statically linked
1949func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1950 // Practically, we only care about regular APEXes on the device.
1951 if ctx.Host() || a.testApex || a.vndkApex {
1952 return
1953 }
1954
1955 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
1956
1957 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1958 if ccm, ok := to.(*cc.Module); ok {
1959 apexName := ctx.ModuleName()
1960 fromName := ctx.OtherModuleName(from)
1961 toName := ctx.OtherModuleName(to)
1962
1963 // If `to` is not actually in the same APEX as `from` then it does not need
1964 // apex_available and neither do any of its dependencies.
1965 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1966 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1967 return false
1968 }
1969
1970 // The dynamic linker and crash_dump tool in the runtime APEX is the only
1971 // exception to this rule. It can't make the static dependencies dynamic
1972 // because it can't do the dynamic linking for itself.
1973 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1974 return false
1975 }
1976
1977 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
1978 if isStubLibraryFromOtherApex && !externalDep {
1979 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1980 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1981 }
1982
1983 }
1984 return true
1985 })
1986}
1987
Artur Satayev8cf899a2020-04-15 17:29:42 +01001988// Enforce that Java deps of the apex are using stable SDKs to compile
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001989func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1990 if a.Updatable() {
1991 if String(a.properties.Min_sdk_version) == "" {
1992 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1993 }
1994 a.checkJavaStableSdkVersion(ctx)
1995 }
1996}
1997
Artur Satayev8cf899a2020-04-15 17:29:42 +01001998func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09001999 // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs,
2000 // java's checkLinkType guarantees correct usage for transitive deps
Artur Satayev8cf899a2020-04-15 17:29:42 +01002001 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2002 tag := ctx.OtherModuleDependencyTag(module)
2003 switch tag {
2004 case javaLibTag, androidAppTag:
2005 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2006 if err := m.CheckStableSdkVersion(); err != nil {
2007 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2008 }
2009 }
2010 }
2011 })
2012}
2013
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002014// Ensures that the all the dependencies are marked as available for this APEX
2015func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2016 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2017 if ctx.Host() || a.testApex || a.vndkApex {
2018 return
2019 }
2020
2021 // Because APEXes targeting other than system/system_ext partitions can't set
2022 // apex_available, we skip checks for these APEXes
2023 if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
2024 return
2025 }
2026
2027 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2028 // Requiring them and their transitive depencies with apex_available is not right
2029 // because they just add noise.
2030 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2031 return
2032 }
2033
2034 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
2035 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2036 if externalDep {
2037 return false
2038 }
2039
2040 apexName := ctx.ModuleName()
2041 fromName := ctx.OtherModuleName(from)
2042 toName := ctx.OtherModuleName(to)
2043
2044 // If `to` is not actually in the same APEX as `from` then it does not need
2045 // apex_available and neither do any of its dependencies.
2046 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2047 // As soon as the dependency graph crosses the APEX boundary, don't go
2048 // further.
2049 return false
2050 }
2051
2052 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
2053 return true
2054 }
2055 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'. Dependency path:%s",
2056 fromName, toName, ctx.GetPathString(true))
2057 // Visit this module's dependencies to check and report any issues with their availability.
2058 return true
2059 })
2060}
2061
2062var (
2063 apexAvailBaseline = makeApexAvailableBaseline()
2064 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
2065)
2066
Colin Cross440e0d02020-06-11 11:32:11 -07002067func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002068 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002069 moduleName = normalizeModuleName(moduleName)
2070
Colin Cross440e0d02020-06-11 11:32:11 -07002071 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002072 return true
2073 }
2074
2075 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002076 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002077 return true
2078 }
2079
2080 return false
2081}
2082
2083func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002084 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2085 // system. Trim the prefix for the check since they are confusing
2086 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2087 if strings.HasPrefix(moduleName, "libclang_rt.") {
2088 // This module has many arch variants that depend on the product being built.
2089 // We don't want to list them all
2090 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002091 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002092 if strings.HasPrefix(moduleName, "androidx.") {
2093 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2094 moduleName = "androidx"
2095 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002096 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002097}
2098
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002099// Transform the map of apex -> modules to module -> apexes.
2100func invertApexBaseline(m map[string][]string) map[string][]string {
2101 r := make(map[string][]string)
2102 for apex, modules := range m {
2103 for _, module := range modules {
2104 r[module] = append(r[module], apex)
2105 }
2106 }
2107 return r
2108}
2109
2110// Retrieve the baseline of apexes to which the supplied module belongs.
2111func BaselineApexAvailable(moduleName string) []string {
2112 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
2113}
2114
Jiyong Parkc0ec6f92020-11-19 23:00:52 +09002115// This is a map from apex to modules, which overrides the apex_available setting for that
2116// particular module to make it available for the apex regardless of its setting.
Jiyong Park8e6d52f2020-11-19 14:37:47 +09002117// TODO(b/147364041): remove this
2118func makeApexAvailableBaseline() map[string][]string {
2119 // The "Module separator"s below are employed to minimize merge conflicts.
2120 m := make(map[string][]string)
2121 //
2122 // Module separator
2123 //
2124 m["com.android.appsearch"] = []string{
2125 "icing-java-proto-lite",
2126 "libprotobuf-java-lite",
2127 }
2128 //
2129 // Module separator
2130 //
2131 m["com.android.bluetooth.updatable"] = []string{
2132 "android.hardware.audio.common@5.0",
2133 "android.hardware.bluetooth.a2dp@1.0",
2134 "android.hardware.bluetooth.audio@2.0",
2135 "android.hardware.bluetooth@1.0",
2136 "android.hardware.bluetooth@1.1",
2137 "android.hardware.graphics.bufferqueue@1.0",
2138 "android.hardware.graphics.bufferqueue@2.0",
2139 "android.hardware.graphics.common@1.0",
2140 "android.hardware.graphics.common@1.1",
2141 "android.hardware.graphics.common@1.2",
2142 "android.hardware.media@1.0",
2143 "android.hidl.safe_union@1.0",
2144 "android.hidl.token@1.0",
2145 "android.hidl.token@1.0-utils",
2146 "avrcp-target-service",
2147 "avrcp_headers",
2148 "bluetooth-protos-lite",
2149 "bluetooth.mapsapi",
2150 "com.android.vcard",
2151 "dnsresolver_aidl_interface-V2-java",
2152 "ipmemorystore-aidl-interfaces-V5-java",
2153 "ipmemorystore-aidl-interfaces-java",
2154 "internal_include_headers",
2155 "lib-bt-packets",
2156 "lib-bt-packets-avrcp",
2157 "lib-bt-packets-base",
2158 "libFraunhoferAAC",
2159 "libaudio-a2dp-hw-utils",
2160 "libaudio-hearing-aid-hw-utils",
2161 "libbinder_headers",
2162 "libbluetooth",
2163 "libbluetooth-types",
2164 "libbluetooth-types-header",
2165 "libbluetooth_gd",
2166 "libbluetooth_headers",
2167 "libbluetooth_jni",
2168 "libbt-audio-hal-interface",
2169 "libbt-bta",
2170 "libbt-common",
2171 "libbt-hci",
2172 "libbt-platform-protos-lite",
2173 "libbt-protos-lite",
2174 "libbt-sbc-decoder",
2175 "libbt-sbc-encoder",
2176 "libbt-stack",
2177 "libbt-utils",
2178 "libbtcore",
2179 "libbtdevice",
2180 "libbte",
2181 "libbtif",
2182 "libchrome",
2183 "libevent",
2184 "libfmq",
2185 "libg722codec",
2186 "libgui_headers",
2187 "libmedia_headers",
2188 "libmodpb64",
2189 "libosi",
2190 "libstagefright_foundation_headers",
2191 "libstagefright_headers",
2192 "libstatslog",
2193 "libstatssocket",
2194 "libtinyxml2",
2195 "libudrv-uipc",
2196 "libz",
2197 "media_plugin_headers",
2198 "net-utils-services-common",
2199 "netd_aidl_interface-unstable-java",
2200 "netd_event_listener_interface-java",
2201 "netlink-client",
2202 "networkstack-client",
2203 "sap-api-java-static",
2204 "services.net",
2205 }
2206 //
2207 // Module separator
2208 //
2209 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
2210 //
2211 // Module separator
2212 //
2213 m["com.android.extservices"] = []string{
2214 "error_prone_annotations",
2215 "ExtServices-core",
2216 "ExtServices",
2217 "libtextclassifier-java",
2218 "libz_current",
2219 "textclassifier-statsd",
2220 "TextClassifierNotificationLibNoManifest",
2221 "TextClassifierServiceLibNoManifest",
2222 }
2223 //
2224 // Module separator
2225 //
2226 m["com.android.neuralnetworks"] = []string{
2227 "android.hardware.neuralnetworks@1.0",
2228 "android.hardware.neuralnetworks@1.1",
2229 "android.hardware.neuralnetworks@1.2",
2230 "android.hardware.neuralnetworks@1.3",
2231 "android.hidl.allocator@1.0",
2232 "android.hidl.memory.token@1.0",
2233 "android.hidl.memory@1.0",
2234 "android.hidl.safe_union@1.0",
2235 "libarect",
2236 "libbuildversion",
2237 "libmath",
2238 "libprocpartition",
2239 "libsync",
2240 }
2241 //
2242 // Module separator
2243 //
2244 m["com.android.media"] = []string{
2245 "android.frameworks.bufferhub@1.0",
2246 "android.hardware.cas.native@1.0",
2247 "android.hardware.cas@1.0",
2248 "android.hardware.configstore-utils",
2249 "android.hardware.configstore@1.0",
2250 "android.hardware.configstore@1.1",
2251 "android.hardware.graphics.allocator@2.0",
2252 "android.hardware.graphics.allocator@3.0",
2253 "android.hardware.graphics.bufferqueue@1.0",
2254 "android.hardware.graphics.bufferqueue@2.0",
2255 "android.hardware.graphics.common@1.0",
2256 "android.hardware.graphics.common@1.1",
2257 "android.hardware.graphics.common@1.2",
2258 "android.hardware.graphics.mapper@2.0",
2259 "android.hardware.graphics.mapper@2.1",
2260 "android.hardware.graphics.mapper@3.0",
2261 "android.hardware.media.omx@1.0",
2262 "android.hardware.media@1.0",
2263 "android.hidl.allocator@1.0",
2264 "android.hidl.memory.token@1.0",
2265 "android.hidl.memory@1.0",
2266 "android.hidl.token@1.0",
2267 "android.hidl.token@1.0-utils",
2268 "bionic_libc_platform_headers",
2269 "exoplayer2-extractor",
2270 "exoplayer2-extractor-annotation-stubs",
2271 "gl_headers",
2272 "jsr305",
2273 "libEGL",
2274 "libEGL_blobCache",
2275 "libEGL_getProcAddress",
2276 "libFLAC",
2277 "libFLAC-config",
2278 "libFLAC-headers",
2279 "libGLESv2",
2280 "libaacextractor",
2281 "libamrextractor",
2282 "libarect",
2283 "libaudio_system_headers",
2284 "libaudioclient",
2285 "libaudioclient_headers",
2286 "libaudiofoundation",
2287 "libaudiofoundation_headers",
2288 "libaudiomanager",
2289 "libaudiopolicy",
2290 "libaudioutils",
2291 "libaudioutils_fixedfft",
2292 "libbinder_headers",
2293 "libbluetooth-types-header",
2294 "libbufferhub",
2295 "libbufferhub_headers",
2296 "libbufferhubqueue",
2297 "libc_malloc_debug_backtrace",
2298 "libcamera_client",
2299 "libcamera_metadata",
2300 "libdvr_headers",
2301 "libexpat",
2302 "libfifo",
2303 "libflacextractor",
2304 "libgrallocusage",
2305 "libgraphicsenv",
2306 "libgui",
2307 "libgui_headers",
2308 "libhardware_headers",
2309 "libinput",
2310 "liblzma",
2311 "libmath",
2312 "libmedia",
2313 "libmedia_codeclist",
2314 "libmedia_headers",
2315 "libmedia_helper",
2316 "libmedia_helper_headers",
2317 "libmedia_midiiowrapper",
2318 "libmedia_omx",
2319 "libmediautils",
2320 "libmidiextractor",
2321 "libmkvextractor",
2322 "libmp3extractor",
2323 "libmp4extractor",
2324 "libmpeg2extractor",
2325 "libnativebase_headers",
2326 "libnativewindow_headers",
2327 "libnblog",
2328 "liboggextractor",
2329 "libpackagelistparser",
2330 "libpdx",
2331 "libpdx_default_transport",
2332 "libpdx_headers",
2333 "libpdx_uds",
2334 "libprocinfo",
2335 "libspeexresampler",
2336 "libspeexresampler",
2337 "libstagefright_esds",
2338 "libstagefright_flacdec",
2339 "libstagefright_flacdec",
2340 "libstagefright_foundation",
2341 "libstagefright_foundation_headers",
2342 "libstagefright_foundation_without_imemory",
2343 "libstagefright_headers",
2344 "libstagefright_id3",
2345 "libstagefright_metadatautils",
2346 "libstagefright_mpeg2extractor",
2347 "libstagefright_mpeg2support",
2348 "libsync",
2349 "libui",
2350 "libui_headers",
2351 "libunwindstack",
2352 "libvibrator",
2353 "libvorbisidec",
2354 "libwavextractor",
2355 "libwebm",
2356 "media_ndk_headers",
2357 "media_plugin_headers",
2358 "updatable-media",
2359 }
2360 //
2361 // Module separator
2362 //
2363 m["com.android.media.swcodec"] = []string{
2364 "android.frameworks.bufferhub@1.0",
2365 "android.hardware.common-ndk_platform",
2366 "android.hardware.configstore-utils",
2367 "android.hardware.configstore@1.0",
2368 "android.hardware.configstore@1.1",
2369 "android.hardware.graphics.allocator@2.0",
2370 "android.hardware.graphics.allocator@3.0",
2371 "android.hardware.graphics.allocator@4.0",
2372 "android.hardware.graphics.bufferqueue@1.0",
2373 "android.hardware.graphics.bufferqueue@2.0",
2374 "android.hardware.graphics.common-ndk_platform",
2375 "android.hardware.graphics.common@1.0",
2376 "android.hardware.graphics.common@1.1",
2377 "android.hardware.graphics.common@1.2",
2378 "android.hardware.graphics.mapper@2.0",
2379 "android.hardware.graphics.mapper@2.1",
2380 "android.hardware.graphics.mapper@3.0",
2381 "android.hardware.graphics.mapper@4.0",
2382 "android.hardware.media.bufferpool@2.0",
2383 "android.hardware.media.c2@1.0",
2384 "android.hardware.media.c2@1.1",
2385 "android.hardware.media.omx@1.0",
2386 "android.hardware.media@1.0",
2387 "android.hardware.media@1.0",
2388 "android.hidl.memory.token@1.0",
2389 "android.hidl.memory@1.0",
2390 "android.hidl.safe_union@1.0",
2391 "android.hidl.token@1.0",
2392 "android.hidl.token@1.0-utils",
2393 "libEGL",
2394 "libFLAC",
2395 "libFLAC-config",
2396 "libFLAC-headers",
2397 "libFraunhoferAAC",
2398 "libLibGuiProperties",
2399 "libarect",
2400 "libaudio_system_headers",
2401 "libaudioutils",
2402 "libaudioutils",
2403 "libaudioutils_fixedfft",
2404 "libavcdec",
2405 "libavcenc",
2406 "libavservices_minijail",
2407 "libavservices_minijail",
2408 "libbinder_headers",
2409 "libbinderthreadstateutils",
2410 "libbluetooth-types-header",
2411 "libbufferhub_headers",
2412 "libcodec2",
2413 "libcodec2_headers",
2414 "libcodec2_hidl@1.0",
2415 "libcodec2_hidl@1.1",
2416 "libcodec2_internal",
2417 "libcodec2_soft_aacdec",
2418 "libcodec2_soft_aacenc",
2419 "libcodec2_soft_amrnbdec",
2420 "libcodec2_soft_amrnbenc",
2421 "libcodec2_soft_amrwbdec",
2422 "libcodec2_soft_amrwbenc",
2423 "libcodec2_soft_av1dec_gav1",
2424 "libcodec2_soft_avcdec",
2425 "libcodec2_soft_avcenc",
2426 "libcodec2_soft_common",
2427 "libcodec2_soft_flacdec",
2428 "libcodec2_soft_flacenc",
2429 "libcodec2_soft_g711alawdec",
2430 "libcodec2_soft_g711mlawdec",
2431 "libcodec2_soft_gsmdec",
2432 "libcodec2_soft_h263dec",
2433 "libcodec2_soft_h263enc",
2434 "libcodec2_soft_hevcdec",
2435 "libcodec2_soft_hevcenc",
2436 "libcodec2_soft_mp3dec",
2437 "libcodec2_soft_mpeg2dec",
2438 "libcodec2_soft_mpeg4dec",
2439 "libcodec2_soft_mpeg4enc",
2440 "libcodec2_soft_opusdec",
2441 "libcodec2_soft_opusenc",
2442 "libcodec2_soft_rawdec",
2443 "libcodec2_soft_vorbisdec",
2444 "libcodec2_soft_vp8dec",
2445 "libcodec2_soft_vp8enc",
2446 "libcodec2_soft_vp9dec",
2447 "libcodec2_soft_vp9enc",
2448 "libcodec2_vndk",
2449 "libdvr_headers",
2450 "libfmq",
2451 "libfmq",
2452 "libgav1",
2453 "libgralloctypes",
2454 "libgrallocusage",
2455 "libgraphicsenv",
2456 "libgsm",
2457 "libgui_bufferqueue_static",
2458 "libgui_headers",
2459 "libhardware",
2460 "libhardware_headers",
2461 "libhevcdec",
2462 "libhevcenc",
2463 "libion",
2464 "libjpeg",
2465 "liblzma",
2466 "libmath",
2467 "libmedia_codecserviceregistrant",
2468 "libmedia_headers",
2469 "libmpeg2dec",
2470 "libnativebase_headers",
2471 "libnativewindow_headers",
2472 "libpdx_headers",
2473 "libscudo_wrapper",
2474 "libsfplugin_ccodec_utils",
2475 "libspeexresampler",
2476 "libstagefright_amrnb_common",
2477 "libstagefright_amrnbdec",
2478 "libstagefright_amrnbenc",
2479 "libstagefright_amrwbdec",
2480 "libstagefright_amrwbenc",
2481 "libstagefright_bufferpool@2.0.1",
2482 "libstagefright_bufferqueue_helper",
2483 "libstagefright_enc_common",
2484 "libstagefright_flacdec",
2485 "libstagefright_foundation",
2486 "libstagefright_foundation_headers",
2487 "libstagefright_headers",
2488 "libstagefright_m4vh263dec",
2489 "libstagefright_m4vh263enc",
2490 "libstagefright_mp3dec",
2491 "libsync",
2492 "libui",
2493 "libui_headers",
2494 "libunwindstack",
2495 "libvorbisidec",
2496 "libvpx",
2497 "libyuv",
2498 "libyuv_static",
2499 "media_ndk_headers",
2500 "media_plugin_headers",
2501 "mediaswcodec",
2502 }
2503 //
2504 // Module separator
2505 //
2506 m["com.android.mediaprovider"] = []string{
2507 "MediaProvider",
2508 "MediaProviderGoogle",
2509 "fmtlib_ndk",
2510 "libbase_ndk",
2511 "libfuse",
2512 "libfuse_jni",
2513 }
2514 //
2515 // Module separator
2516 //
2517 m["com.android.permission"] = []string{
2518 "car-ui-lib",
2519 "iconloader",
2520 "kotlin-annotations",
2521 "kotlin-stdlib",
2522 "kotlin-stdlib-jdk7",
2523 "kotlin-stdlib-jdk8",
2524 "kotlinx-coroutines-android",
2525 "kotlinx-coroutines-android-nodeps",
2526 "kotlinx-coroutines-core",
2527 "kotlinx-coroutines-core-nodeps",
2528 "permissioncontroller-statsd",
2529 "GooglePermissionController",
2530 "PermissionController",
2531 "SettingsLibActionBarShadow",
2532 "SettingsLibAppPreference",
2533 "SettingsLibBarChartPreference",
2534 "SettingsLibLayoutPreference",
2535 "SettingsLibProgressBar",
2536 "SettingsLibSearchWidget",
2537 "SettingsLibSettingsTheme",
2538 "SettingsLibRestrictedLockUtils",
2539 "SettingsLibHelpUtils",
2540 }
2541 //
2542 // Module separator
2543 //
2544 m["com.android.runtime"] = []string{
2545 "bionic_libc_platform_headers",
2546 "libarm-optimized-routines-math",
2547 "libc_aeabi",
2548 "libc_bionic",
2549 "libc_bionic_ndk",
2550 "libc_bootstrap",
2551 "libc_common",
2552 "libc_common_shared",
2553 "libc_common_static",
2554 "libc_dns",
2555 "libc_dynamic_dispatch",
2556 "libc_fortify",
2557 "libc_freebsd",
2558 "libc_freebsd_large_stack",
2559 "libc_gdtoa",
2560 "libc_init_dynamic",
2561 "libc_init_static",
2562 "libc_jemalloc_wrapper",
2563 "libc_netbsd",
2564 "libc_nomalloc",
2565 "libc_nopthread",
2566 "libc_openbsd",
2567 "libc_openbsd_large_stack",
2568 "libc_openbsd_ndk",
2569 "libc_pthread",
2570 "libc_static_dispatch",
2571 "libc_syscalls",
2572 "libc_tzcode",
2573 "libc_unwind_static",
2574 "libdebuggerd",
2575 "libdebuggerd_common_headers",
2576 "libdebuggerd_handler_core",
2577 "libdebuggerd_handler_fallback",
2578 "libdl_static",
2579 "libjemalloc5",
2580 "liblinker_main",
2581 "liblinker_malloc",
2582 "liblz4",
2583 "liblzma",
2584 "libprocinfo",
2585 "libpropertyinfoparser",
2586 "libscudo",
2587 "libstdc++",
2588 "libsystemproperties",
2589 "libtombstoned_client_static",
2590 "libunwindstack",
2591 "libz",
2592 "libziparchive",
2593 }
2594 //
2595 // Module separator
2596 //
2597 m["com.android.tethering"] = []string{
2598 "android.hardware.tetheroffload.config-V1.0-java",
2599 "android.hardware.tetheroffload.control-V1.0-java",
2600 "android.hidl.base-V1.0-java",
2601 "libcgrouprc",
2602 "libcgrouprc_format",
2603 "libtetherutilsjni",
2604 "libvndksupport",
2605 "net-utils-framework-common",
2606 "netd_aidl_interface-V3-java",
2607 "netlink-client",
2608 "networkstack-aidl-interfaces-java",
2609 "tethering-aidl-interfaces-java",
2610 "TetheringApiCurrentLib",
2611 }
2612 //
2613 // Module separator
2614 //
2615 m["com.android.wifi"] = []string{
2616 "PlatformProperties",
2617 "android.hardware.wifi-V1.0-java",
2618 "android.hardware.wifi-V1.0-java-constants",
2619 "android.hardware.wifi-V1.1-java",
2620 "android.hardware.wifi-V1.2-java",
2621 "android.hardware.wifi-V1.3-java",
2622 "android.hardware.wifi-V1.4-java",
2623 "android.hardware.wifi.hostapd-V1.0-java",
2624 "android.hardware.wifi.hostapd-V1.1-java",
2625 "android.hardware.wifi.hostapd-V1.2-java",
2626 "android.hardware.wifi.supplicant-V1.0-java",
2627 "android.hardware.wifi.supplicant-V1.1-java",
2628 "android.hardware.wifi.supplicant-V1.2-java",
2629 "android.hardware.wifi.supplicant-V1.3-java",
2630 "android.hidl.base-V1.0-java",
2631 "android.hidl.manager-V1.0-java",
2632 "android.hidl.manager-V1.1-java",
2633 "android.hidl.manager-V1.2-java",
2634 "bouncycastle-unbundled",
2635 "dnsresolver_aidl_interface-V2-java",
2636 "error_prone_annotations",
2637 "framework-wifi-pre-jarjar",
2638 "framework-wifi-util-lib",
2639 "ipmemorystore-aidl-interfaces-V3-java",
2640 "ipmemorystore-aidl-interfaces-java",
2641 "ksoap2",
2642 "libnanohttpd",
2643 "libwifi-jni",
2644 "net-utils-services-common",
2645 "netd_aidl_interface-V2-java",
2646 "netd_aidl_interface-unstable-java",
2647 "netd_event_listener_interface-java",
2648 "netlink-client",
2649 "networkstack-client",
2650 "services.net",
2651 "wifi-lite-protos",
2652 "wifi-nano-protos",
2653 "wifi-service-pre-jarjar",
2654 "wifi-service-resources",
2655 }
2656 //
2657 // Module separator
2658 //
2659 m["com.android.sdkext"] = []string{
2660 "fmtlib_ndk",
2661 "libbase_ndk",
2662 "libprotobuf-cpp-lite-ndk",
2663 }
2664 //
2665 // Module separator
2666 //
2667 m["com.android.os.statsd"] = []string{
2668 "libstatssocket",
2669 }
2670 //
2671 // Module separator
2672 //
2673 m[android.AvailableToAnyApex] = []string{
2674 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
2675 "androidx",
2676 "androidx-constraintlayout_constraintlayout",
2677 "androidx-constraintlayout_constraintlayout-nodeps",
2678 "androidx-constraintlayout_constraintlayout-solver",
2679 "androidx-constraintlayout_constraintlayout-solver-nodeps",
2680 "com.google.android.material_material",
2681 "com.google.android.material_material-nodeps",
2682
2683 "libatomic",
2684 "libclang_rt",
2685 "libgcc_stripped",
2686 "libprofile-clang-extras",
2687 "libprofile-clang-extras_ndk",
2688 "libprofile-extras",
2689 "libprofile-extras_ndk",
2690 "libunwind_llvm",
2691 }
2692 return m
2693}
2694
2695func init() {
2696 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
2697 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
2698}
2699
2700func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
2701 rules := make([]android.Rule, 0, len(modules_packages))
2702 for module_name, module_packages := range modules_packages {
2703 permitted_packages_rule := android.NeverAllow().
2704 BootclasspathJar().
2705 With("apex_available", module_name).
2706 WithMatcher("permitted_packages", android.NotInList(module_packages)).
2707 Because("jars that are part of the " + module_name +
2708 " module may only allow these packages: " + strings.Join(module_packages, ",") +
2709 ". Please jarjar or move code around.")
2710 rules = append(rules, permitted_packages_rule)
2711 }
2712 return rules
2713}
2714
2715// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2716// Adding code to the bootclasspath in new packages will cause issues on module update.
2717func qModulesPackages() map[string][]string {
2718 return map[string][]string{
2719 "com.android.conscrypt": []string{
2720 "android.net.ssl",
2721 "com.android.org.conscrypt",
2722 },
2723 "com.android.media": []string{
2724 "android.media",
2725 },
2726 }
2727}
2728
2729// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
2730// Adding code to the bootclasspath in new packages will cause issues on module update.
2731func rModulesPackages() map[string][]string {
2732 return map[string][]string{
2733 "com.android.mediaprovider": []string{
2734 "android.provider",
2735 },
2736 "com.android.permission": []string{
2737 "android.permission",
2738 "android.app.role",
2739 "com.android.permission",
2740 "com.android.role",
2741 },
2742 "com.android.sdkext": []string{
2743 "android.os.ext",
2744 },
2745 "com.android.os.statsd": []string{
2746 "android.app",
2747 "android.os",
2748 "android.util",
2749 "com.android.internal.statsd",
2750 "com.android.server.stats",
2751 },
2752 "com.android.wifi": []string{
2753 "com.android.server.wifi",
2754 "com.android.wifi.x",
2755 "android.hardware.wifi",
2756 "android.net.wifi",
2757 },
2758 "com.android.tethering": []string{
2759 "android.net",
2760 },
2761 }
2762}