blob: 4383876da573a57bd3c9a206342162ae28630b78 [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
15package apex
16
17import (
18 "fmt"
19 "io"
20 "path/filepath"
21 "runtime"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
36var (
37 pctx = android.NewPackageContext("android/apex")
38
39 // Create a canned fs config file where all files and directories are
40 // by default set to (uid/gid/mode) = (1000/1000/0644)
41 // TODO(b/113082813) make this configurable using config.fs syntax
42 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000043 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000044 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090045 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090046 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090047 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090048 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090049
Jooyung Hane1633032019-08-01 17:41:43 +090050 injectApexDependency = pctx.StaticRule("injectApexDependency", blueprint.RuleParams{
51 Command: `rm -f $out && ${jsonmodify} $in ` +
52 `-a provideNativeLibs ${provideNativeLibs} ` +
53 `-a requireNativeLibs ${requireNativeLibs} -o $out`,
54 CommandDeps: []string{"${jsonmodify}"},
55 Description: "Inject dependency into ${out}",
56 }, "provideNativeLibs", "requireNativeLibs")
57
Jiyong Park48ca7dc2018-10-10 14:01:00 +090058 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
59 // against the binary policy using sefcontext_compiler -p <policy>.
60
61 // TODO(b/114327326): automate the generation of file_contexts
62 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
63 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010064 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090065 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090066 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067 `--file_contexts ${file_contexts} ` +
68 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080069 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090070 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090071 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
72 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000073 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010074 Rspfile: "${out}.copy_commands",
75 RspfileContent: "${copy_commands}",
76 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090077 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080078
Alex Light5098a612018-11-29 17:12:15 -080079 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
80 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010081 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080082 `APEXER_TOOL_PATH=${tool_path} ` +
83 `${apexer} --force --manifest ${manifest} ` +
84 `--payload_type zip ` +
85 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010086 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
87 Rspfile: "${out}.copy_commands",
88 RspfileContent: "${copy_commands}",
89 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080090 }, "tool_path", "image_dir", "copy_commands", "manifest")
91
Colin Crossa4925902018-11-16 11:36:28 -080092 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
93 blueprint.RuleParams{
94 Command: `${aapt2} convert --output-format proto $in -o $out`,
95 CommandDeps: []string{"${aapt2}"},
96 })
97
98 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090099 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +0000100 `apex_payload.img:apex/${abi}.img ` +
101 `apex_manifest.json:root/apex_manifest.json ` +
Jaewoong Jungb00c1fb2019-09-04 13:26:18 -0700102 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
103 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
Colin Crossa4925902018-11-16 11:36:28 -0800104 CommandDeps: []string{"${zip2zip}"},
105 Description: "app bundle",
106 }, "abi")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100107
108 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
109 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
110 Rspfile: "${out}.emit_commands",
111 RspfileContent: "${emit_commands}",
112 Description: "Emit APEX image content",
113 }, "emit_commands")
114
115 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
116 Command: `diff --unchanged-group-format='' \` +
117 `--changed-group-format='%<' \` +
118 `${image_content_file} ${whitelisted_files_file} || (` +
119 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
120 ` "To fix the build run following command:" && ` +
121 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
122 `exit 1)`,
123 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
124 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900125)
126
Alex Light5098a612018-11-29 17:12:15 -0800127var imageApexSuffix = ".apex"
128var zipApexSuffix = ".zipapex"
129
130var imageApexType = "image"
131var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900132
133type dependencyTag struct {
134 blueprint.BaseDependencyTag
135 name string
136}
137
138var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900139 sharedLibTag = dependencyTag{name: "sharedLib"}
140 executableTag = dependencyTag{name: "executable"}
141 javaLibTag = dependencyTag{name: "javaLib"}
142 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100143 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900144 keyTag = dependencyTag{name: "key"}
145 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900146 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900147 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900148)
149
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900150var (
151 whitelistNoApex = map[string][]string{
152 "apex_test_build_features": []string{"libbinder"},
153 "com.android.neuralnetworks": []string{"libbinder"},
154 "com.android.media": []string{"libbinder"},
155 "com.android.media.swcodec": []string{"libbinder"},
156 "test_com.android.media.swcodec": []string{"libbinder"},
Jooyung Han344d5432019-08-23 11:17:39 +0900157 "com.android.vndk": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900158 }
159)
160
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900161func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700162 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900163 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900164 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100165 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
166 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
167 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
168 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000169 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100170 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
171 } else {
172 return pctx.HostBinToolPath(ctx, tool).String()
173 }
174 })
175 }
176 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900177 pctx.HostBinToolVariable("avbtool", "avbtool")
178 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
179 pctx.HostBinToolVariable("merge_zips", "merge_zips")
180 pctx.HostBinToolVariable("mke2fs", "mke2fs")
181 pctx.HostBinToolVariable("resize2fs", "resize2fs")
182 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
183 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800184 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900185 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900186 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900187
Jiyong Parkd1063c12019-07-17 20:08:41 +0900188 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800189 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900190 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900191 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700192 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900193
Jooyung Han344d5432019-08-23 11:17:39 +0900194 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
195 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
196 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
197 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900198 android.PostDepsMutators(RegisterPostDepsMutators)
199}
200
201func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
202 ctx.TopDown("apex_deps", apexDepsMutator)
203 ctx.BottomUp("apex", apexMutator).Parallel()
204 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
205 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900206}
207
Jooyung Han344d5432019-08-23 11:17:39 +0900208var (
209 vndkApexListKey = android.NewOnceKey("vndkApexList")
210 vndkApexListMutex sync.Mutex
211)
212
213func vndkApexList(config android.Config) map[string]*apexBundle {
214 return config.Once(vndkApexListKey, func() interface{} {
215 return map[string]*apexBundle{}
216 }).(map[string]*apexBundle)
217}
218
219// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
220func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
221 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
222 if ab.IsNativeBridgeSupported() {
223 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
224 }
225 vndkVersion := proptools.StringDefault(ab.vndkProperties.Vndk_version, mctx.DeviceConfig().PlatformVndkVersion())
226 vndkApexListMutex.Lock()
227 defer vndkApexListMutex.Unlock()
228 vndkApexList := vndkApexList(mctx.Config())
229 if other, ok := vndkApexList[vndkVersion]; ok {
230 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.Name())
231 }
232 vndkApexList[vndkVersion] = ab
233 }
234}
235
236// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
237// It filters only libs with matching targets.
238func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
239 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
240 vndkApexList := vndkApexList(mctx.Config())
241 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
242 targetArch := cc.Target().String()
243 for _, target := range ab.MultiTargets() {
244 if target.String() == targetArch {
245 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
246 break
247 }
248 }
249 }
250 }
251}
252
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900253// Mark the direct and transitive dependencies of apex bundles so that they
254// can be built for the apex bundles.
255func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800256 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800257 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900258 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900259 depName := mctx.OtherModuleName(child)
260 // If the parent is apexBundle, this child is directly depended.
261 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800262 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800263 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
264 // non-installable apex's cannot be installed and so should not prevent libraries from being
265 // installed to the system.
266 android.UpdateApexDependency(apexBundleName, depName, directDep)
267 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900268
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900269 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900270 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900271 return true
272 } else {
273 return false
274 }
275 })
276 }
277}
278
279// Create apex variations if a module is included in APEX(s).
280func apexMutator(mctx android.BottomUpMutatorContext) {
281 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900282 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900283 } else if _, ok := mctx.Module().(*apexBundle); ok {
284 // apex bundle itself is mutated so that it and its modules have same
285 // apex variant.
286 apexBundleName := mctx.ModuleName()
287 mctx.CreateVariations(apexBundleName)
288 }
289}
Sundong Ahne9b55722019-09-06 17:37:42 +0900290
291func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
292 if _, ok := mctx.Module().(*apexBundle); ok {
293 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
294 modules := mctx.CreateLocalVariations("", "flattened")
295 modules[0].(*apexBundle).SetFlattened(false)
296 modules[1].(*apexBundle).SetFlattened(true)
297 }
298 }
299}
300
Jooyung Han5c998b92019-06-27 11:30:33 +0900301func apexUsesMutator(mctx android.BottomUpMutatorContext) {
302 if ab, ok := mctx.Module().(*apexBundle); ok {
303 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
304 }
305}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900306
Alex Light9670d332019-01-29 18:07:33 -0800307type apexNativeDependencies struct {
308 // List of native libraries
309 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900310
Alex Light9670d332019-01-29 18:07:33 -0800311 // List of native executables
312 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900313
Roland Levillain630846d2019-06-26 12:48:34 +0100314 // List of native tests
315 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800316}
Jooyung Han344d5432019-08-23 11:17:39 +0900317
Alex Light9670d332019-01-29 18:07:33 -0800318type apexMultilibProperties struct {
319 // Native dependencies whose compile_multilib is "first"
320 First apexNativeDependencies
321
322 // Native dependencies whose compile_multilib is "both"
323 Both apexNativeDependencies
324
325 // Native dependencies whose compile_multilib is "prefer32"
326 Prefer32 apexNativeDependencies
327
328 // Native dependencies whose compile_multilib is "32"
329 Lib32 apexNativeDependencies
330
331 // Native dependencies whose compile_multilib is "64"
332 Lib64 apexNativeDependencies
333}
334
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900335type apexBundleProperties struct {
336 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000337 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800338 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900339
Jiyong Park40e26a22019-02-08 02:53:06 +0900340 // AndroidManifest.xml file used for the zip container of this APEX bundle.
341 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800342 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900343
Jiyong Park05e70dd2019-03-18 14:26:32 +0900344 // Canonical name of the APEX bundle in the manifest file.
345 // If unspecified, defaults to the value of name
346 Apex_name *string
347
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900348 // Determines the file contexts file for setting security context to each file in this APEX bundle.
349 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
350 // used.
351 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900352 File_contexts *string
353
354 // List of native shared libs that are embedded inside this APEX bundle
355 Native_shared_libs []string
356
Roland Levillain630846d2019-06-26 12:48:34 +0100357 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900358 Binaries []string
359
360 // List of java libraries that are embedded inside this APEX bundle
361 Java_libs []string
362
363 // List of prebuilt files that are embedded inside this APEX bundle
364 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900365
Roland Levillain630846d2019-06-26 12:48:34 +0100366 // List of tests that are embedded inside this APEX bundle
367 Tests []string
368
Jiyong Parkff1458f2018-10-12 21:49:38 +0900369 // Name of the apex_key module that provides the private key to sign APEX
370 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900371
Alex Light5098a612018-11-29 17:12:15 -0800372 // The type of APEX to build. Controls what the APEX payload is. Either
373 // 'image', 'zip' or 'both'. Default: 'image'.
374 Payload_type *string
375
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900376 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
377 // or an android_app_certificate module name in the form ":module".
378 Certificate *string
379
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900380 // Whether this APEX is installable to one of the partitions. Default: true.
381 Installable *bool
382
Jiyong Parkda6eb592018-12-19 17:12:36 +0900383 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
384 // Default is false.
385 Use_vendor *bool
386
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800387 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
388 Ignore_system_library_special_case *bool
389
Alex Light9670d332019-01-29 18:07:33 -0800390 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900391
Jiyong Parkf97782b2019-02-13 20:28:58 +0900392 // List of sanitizer names that this APEX is enabled for
393 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900394
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900395 PreventInstall bool `blueprint:"mutated"`
396
397 HideFromMake bool `blueprint:"mutated"`
398
Jooyung Han5c998b92019-06-27 11:30:33 +0900399 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
400 Provide_cpp_shared_libs *bool
401
402 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
403 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100404
405 // A txt file containing list of files that are whitelisted to be included in this APEX.
406 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900407
408 // List of APKs to package inside APEX
409 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900410
411 // To distinguish between flattened and non-flattened variants.
412 // if set true, then this variant is flattened variant.
413 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900414
415 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
416 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
417 // is implied. This value affects all modules included in this APEX. In other words, they are
418 // also built with the SDKs specified here.
419 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800420}
421
422type apexTargetBundleProperties struct {
423 Target struct {
424 // Multilib properties only for android.
425 Android struct {
426 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900427 }
Jooyung Han344d5432019-08-23 11:17:39 +0900428
Alex Light9670d332019-01-29 18:07:33 -0800429 // Multilib properties only for host.
430 Host struct {
431 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900432 }
Jooyung Han344d5432019-08-23 11:17:39 +0900433
Alex Light9670d332019-01-29 18:07:33 -0800434 // Multilib properties only for host linux_bionic.
435 Linux_bionic struct {
436 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900437 }
Jooyung Han344d5432019-08-23 11:17:39 +0900438
Alex Light9670d332019-01-29 18:07:33 -0800439 // Multilib properties only for host linux_glibc.
440 Linux_glibc struct {
441 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900442 }
443 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900444}
445
Jooyung Han344d5432019-08-23 11:17:39 +0900446type apexVndkProperties struct {
447 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
448 Vndk_version *string
449}
450
Jiyong Park8fd61922018-11-08 02:50:25 +0900451type apexFileClass int
452
453const (
454 etc apexFileClass = iota
455 nativeSharedLib
456 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900457 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800458 pyBinary
459 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900460 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100461 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900462 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900463)
464
Alex Light5098a612018-11-29 17:12:15 -0800465type apexPackaging int
466
467const (
468 imageApex apexPackaging = iota
469 zipApex
470 both
471)
472
473func (a apexPackaging) image() bool {
474 switch a {
475 case imageApex, both:
476 return true
477 }
478 return false
479}
480
481func (a apexPackaging) zip() bool {
482 switch a {
483 case zipApex, both:
484 return true
485 }
486 return false
487}
488
489func (a apexPackaging) suffix() string {
490 switch a {
491 case imageApex:
492 return imageApexSuffix
493 case zipApex:
494 return zipApexSuffix
495 case both:
496 panic(fmt.Errorf("must be either zip or image"))
497 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100498 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800499 }
500}
501
502func (a apexPackaging) name() string {
503 switch a {
504 case imageApex:
505 return imageApexType
506 case zipApex:
507 return zipApexType
508 case both:
509 panic(fmt.Errorf("must be either zip or image"))
510 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100511 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800512 }
513}
514
Jiyong Park8fd61922018-11-08 02:50:25 +0900515func (class apexFileClass) NameInMake() string {
516 switch class {
517 case etc:
518 return "ETC"
519 case nativeSharedLib:
520 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800521 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900522 return "EXECUTABLES"
523 case javaSharedLib:
524 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100525 case nativeTest:
526 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900527 case app:
528 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900529 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100530 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900531 }
532}
533
534type apexFile struct {
535 builtFile android.Path
536 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900537 installDir string
538 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900539 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800540 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900541}
542
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900543type apexBundle struct {
544 android.ModuleBase
545 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900546 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900547
Alex Light9670d332019-01-29 18:07:33 -0800548 properties apexBundleProperties
549 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900550 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900551
Alex Light5098a612018-11-29 17:12:15 -0800552 apexTypes apexPackaging
553
Colin Crossa4925902018-11-16 11:36:28 -0800554 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800555 outputFiles map[apexPackaging]android.WritablePath
Roland Levillain935639d2019-08-13 14:55:28 +0100556 flattenedOutput android.OutputPath
Colin Crossa4925902018-11-16 11:36:28 -0800557 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900558
Jiyong Park03b68dd2019-07-26 23:20:40 +0900559 prebuiltFileToDelete string
560
Jiyong Park42cca6c2019-04-01 11:15:50 +0900561 public_key_file android.Path
562 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900563
564 container_certificate_file android.Path
565 container_private_key_file android.Path
566
Jiyong Park8fd61922018-11-08 02:50:25 +0900567 // list of files to be included in this apex
568 filesInfo []apexFile
569
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900570 // list of module names that this APEX is depending on
571 externalDeps []string
572
Alex Light0851b882019-02-07 13:20:53 -0800573 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900574 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900575
576 // intermediate path for apex_manifest.json
577 manifestOut android.WritablePath
Sundong Ahne9b55722019-09-06 17:37:42 +0900578
579 // A config value of (TARGET_FLATTEN_APEX && !TARGET_BUILD_APPS)
580 flattenedConfigValue bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900581}
582
Jiyong Park397e55e2018-10-24 21:09:55 +0900583func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100584 native_shared_libs []string, binaries []string, tests []string,
585 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900586 // Use *FarVariation* to be able to depend on modules having
587 // conflicting variations with this module. This is required since
588 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
589 // for native shared libs.
590 ctx.AddFarVariationDependencies([]blueprint.Variation{
591 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900592 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900593 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900594 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900595 }, sharedLibTag, native_shared_libs...)
596
597 ctx.AddFarVariationDependencies([]blueprint.Variation{
598 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900599 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900600 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100601
602 ctx.AddFarVariationDependencies([]blueprint.Variation{
603 {Mutator: "arch", Variation: arch},
604 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100605 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100606 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900607}
608
Alex Light9670d332019-01-29 18:07:33 -0800609func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
610 if ctx.Os().Class == android.Device {
611 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
612 } else {
613 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
614 if ctx.Os().Bionic() {
615 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
616 } else {
617 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
618 }
619 }
620}
621
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900622func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800623
Jiyong Park397e55e2018-10-24 21:09:55 +0900624 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900625 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800626
627 a.combineProperties(ctx)
628
Jiyong Park397e55e2018-10-24 21:09:55 +0900629 has32BitTarget := false
630 for _, target := range targets {
631 if target.Arch.ArchType.Multilib == "lib32" {
632 has32BitTarget = true
633 }
634 }
635 for i, target := range targets {
636 // When multilib.* is omitted for native_shared_libs, it implies
637 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900638 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900639 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900640 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900641 {Mutator: "link", Variation: "shared"},
642 }, sharedLibTag, a.properties.Native_shared_libs...)
643
Roland Levillain630846d2019-06-26 12:48:34 +0100644 // When multilib.* is omitted for tests, it implies
645 // multilib.both.
646 ctx.AddFarVariationDependencies([]blueprint.Variation{
647 {Mutator: "arch", Variation: target.String()},
648 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100649 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100650 }, testTag, a.properties.Tests...)
651
Jiyong Park397e55e2018-10-24 21:09:55 +0900652 // Add native modules targetting both ABIs
653 addDependenciesForNativeModules(ctx,
654 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100655 a.properties.Multilib.Both.Binaries,
656 a.properties.Multilib.Both.Tests,
657 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900658 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900659
Alex Light3d673592019-01-18 14:37:31 -0800660 isPrimaryAbi := i == 0
661 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900662 // When multilib.* is omitted for binaries, it implies
663 // multilib.first.
664 ctx.AddFarVariationDependencies([]blueprint.Variation{
665 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900666 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900667 }, executableTag, a.properties.Binaries...)
668
669 // Add native modules targetting the first ABI
670 addDependenciesForNativeModules(ctx,
671 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100672 a.properties.Multilib.First.Binaries,
673 a.properties.Multilib.First.Tests,
674 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900675 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800676
677 // When multilib.* is omitted for prebuilts, it implies multilib.first.
678 ctx.AddFarVariationDependencies([]blueprint.Variation{
679 {Mutator: "arch", Variation: target.String()},
680 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900681 }
682
683 switch target.Arch.ArchType.Multilib {
684 case "lib32":
685 // Add native modules targetting 32-bit ABI
686 addDependenciesForNativeModules(ctx,
687 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100688 a.properties.Multilib.Lib32.Binaries,
689 a.properties.Multilib.Lib32.Tests,
690 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900691 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900692
693 addDependenciesForNativeModules(ctx,
694 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100695 a.properties.Multilib.Prefer32.Binaries,
696 a.properties.Multilib.Prefer32.Tests,
697 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900698 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900699 case "lib64":
700 // Add native modules targetting 64-bit ABI
701 addDependenciesForNativeModules(ctx,
702 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100703 a.properties.Multilib.Lib64.Binaries,
704 a.properties.Multilib.Lib64.Tests,
705 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900706 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900707
708 if !has32BitTarget {
709 addDependenciesForNativeModules(ctx,
710 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100711 a.properties.Multilib.Prefer32.Binaries,
712 a.properties.Multilib.Prefer32.Tests,
713 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900714 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900715 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700716
717 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
718 for _, sanitizer := range ctx.Config().SanitizeDevice() {
719 if sanitizer == "hwaddress" {
720 addDependenciesForNativeModules(ctx,
721 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100722 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700723 break
724 }
725 }
726 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900727 }
728
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900729 }
730
Jiyong Parkff1458f2018-10-12 21:49:38 +0900731 ctx.AddFarVariationDependencies([]blueprint.Variation{
732 {Mutator: "arch", Variation: "android_common"},
733 }, javaLibTag, a.properties.Java_libs...)
734
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900735 ctx.AddFarVariationDependencies([]blueprint.Variation{
736 {Mutator: "arch", Variation: "android_common"},
737 }, androidAppTag, a.properties.Apps...)
738
Jiyong Park23c52b02019-02-02 13:13:47 +0900739 if String(a.properties.Key) == "" {
740 ctx.ModuleErrorf("key is missing")
741 return
742 }
743 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900744
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900745 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900746 if cert != "" {
747 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900748 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900749
750 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
751 if len(a.properties.Uses_sdks) > 0 {
752 sdkRefs := []android.SdkRef{}
753 for _, str := range a.properties.Uses_sdks {
754 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
755 sdkRefs = append(sdkRefs, parsed)
756 }
757 a.BuildWithSdks(sdkRefs)
758 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900759}
760
Colin Cross0ea8ba82019-06-06 14:33:29 -0700761func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900762 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
763 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000764 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900765 }
766 return String(a.properties.Certificate)
767}
768
Colin Cross41955e82019-05-29 14:40:35 -0700769func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
770 switch tag {
771 case "":
772 if file, ok := a.outputFiles[imageApex]; ok {
773 return android.Paths{file}, nil
774 } else {
775 return nil, nil
776 }
Roland Levillain935639d2019-08-13 14:55:28 +0100777 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900778 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100779 flattenedApexPath := a.flattenedOutput
780 return android.Paths{flattenedApexPath}, nil
781 } else {
782 return nil, nil
783 }
Colin Cross41955e82019-05-29 14:40:35 -0700784 default:
785 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900786 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900787}
788
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900789func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900790 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900791}
792
Jiyong Park7c1dc612019-01-05 11:15:24 +0900793func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
794 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900795 return "vendor"
796 } else {
797 return "core"
798 }
799}
800
Jiyong Parkf97782b2019-02-13 20:28:58 +0900801func (a *apexBundle) EnableSanitizer(sanitizerName string) {
802 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
803 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
804 }
805}
806
Jiyong Park388ef3f2019-01-28 19:47:32 +0900807func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900808 if android.InList(sanitizerName, a.properties.SanitizerNames) {
809 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900810 }
811
812 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900813 globalSanitizerNames := []string{}
814 if a.Host() {
815 globalSanitizerNames = ctx.Config().SanitizeHost()
816 } else {
817 arches := ctx.Config().SanitizeDeviceArch()
818 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
819 globalSanitizerNames = ctx.Config().SanitizeDevice()
820 }
821 }
822 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900823}
824
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900825func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
826 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
827}
828
829func (a *apexBundle) PreventInstall() {
830 a.properties.PreventInstall = true
831}
832
833func (a *apexBundle) HideFromMake() {
834 a.properties.HideFromMake = true
835}
836
Sundong Ahne9b55722019-09-06 17:37:42 +0900837func (a *apexBundle) SetFlattened(flattened bool) {
838 a.properties.Flattened = flattened
839}
840
Martin Stjernholm279de572019-09-10 23:18:20 +0100841func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900842 // Decide the APEX-local directory by the multilib of the library
843 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100844 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845 case "lib32":
846 dirInApex = "lib"
847 case "lib64":
848 dirInApex = "lib64"
849 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100850 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
851 if !ccMod.Arch().Native {
852 dirInApex = filepath.Join(dirInApex, ccMod.Arch().ArchType.String())
853 } else if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
854 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900855 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100856 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
857 // Special case for Bionic libs and other libs installed with them. This is
858 // to prevent those libs from being included in the search path
859 // /apex/com.android.runtime/${LIB}. This exclusion is required because
860 // those libs in the Runtime APEX are available via the legacy paths in
861 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
862 // to the legacy paths and thus will be loaded into the default linker
863 // namespace (aka "platform" namespace). If the libs are directly in
864 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
865 // into the runtime linker namespace, which will result in double loading of
866 // them, which isn't supported.
867 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900868 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900869
Martin Stjernholm279de572019-09-10 23:18:20 +0100870 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900871 return
872}
873
874func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900875 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200876 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900877 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200878 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
879 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900880 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900881 fileToCopy = cc.OutputFile().Path()
882 return
883}
884
Alex Light778127a2019-02-27 14:19:50 -0800885func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
886 dirInApex = "bin"
887 fileToCopy = py.HostToolPath().Path()
888 return
889}
890func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
891 dirInApex = "bin"
892 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
893 if err != nil {
894 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
895 return
896 }
897 fileToCopy = android.PathForOutput(ctx, s)
898 return
899}
900
Jiyong Park04480cf2019-02-06 00:16:29 +0900901func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
902 dirInApex = filepath.Join("bin", sh.SubDir())
903 fileToCopy = sh.OutputFile()
904 return
905}
906
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900907func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
908 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900909 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900910 return
911}
912
Jiyong Park9e6c2422019-08-09 20:39:45 +0900913func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
914 dirInApex = "javalib"
915 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
916 implJars := java.ImplementationJars()
917 if len(implJars) != 1 {
918 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
919 strings.Join(implJars.Strings(), ", ")))
920 }
921 fileToCopy = implJars[0]
922 return
923}
924
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900925func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
926 dirInApex = filepath.Join("etc", prebuilt.SubDir())
927 fileToCopy = prebuilt.OutputFile()
928 return
929}
930
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900931func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
932 dirInApex = filepath.Join("app", pkgName)
933 fileToCopy = app.OutputFile()
934 return
935}
936
Roland Levillain935639d2019-08-13 14:55:28 +0100937// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
938type flattenedApexContext struct {
939 android.ModuleContext
940}
941
942func (c *flattenedApexContext) InstallBypassMake() bool {
943 return true
944}
945
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900946func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900947 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900948
Alex Light5098a612018-11-29 17:12:15 -0800949 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
950 a.apexTypes = imageApex
951 } else if *a.properties.Payload_type == "zip" {
952 a.apexTypes = zipApex
953 } else if *a.properties.Payload_type == "both" {
954 a.apexTypes = both
955 } else {
956 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
957 return
958 }
959
Roland Levillain630846d2019-06-26 12:48:34 +0100960 if len(a.properties.Tests) > 0 && !a.testApex {
961 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
962 return
963 }
964
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800965 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
966
Jooyung Hane1633032019-08-01 17:41:43 +0900967 // native lib dependencies
968 var provideNativeLibs []string
969 var requireNativeLibs []string
970
Jooyung Han5c998b92019-06-27 11:30:33 +0900971 // Check if "uses" requirements are met with dependent apexBundles
972 var providedNativeSharedLibs []string
973 useVendor := proptools.Bool(a.properties.Use_vendor)
974 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
975 if ctx.OtherModuleDependencyTag(m) != usesTag {
976 return
977 }
978 otherName := ctx.OtherModuleName(m)
979 other, ok := m.(*apexBundle)
980 if !ok {
981 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
982 return
983 }
984 if proptools.Bool(other.properties.Use_vendor) != useVendor {
985 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
986 return
987 }
988 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
989 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
990 return
991 }
992 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
993 })
994
Alex Light778127a2019-02-27 14:19:50 -0800995 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +0100996 depTag := ctx.OtherModuleDependencyTag(child)
997 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900998 if _, ok := parent.(*apexBundle); ok {
999 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001000 switch depTag {
1001 case sharedLibTag:
1002 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001003 if cc.HasStubsVariants() {
1004 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1005 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001006 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001007 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001008 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001009 } else {
1010 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001011 }
1012 case executableTag:
1013 if cc, ok := child.(*cc.Module); ok {
1014 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001015 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001017 } else if sh, ok := child.(*android.ShBinary); ok {
1018 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
1019 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -08001020 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1021 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1022 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1023 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1024 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1025 // NB: Since go binaries are static we don't need the module for anything here, which is
1026 // good since the go tool is a blueprint.Module not an android.Module like we would
1027 // normally use.
1028 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001029 } else {
Alex Light778127a2019-02-27 14:19:50 -08001030 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 +09001031 }
1032 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001033 if javaLib, ok := child.(*java.Library); ok {
1034 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001035 if fileToCopy == nil {
1036 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1037 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001038 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1039 }
1040 return true
1041 } else if javaLib, ok := child.(*java.Import); ok {
1042 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1043 if fileToCopy == nil {
1044 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1045 } else {
1046 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001047 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001048 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001049 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001050 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001051 }
1052 case prebuiltTag:
1053 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1054 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001055 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001057 } else {
1058 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1059 }
Roland Levillain630846d2019-06-26 12:48:34 +01001060 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001061 if ccTest, ok := child.(*cc.Module); ok {
1062 if ccTest.IsTestPerSrcAllTestsVariation() {
1063 // Multiple-output test module (where `test_per_src: true`).
1064 //
1065 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1066 // We do not add this variation to `filesInfo`, as it has no output;
1067 // however, we do add the other variations of this module as indirect
1068 // dependencies (see below).
1069 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001070 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001071 // Single-output test module (where `test_per_src: false`).
1072 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1073 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001074 }
Roland Levillain630846d2019-06-26 12:48:34 +01001075 return true
1076 } else {
1077 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1078 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001079 case keyTag:
1080 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001081 a.private_key_file = key.private_key_file
1082 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001083 return false
1084 } else {
1085 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001086 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001087 case certificateTag:
1088 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001089 a.container_certificate_file = dep.Certificate.Pem
1090 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001091 return false
1092 } else {
1093 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1094 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001095 case android.PrebuiltDepTag:
1096 // If the prebuilt is force disabled, remember to delete the prebuilt file
1097 // that might have been installed in the previous builds
1098 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1099 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1100 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001101 case androidAppTag:
1102 if ap, ok := child.(*java.AndroidApp); ok {
1103 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1104 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1105 return true
1106 } else {
1107 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1108 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001109 }
1110 } else {
1111 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001112 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001113 // We cannot use a switch statement on `depTag` here as the checked
1114 // tags used below are private (e.g. `cc.sharedDepTag`).
1115 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1116 if cc, ok := child.(*cc.Module); ok {
1117 if android.InList(cc.Name(), providedNativeSharedLibs) {
1118 // If we're using a shared library which is provided from other APEX,
1119 // don't include it in this APEX
1120 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001121 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001122 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1123 // If the dependency is a stubs lib, don't include it in this APEX,
1124 // but make sure that the lib is installed on the device.
1125 // In case no APEX is having the lib, the lib is installed to the system
1126 // partition.
1127 //
1128 // Always include if we are a host-apex however since those won't have any
1129 // system libraries.
1130 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1131 a.externalDeps = append(a.externalDeps, cc.Name())
1132 }
Jooyung Hane1633032019-08-01 17:41:43 +09001133 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001134 // Don't track further
1135 return false
1136 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001137 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001138 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1139 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001140 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001141 } else if cc.IsTestPerSrcDepTag(depTag) {
1142 if cc, ok := child.(*cc.Module); ok {
1143 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1144 // Handle modules created as `test_per_src` variations of a single test module:
1145 // use the name of the generated test binary (`fileToCopy`) instead of the name
1146 // of the original test module (`depName`, shared by all `test_per_src`
1147 // variations of that module).
1148 moduleName := filepath.Base(fileToCopy.String())
1149 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1150 return true
1151 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001152 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001153 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Sundong Ahn2db7f462019-08-27 18:53:12 +09001154 } else if am.NoApex() && !android.InList(depName, whitelistNoApex[ctx.ModuleName()]) {
1155 ctx.ModuleErrorf("tries to include no_apex module %s", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001156 }
1157 }
1158 }
1159 return false
1160 })
1161
Sundong Ahne9b55722019-09-06 17:37:42 +09001162 a.flattenedConfigValue = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1163 if a.flattenedConfigValue {
1164 a.properties.Flattened = true
1165 }
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001166 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001167 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1168 return
1169 }
1170
Jiyong Park8fd61922018-11-08 02:50:25 +09001171 // remove duplicates in filesInfo
1172 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001173 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001174 result := []apexFile{}
1175 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001176 dest := filepath.Join(f.installDir, f.builtFile.Base())
1177 if !encountered[dest] {
1178 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001179 result = append(result, f)
1180 }
1181 }
1182 return result
1183 }
1184 filesInfo = removeDup(filesInfo)
1185
1186 // to have consistent build rules
1187 sort.Slice(filesInfo, func(i, j int) bool {
1188 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1189 })
1190
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09001191 // check no_apex modules
1192 whitelist := whitelistNoApex[ctx.ModuleName()]
1193 for i := range filesInfo {
1194 if am, ok := filesInfo[i].module.(android.ApexModule); ok {
1195 if am.NoApex() && !android.InList(filesInfo[i].moduleName, whitelist) {
1196 ctx.ModuleErrorf("tries to include no_apex module %s", filesInfo[i].moduleName)
1197 }
1198 }
1199 }
1200
Jiyong Park8fd61922018-11-08 02:50:25 +09001201 // prepend the name of this APEX to the module names. These names will be the names of
1202 // modules that will be defined if the APEX is flattened.
1203 for i := range filesInfo {
1204 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
1205 }
1206
Jiyong Park8fd61922018-11-08 02:50:25 +09001207 a.installDir = android.PathForModuleInstall(ctx, "apex")
1208 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001209
Jooyung Hane1633032019-08-01 17:41:43 +09001210 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
1211 // put dependency({provide|require}NativeLibs) in apex_manifest.json
1212 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
1213 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1214 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
1215 ctx.Build(pctx, android.BuildParams{
1216 Rule: injectApexDependency,
1217 Input: manifestSrc,
1218 Output: a.manifestOut,
1219 Args: map[string]string{
1220 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1221 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
1222 },
1223 })
1224
Roland Levillain935639d2019-08-13 14:55:28 +01001225 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1226 // reply true to `InstallBypassMake()` (thus making the call
1227 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1228 // instead of `android.PathForOutput`) to return the correct path to the flattened
1229 // APEX (as its contents is installed by Make, not Soong).
1230 factx := flattenedApexContext{ctx}
1231 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
1232
Alex Light5098a612018-11-29 17:12:15 -08001233 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001234 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001235 }
1236 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001237 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001238 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001239 // in other modules. It is in AndroidMk where the selection of flattened
1240 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001241 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001242 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001243 }
1244}
1245
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001246func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001247 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001248 for _, f := range a.filesInfo {
1249 if f.module != nil {
1250 notice := f.module.NoticeFile()
1251 if notice.Valid() {
1252 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001253 }
1254 }
1255 }
1256 // append the notice file specified in the apex module itself
1257 if a.NoticeFile().Valid() {
1258 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001259 }
1260
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001261 if len(noticeFiles) == 0 {
1262 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001263 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001264
Jaewoong Jung98772792019-07-01 17:15:13 -07001265 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001266}
1267
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001268func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001269 cert := String(a.properties.Certificate)
1270 if cert != "" && android.SrcIsModule(cert) == "" {
1271 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001272 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1273 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001274 } else if cert == "" {
1275 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001276 a.container_certificate_file = pem
1277 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001278 }
1279
Alex Light5098a612018-11-29 17:12:15 -08001280 var abis []string
1281 for _, target := range ctx.MultiTargets() {
1282 if len(target.Arch.Abi) > 0 {
1283 abis = append(abis, target.Arch.Abi[0])
1284 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001285 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001286
Alex Light5098a612018-11-29 17:12:15 -08001287 abis = android.FirstUniqueStrings(abis)
1288
1289 suffix := apexType.suffix()
1290 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001291
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001292 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001293 for _, f := range a.filesInfo {
1294 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001295 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001296
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001297 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001298 emitCommands := []string{}
1299 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1300 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001301 for i, src := range filesToCopy {
1302 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001303 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001304 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001305 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1306 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001307 for _, sym := range a.filesInfo[i].symlinks {
1308 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1309 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1310 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001311 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001312 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001313 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001314
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001315 if a.properties.Whitelisted_files != nil {
1316 ctx.Build(pctx, android.BuildParams{
1317 Rule: emitApexContentRule,
1318 Implicits: implicitInputs,
1319 Output: imageContentFile,
1320 Description: "emit apex image content",
1321 Args: map[string]string{
1322 "emit_commands": strings.Join(emitCommands, " && "),
1323 },
1324 })
1325 implicitInputs = append(implicitInputs, imageContentFile)
1326 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1327
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001328 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001329 ctx.Build(pctx, android.BuildParams{
1330 Rule: diffApexContentRule,
1331 Implicits: implicitInputs,
1332 Output: phonyOutput,
1333 Description: "diff apex image content",
1334 Args: map[string]string{
1335 "whitelisted_files_file": whitelistedFilesFile.String(),
1336 "image_content_file": imageContentFile.String(),
1337 "apex_module_name": ctx.ModuleName(),
1338 },
1339 })
1340
1341 implicitInputs = append(implicitInputs, phonyOutput)
1342 }
1343
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001344 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1345 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001346
Alex Light5098a612018-11-29 17:12:15 -08001347 if apexType.image() {
1348 // files and dirs that will be created in APEX
1349 var readOnlyPaths []string
1350 var executablePaths []string // this also includes dirs
1351 for _, f := range a.filesInfo {
1352 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001353 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001354 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001355 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001356 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001357 }
Alex Light5098a612018-11-29 17:12:15 -08001358 } else {
1359 readOnlyPaths = append(readOnlyPaths, pathInApex)
1360 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001361 dir := f.installDir
1362 for !android.InList(dir, executablePaths) && dir != "" {
1363 executablePaths = append(executablePaths, dir)
1364 dir, _ = filepath.Split(dir) // move up to the parent
1365 if len(dir) > 0 {
1366 // remove trailing slash
1367 dir = dir[:len(dir)-1]
1368 }
Alex Light5098a612018-11-29 17:12:15 -08001369 }
1370 }
1371 sort.Strings(readOnlyPaths)
1372 sort.Strings(executablePaths)
1373 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1374 ctx.Build(pctx, android.BuildParams{
1375 Rule: generateFsConfig,
1376 Output: cannedFsConfig,
1377 Description: "generate fs config",
1378 Args: map[string]string{
1379 "ro_paths": strings.Join(readOnlyPaths, " "),
1380 "exec_paths": strings.Join(executablePaths, " "),
1381 },
1382 })
1383
1384 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1385 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1386 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1387 if !fileContextsOptionalPath.Valid() {
1388 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1389 return
1390 }
1391 fileContexts := fileContextsOptionalPath.Path()
1392
Jiyong Park835d82b2018-12-27 16:04:18 +09001393 optFlags := []string{}
1394
Alex Light5098a612018-11-29 17:12:15 -08001395 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001396 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1397 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001398
Jiyong Park7f67f482019-01-05 12:57:48 +09001399 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1400 if overridden {
1401 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1402 }
1403
Jiyong Park40e26a22019-02-08 02:53:06 +09001404 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001405 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001406 implicitInputs = append(implicitInputs, androidManifestFile)
1407 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1408 }
1409
Jiyong Park71b519d2019-04-18 17:25:49 +09001410 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1411 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1412 ctx.Config().UnbundledBuild() &&
1413 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1414 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1415 apiFingerprint := java.ApiFingerprintPath(ctx)
1416 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1417 implicitInputs = append(implicitInputs, apiFingerprint)
1418 }
1419 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1420
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001421 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1422 if noticeFile.Valid() {
1423 // If there's a NOTICE file, embed it as an asset file in the APEX.
1424 implicitInputs = append(implicitInputs, noticeFile.Path())
1425 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1426 }
1427
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001428 if !ctx.Config().UnbundledBuild() && a.installable() {
1429 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1430 // don't need hashtree for activation. Therefore, by removing hashtree from
1431 // apex bundle (filesystem image in it, to be specific), we can save storage.
1432 optFlags = append(optFlags, "--no_hashtree")
1433 }
1434
Alex Light5098a612018-11-29 17:12:15 -08001435 ctx.Build(pctx, android.BuildParams{
1436 Rule: apexRule,
1437 Implicits: implicitInputs,
1438 Output: unsignedOutputFile,
1439 Description: "apex (" + apexType.name() + ")",
1440 Args: map[string]string{
1441 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1442 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1443 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001444 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001445 "file_contexts": fileContexts.String(),
1446 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001447 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001448 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001449 },
1450 })
1451
1452 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1453 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1454 a.bundleModuleFile = bundleModuleFile
1455
1456 ctx.Build(pctx, android.BuildParams{
1457 Rule: apexProtoConvertRule,
1458 Input: unsignedOutputFile,
1459 Output: apexProtoFile,
1460 Description: "apex proto convert",
1461 })
1462
1463 ctx.Build(pctx, android.BuildParams{
1464 Rule: apexBundleRule,
1465 Input: apexProtoFile,
1466 Output: a.bundleModuleFile,
1467 Description: "apex bundle module",
1468 Args: map[string]string{
1469 "abi": strings.Join(abis, "."),
1470 },
1471 })
1472 } else {
1473 ctx.Build(pctx, android.BuildParams{
1474 Rule: zipApexRule,
1475 Implicits: implicitInputs,
1476 Output: unsignedOutputFile,
1477 Description: "apex (" + apexType.name() + ")",
1478 Args: map[string]string{
1479 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1480 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1481 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001482 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001483 },
1484 })
Colin Crossa4925902018-11-16 11:36:28 -08001485 }
Colin Crossa4925902018-11-16 11:36:28 -08001486
Alex Light5098a612018-11-29 17:12:15 -08001487 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001488 ctx.Build(pctx, android.BuildParams{
1489 Rule: java.Signapk,
1490 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001491 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001492 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001493 Implicits: []android.Path{
1494 a.container_certificate_file,
1495 a.container_private_key_file,
1496 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001497 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001498 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001499 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001500 },
1501 })
Alex Light5098a612018-11-29 17:12:15 -08001502
1503 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahn72f1f3e2019-09-12 22:53:00 +09001504 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && (!a.properties.Flattened || a.flattenedConfigValue) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001505 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001506 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001507}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001508
Jiyong Park8fd61922018-11-08 02:50:25 +09001509func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001510 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001511 // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001512 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001513 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001514
Jiyong Park42cca6c2019-04-01 11:15:50 +09001515 // rename to apex_pubkey
1516 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1517 ctx.Build(pctx, android.BuildParams{
1518 Rule: android.Cp,
1519 Input: a.public_key_file,
1520 Output: copiedPubkey,
1521 })
1522 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1523
Jiyong Park23c52b02019-02-02 13:13:47 +09001524 if ctx.Config().FlattenApex() {
1525 for _, fi := range a.filesInfo {
1526 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001527 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1528 for _, sym := range fi.symlinks {
1529 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1530 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001531 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001532 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001533 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001534}
1535
1536func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001537 if a.properties.HideFromMake {
1538 return android.AndroidMkData{
1539 Disabled: true,
1540 }
1541 }
Alex Light5098a612018-11-29 17:12:15 -08001542 writers := []android.AndroidMkData{}
1543 if a.apexTypes.image() {
1544 writers = append(writers, a.androidMkForType(imageApex))
1545 }
1546 if a.apexTypes.zip() {
1547 writers = append(writers, a.androidMkForType(zipApex))
1548 }
1549 return android.AndroidMkData{
1550 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1551 for _, data := range writers {
1552 data.Custom(w, name, prefix, moduleDir, data)
1553 }
1554 }}
1555}
1556
Alex Lightf1801bc2019-02-13 11:10:07 -08001557func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001558 moduleNames := []string{}
1559
1560 for _, fi := range a.filesInfo {
1561 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1562 continue
1563 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001564 if a.properties.Flattened && !apexType.image() {
1565 continue
Jiyong Park94427262019-02-05 23:18:47 +09001566 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001567
1568 var suffix string
1569 if a.properties.Flattened && !a.flattenedConfigValue {
1570 suffix = ".flattened"
1571 }
1572
1573 if !android.InList(fi.moduleName, moduleNames) {
1574 moduleNames = append(moduleNames, fi.moduleName+suffix)
1575 }
1576
Jiyong Park94427262019-02-05 23:18:47 +09001577 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1578 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001579 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Jiyong Park05e70dd2019-03-18 14:26:32 +09001580 // /apex/<name>/{lib|framework|...}
1581 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1582 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001583 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001584 // /system/apex/<name>/{lib|framework|...}
1585 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1586 a.installDir.RelPathString(), name, fi.installDir))
Sundong Ahne9b55722019-09-06 17:37:42 +09001587 if a.flattenedConfigValue {
1588 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1589 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001590 if len(fi.symlinks) > 0 {
1591 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1592 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001593
1594 if fi.module != nil && fi.module.NoticeFile().Valid() {
1595 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1596 }
Jiyong Park94427262019-02-05 23:18:47 +09001597 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001598 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001599 }
1600 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1601 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1602 if fi.module != nil {
1603 archStr := fi.module.Target().Arch.ArchType.String()
1604 host := false
1605 switch fi.module.Target().Os.Class {
1606 case android.Host:
1607 if archStr != "common" {
1608 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1609 }
1610 host = true
1611 case android.HostCross:
1612 if archStr != "common" {
1613 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1614 }
1615 host = true
1616 case android.Device:
1617 if archStr != "common" {
1618 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1619 }
1620 }
1621 if host {
1622 makeOs := fi.module.Target().Os.String()
1623 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1624 makeOs = "linux"
1625 }
1626 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1627 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1628 }
1629 }
1630 if fi.class == javaSharedLib {
1631 javaModule := fi.module.(*java.Library)
1632 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1633 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1634 // we will have foo.jar.jar
1635 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1636 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1637 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1638 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1639 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1640 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001641 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001642 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001643 if cc, ok := fi.module.(*cc.Module); ok {
1644 if cc.UnstrippedOutputFile() != nil {
1645 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1646 }
1647 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001648 if cc.CoverageOutputFile().Valid() {
1649 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1650 }
Jiyong Park94427262019-02-05 23:18:47 +09001651 }
1652 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1653 } else {
1654 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1655 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1656 }
1657 }
1658 return moduleNames
1659}
1660
Alex Light5098a612018-11-29 17:12:15 -08001661func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001662 return android.AndroidMkData{
1663 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1664 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001665 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001666 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001667 }
1668
Sundong Ahne9b55722019-09-06 17:37:42 +09001669 if a.properties.Flattened && !a.flattenedConfigValue {
1670 name = name + ".flattened"
1671 }
1672
1673 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001674 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001675 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1676 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1677 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001678 if len(moduleNames) > 0 {
1679 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1680 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001681 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001682 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1683
Sundong Ahn72f1f3e2019-09-12 22:53:00 +09001684 } else if !a.properties.Flattened || a.flattenedConfigValue {
Alex Light5098a612018-11-29 17:12:15 -08001685 // zip-apex is the less common type so have the name refer to the image-apex
1686 // only and use {name}.zip if you want the zip-apex
1687 if apexType == zipApex && a.apexTypes == both {
1688 name = name + ".zip"
1689 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001690 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1691 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1692 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1693 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001694 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001695 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001696 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001697 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001698 if len(moduleNames) > 0 {
1699 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1700 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001701 if len(a.externalDeps) > 0 {
1702 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1703 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001704 if a.prebuiltFileToDelete != "" {
1705 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1706 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1707 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001708 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001709
Alex Light5098a612018-11-29 17:12:15 -08001710 if apexType == imageApex {
1711 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1712 }
Jiyong Park719b4462019-01-13 00:39:51 +09001713 }
1714 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001715}
1716
Jooyung Han344d5432019-08-23 11:17:39 +09001717func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001718 module := &apexBundle{
1719 outputFiles: map[apexPackaging]android.WritablePath{},
1720 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001721 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001722 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001723 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001724 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1725 })
Alex Light5098a612018-11-29 17:12:15 -08001726 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001727 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001728 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001729 return module
1730}
Jiyong Park30ca9372019-02-07 16:27:23 +09001731
Jooyung Han344d5432019-08-23 11:17:39 +09001732func ApexBundleFactory(testApex bool) android.Module {
1733 bundle := newApexBundle()
1734 bundle.testApex = testApex
1735 return bundle
1736}
1737
1738func testApexBundleFactory() android.Module {
1739 bundle := newApexBundle()
1740 bundle.testApex = true
1741 return bundle
1742}
1743
Jiyong Parkd1063c12019-07-17 20:08:41 +09001744func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001745 return newApexBundle()
1746}
1747
1748// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1749// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1750// If not specified, then the "current" versions are gathered.
1751func vndkApexBundleFactory() android.Module {
1752 bundle := newApexBundle()
1753 bundle.vndkApex = true
1754 bundle.AddProperties(&bundle.vndkProperties)
1755 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1756 ctx.AppendProperties(&struct {
1757 Compile_multilib *string
1758 }{
1759 proptools.StringPtr("both"),
1760 })
1761 })
1762 return bundle
1763}
1764
Jiyong Park30ca9372019-02-07 16:27:23 +09001765//
1766// Defaults
1767//
1768type Defaults struct {
1769 android.ModuleBase
1770 android.DefaultsModuleBase
1771}
1772
Jiyong Park30ca9372019-02-07 16:27:23 +09001773func defaultsFactory() android.Module {
1774 return DefaultsFactory()
1775}
1776
1777func DefaultsFactory(props ...interface{}) android.Module {
1778 module := &Defaults{}
1779
1780 module.AddProperties(props...)
1781 module.AddProperties(
1782 &apexBundleProperties{},
1783 &apexTargetBundleProperties{},
1784 )
1785
1786 android.InitDefaultsModule(module)
1787 return module
1788}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001789
1790//
1791// Prebuilt APEX
1792//
1793type Prebuilt struct {
1794 android.ModuleBase
1795 prebuilt android.Prebuilt
1796
1797 properties PrebuiltProperties
1798
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001799 inputApex android.Path
1800 installDir android.OutputPath
1801 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001802 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001803}
1804
1805type PrebuiltProperties struct {
1806 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001807 Source string `blueprint:"mutated"`
1808 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001809
1810 Src *string
1811 Arch struct {
1812 Arm struct {
1813 Src *string
1814 }
1815 Arm64 struct {
1816 Src *string
1817 }
1818 X86 struct {
1819 Src *string
1820 }
1821 X86_64 struct {
1822 Src *string
1823 }
1824 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001825
1826 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001827 // Optional name for the installed apex. If unspecified, name of the
1828 // module is used as the file name
1829 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001830
1831 // Names of modules to be overridden. Listed modules can only be other binaries
1832 // (in Make or Soong).
1833 // This does not completely prevent installation of the overridden binaries, but if both
1834 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1835 // from PRODUCT_PACKAGES.
1836 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001837}
1838
1839func (p *Prebuilt) installable() bool {
1840 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001841}
1842
1843func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001844 // If the device is configured to use flattened APEX, force disable the prebuilt because
1845 // the prebuilt is a non-flattened one.
1846 forceDisable := ctx.Config().FlattenApex()
1847
1848 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1849 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001850 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001851
Kun Niu10c9f832019-07-29 16:28:57 -07001852 // Force disable the prebuilts when coverage is enabled.
1853 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1854 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1855
Jiyong Park50b81e52019-07-11 11:24:41 +09001856 // b/137216042 don't use prebuilts when address sanitizer is on
1857 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1858 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1859
1860 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001861 p.properties.ForceDisable = true
1862 return
1863 }
1864
Jiyong Parkc95714e2019-03-29 14:23:10 +09001865 // This is called before prebuilt_select and prebuilt_postdeps mutators
1866 // The mutators requires that src to be set correctly for each arch so that
1867 // arch variants are disabled when src is not provided for the arch.
1868 if len(ctx.MultiTargets()) != 1 {
1869 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1870 return
1871 }
1872 var src string
1873 switch ctx.MultiTargets()[0].Arch.ArchType {
1874 case android.Arm:
1875 src = String(p.properties.Arch.Arm.Src)
1876 case android.Arm64:
1877 src = String(p.properties.Arch.Arm64.Src)
1878 case android.X86:
1879 src = String(p.properties.Arch.X86.Src)
1880 case android.X86_64:
1881 src = String(p.properties.Arch.X86_64.Src)
1882 default:
1883 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1884 return
1885 }
1886 if src == "" {
1887 src = String(p.properties.Src)
1888 }
1889 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001890}
1891
Jiyong Park03b68dd2019-07-26 23:20:40 +09001892func (p *Prebuilt) isForceDisabled() bool {
1893 return p.properties.ForceDisable
1894}
1895
Colin Cross41955e82019-05-29 14:40:35 -07001896func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1897 switch tag {
1898 case "":
1899 return android.Paths{p.outputApex}, nil
1900 default:
1901 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1902 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001903}
1904
Jiyong Park4d277042019-04-23 18:00:10 +09001905func (p *Prebuilt) InstallFilename() string {
1906 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1907}
1908
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001909func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001910 if p.properties.ForceDisable {
1911 return
1912 }
1913
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001914 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001915 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001916 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001917 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001918 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1919 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1920 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001921 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1922 ctx.Build(pctx, android.BuildParams{
1923 Rule: android.Cp,
1924 Input: p.inputApex,
1925 Output: p.outputApex,
1926 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001927 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001928 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001929 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001930}
1931
1932func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1933 return &p.prebuilt
1934}
1935
1936func (p *Prebuilt) Name() string {
1937 return p.prebuilt.Name(p.ModuleBase.Name())
1938}
1939
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001940func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1941 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001942 Class: "ETC",
1943 OutputFile: android.OptionalPathForPath(p.inputApex),
1944 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001945 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1946 func(entries *android.AndroidMkEntries) {
1947 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1948 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1949 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1950 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
1951 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001952 },
1953 }
1954}
1955
1956// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1957func PrebuiltFactory() android.Module {
1958 module := &Prebuilt{}
1959 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001960 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001961 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001962 return module
1963}