blob: de9ce0d9589792fe61c9f5f3972dfb4ad51b6793 [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"
24
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
35var (
36 pctx = android.NewPackageContext("android/apex")
37
38 // Create a canned fs config file where all files and directories are
39 // by default set to (uid/gid/mode) = (1000/1000/0644)
40 // TODO(b/113082813) make this configurable using config.fs syntax
41 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000042 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000043 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090044 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090045 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090047 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090048
49 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
50 // against the binary policy using sefcontext_compiler -p <policy>.
51
52 // TODO(b/114327326): automate the generation of file_contexts
53 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
54 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
55 `(${copy_commands}) && ` +
56 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090057 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090058 `--file_contexts ${file_contexts} ` +
59 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080060 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090061 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090062 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
63 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000064 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Jiyong Park48ca7dc2018-10-10 14:01:00 +090065 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090066 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080067
Alex Light5098a612018-11-29 17:12:15 -080068 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
69 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
70 `(${copy_commands}) && ` +
71 `APEXER_TOOL_PATH=${tool_path} ` +
72 `${apexer} --force --manifest ${manifest} ` +
73 `--payload_type zip ` +
74 `${image_dir} ${out} `,
75 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
76 Description: "ZipAPEX ${image_dir} => ${out}",
77 }, "tool_path", "image_dir", "copy_commands", "manifest")
78
Colin Crossa4925902018-11-16 11:36:28 -080079 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
80 blueprint.RuleParams{
81 Command: `${aapt2} convert --output-format proto $in -o $out`,
82 CommandDeps: []string{"${aapt2}"},
83 })
84
85 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090086 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000087 `apex_payload.img:apex/${abi}.img ` +
88 `apex_manifest.json:root/apex_manifest.json ` +
Shahar Amitai328b0772018-11-26 14:12:02 +000089 `AndroidManifest.xml:manifest/AndroidManifest.xml`,
Colin Crossa4925902018-11-16 11:36:28 -080090 CommandDeps: []string{"${zip2zip}"},
91 Description: "app bundle",
92 }, "abi")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090093)
94
Alex Light5098a612018-11-29 17:12:15 -080095var imageApexSuffix = ".apex"
96var zipApexSuffix = ".zipapex"
97
98var imageApexType = "image"
99var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900100
101type dependencyTag struct {
102 blueprint.BaseDependencyTag
103 name string
104}
105
106var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900107 sharedLibTag = dependencyTag{name: "sharedLib"}
108 executableTag = dependencyTag{name: "executable"}
109 javaLibTag = dependencyTag{name: "javaLib"}
110 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100111 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900112 keyTag = dependencyTag{name: "key"}
113 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900114 usesTag = dependencyTag{name: "uses"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900115)
116
117func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700118 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900119 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900120 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100121 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
122 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
123 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
124 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000125 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100126 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
127 } else {
128 return pctx.HostBinToolPath(ctx, tool).String()
129 }
130 })
131 }
132 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900133 pctx.HostBinToolVariable("avbtool", "avbtool")
134 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
135 pctx.HostBinToolVariable("merge_zips", "merge_zips")
136 pctx.HostBinToolVariable("mke2fs", "mke2fs")
137 pctx.HostBinToolVariable("resize2fs", "resize2fs")
138 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
139 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800140 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900141 pctx.HostBinToolVariable("zipalign", "zipalign")
142
Alex Light0851b882019-02-07 13:20:53 -0800143 android.RegisterModuleType("apex", apexBundleFactory)
144 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900145 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700146 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900147
148 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
149 ctx.TopDown("apex_deps", apexDepsMutator)
Colin Cross643614d2019-06-19 22:51:38 -0700150 ctx.BottomUp("apex", apexMutator).Parallel()
Jooyung Han5c998b92019-06-27 11:30:33 +0900151 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900152 })
153}
154
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900155// Mark the direct and transitive dependencies of apex bundles so that they
156// can be built for the apex bundles.
157func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800158 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800159 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900160 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900161 depName := mctx.OtherModuleName(child)
162 // If the parent is apexBundle, this child is directly depended.
163 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800164 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800165 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
166 // non-installable apex's cannot be installed and so should not prevent libraries from being
167 // installed to the system.
168 android.UpdateApexDependency(apexBundleName, depName, directDep)
169 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900170
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900171 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900172 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900173 return true
174 } else {
175 return false
176 }
177 })
178 }
179}
180
181// Create apex variations if a module is included in APEX(s).
182func apexMutator(mctx android.BottomUpMutatorContext) {
183 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900184 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900185 } else if _, ok := mctx.Module().(*apexBundle); ok {
186 // apex bundle itself is mutated so that it and its modules have same
187 // apex variant.
188 apexBundleName := mctx.ModuleName()
189 mctx.CreateVariations(apexBundleName)
190 }
191}
Jooyung Han5c998b92019-06-27 11:30:33 +0900192func apexUsesMutator(mctx android.BottomUpMutatorContext) {
193 if ab, ok := mctx.Module().(*apexBundle); ok {
194 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
195 }
196}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900197
Alex Light9670d332019-01-29 18:07:33 -0800198type apexNativeDependencies struct {
199 // List of native libraries
200 Native_shared_libs []string
201 // List of native executables
202 Binaries []string
Roland Levillain630846d2019-06-26 12:48:34 +0100203 // List of native tests
204 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800205}
206type apexMultilibProperties struct {
207 // Native dependencies whose compile_multilib is "first"
208 First apexNativeDependencies
209
210 // Native dependencies whose compile_multilib is "both"
211 Both apexNativeDependencies
212
213 // Native dependencies whose compile_multilib is "prefer32"
214 Prefer32 apexNativeDependencies
215
216 // Native dependencies whose compile_multilib is "32"
217 Lib32 apexNativeDependencies
218
219 // Native dependencies whose compile_multilib is "64"
220 Lib64 apexNativeDependencies
221}
222
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900223type apexBundleProperties struct {
224 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000225 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800226 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900227
Jiyong Park40e26a22019-02-08 02:53:06 +0900228 // AndroidManifest.xml file used for the zip container of this APEX bundle.
229 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800230 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900231
Jiyong Park05e70dd2019-03-18 14:26:32 +0900232 // Canonical name of the APEX bundle in the manifest file.
233 // If unspecified, defaults to the value of name
234 Apex_name *string
235
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900236 // Determines the file contexts file for setting security context to each file in this APEX bundle.
237 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
238 // used.
239 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900240 File_contexts *string
241
242 // List of native shared libs that are embedded inside this APEX bundle
243 Native_shared_libs []string
244
Roland Levillain630846d2019-06-26 12:48:34 +0100245 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900246 Binaries []string
247
248 // List of java libraries that are embedded inside this APEX bundle
249 Java_libs []string
250
251 // List of prebuilt files that are embedded inside this APEX bundle
252 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900253
Roland Levillain630846d2019-06-26 12:48:34 +0100254 // List of tests that are embedded inside this APEX bundle
255 Tests []string
256
Jiyong Parkff1458f2018-10-12 21:49:38 +0900257 // Name of the apex_key module that provides the private key to sign APEX
258 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900259
Alex Light5098a612018-11-29 17:12:15 -0800260 // The type of APEX to build. Controls what the APEX payload is. Either
261 // 'image', 'zip' or 'both'. Default: 'image'.
262 Payload_type *string
263
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900264 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
265 // or an android_app_certificate module name in the form ":module".
266 Certificate *string
267
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900268 // Whether this APEX is installable to one of the partitions. Default: true.
269 Installable *bool
270
Jiyong Parkda6eb592018-12-19 17:12:36 +0900271 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
272 // Default is false.
273 Use_vendor *bool
274
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800275 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
276 Ignore_system_library_special_case *bool
277
Alex Light9670d332019-01-29 18:07:33 -0800278 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900279
Jiyong Parkf97782b2019-02-13 20:28:58 +0900280 // List of sanitizer names that this APEX is enabled for
281 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900282
283 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
284 Provide_cpp_shared_libs *bool
285
286 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
287 Uses []string
Alex Light9670d332019-01-29 18:07:33 -0800288}
289
290type apexTargetBundleProperties struct {
291 Target struct {
292 // Multilib properties only for android.
293 Android struct {
294 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900295 }
Alex Light9670d332019-01-29 18:07:33 -0800296 // Multilib properties only for host.
297 Host struct {
298 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900299 }
Alex Light9670d332019-01-29 18:07:33 -0800300 // Multilib properties only for host linux_bionic.
301 Linux_bionic struct {
302 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900303 }
Alex Light9670d332019-01-29 18:07:33 -0800304 // Multilib properties only for host linux_glibc.
305 Linux_glibc struct {
306 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900307 }
308 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900309}
310
Jiyong Park8fd61922018-11-08 02:50:25 +0900311type apexFileClass int
312
313const (
314 etc apexFileClass = iota
315 nativeSharedLib
316 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900317 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800318 pyBinary
319 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900320 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100321 nativeTest
Jiyong Park8fd61922018-11-08 02:50:25 +0900322)
323
Alex Light5098a612018-11-29 17:12:15 -0800324type apexPackaging int
325
326const (
327 imageApex apexPackaging = iota
328 zipApex
329 both
330)
331
332func (a apexPackaging) image() bool {
333 switch a {
334 case imageApex, both:
335 return true
336 }
337 return false
338}
339
340func (a apexPackaging) zip() bool {
341 switch a {
342 case zipApex, both:
343 return true
344 }
345 return false
346}
347
348func (a apexPackaging) suffix() string {
349 switch a {
350 case imageApex:
351 return imageApexSuffix
352 case zipApex:
353 return zipApexSuffix
354 case both:
355 panic(fmt.Errorf("must be either zip or image"))
356 default:
357 panic(fmt.Errorf("unkonwn APEX type %d", a))
358 }
359}
360
361func (a apexPackaging) name() string {
362 switch a {
363 case imageApex:
364 return imageApexType
365 case zipApex:
366 return zipApexType
367 case both:
368 panic(fmt.Errorf("must be either zip or image"))
369 default:
370 panic(fmt.Errorf("unkonwn APEX type %d", a))
371 }
372}
373
Jiyong Park8fd61922018-11-08 02:50:25 +0900374func (class apexFileClass) NameInMake() string {
375 switch class {
376 case etc:
377 return "ETC"
378 case nativeSharedLib:
379 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800380 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900381 return "EXECUTABLES"
382 case javaSharedLib:
383 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100384 case nativeTest:
385 return "NATIVE_TESTS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900386 default:
387 panic(fmt.Errorf("unkonwn class %d", class))
388 }
389}
390
391type apexFile struct {
392 builtFile android.Path
393 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900394 installDir string
395 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900396 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800397 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900398}
399
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900400type apexBundle struct {
401 android.ModuleBase
402 android.DefaultableModuleBase
403
Alex Light9670d332019-01-29 18:07:33 -0800404 properties apexBundleProperties
405 targetProperties apexTargetBundleProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900406
Alex Light5098a612018-11-29 17:12:15 -0800407 apexTypes apexPackaging
408
Colin Crossa4925902018-11-16 11:36:28 -0800409 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800410 outputFiles map[apexPackaging]android.WritablePath
Colin Crossa4925902018-11-16 11:36:28 -0800411 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900412
Jiyong Park03b68dd2019-07-26 23:20:40 +0900413 prebuiltFileToDelete string
414
Jiyong Park42cca6c2019-04-01 11:15:50 +0900415 public_key_file android.Path
416 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900417
418 container_certificate_file android.Path
419 container_private_key_file android.Path
420
Jiyong Park8fd61922018-11-08 02:50:25 +0900421 // list of files to be included in this apex
422 filesInfo []apexFile
423
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900424 // list of module names that this APEX is depending on
425 externalDeps []string
426
Jiyong Park8fd61922018-11-08 02:50:25 +0900427 flattened bool
Alex Light0851b882019-02-07 13:20:53 -0800428
429 testApex bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900430}
431
Jiyong Park397e55e2018-10-24 21:09:55 +0900432func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100433 native_shared_libs []string, binaries []string, tests []string,
434 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900435 // Use *FarVariation* to be able to depend on modules having
436 // conflicting variations with this module. This is required since
437 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
438 // for native shared libs.
439 ctx.AddFarVariationDependencies([]blueprint.Variation{
440 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900441 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900442 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900443 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900444 }, sharedLibTag, native_shared_libs...)
445
446 ctx.AddFarVariationDependencies([]blueprint.Variation{
447 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900448 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900449 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100450
451 ctx.AddFarVariationDependencies([]blueprint.Variation{
452 {Mutator: "arch", Variation: arch},
453 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100454 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100455 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900456}
457
Alex Light9670d332019-01-29 18:07:33 -0800458func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
459 if ctx.Os().Class == android.Device {
460 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
461 } else {
462 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
463 if ctx.Os().Bionic() {
464 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
465 } else {
466 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
467 }
468 }
469}
470
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900471func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800472
Jiyong Park397e55e2018-10-24 21:09:55 +0900473 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900474 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800475
476 a.combineProperties(ctx)
477
Jiyong Park397e55e2018-10-24 21:09:55 +0900478 has32BitTarget := false
479 for _, target := range targets {
480 if target.Arch.ArchType.Multilib == "lib32" {
481 has32BitTarget = true
482 }
483 }
484 for i, target := range targets {
485 // When multilib.* is omitted for native_shared_libs, it implies
486 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900487 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900488 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900489 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900490 {Mutator: "link", Variation: "shared"},
491 }, sharedLibTag, a.properties.Native_shared_libs...)
492
Roland Levillain630846d2019-06-26 12:48:34 +0100493 // When multilib.* is omitted for tests, it implies
494 // multilib.both.
495 ctx.AddFarVariationDependencies([]blueprint.Variation{
496 {Mutator: "arch", Variation: target.String()},
497 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100498 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100499 }, testTag, a.properties.Tests...)
500
Jiyong Park397e55e2018-10-24 21:09:55 +0900501 // Add native modules targetting both ABIs
502 addDependenciesForNativeModules(ctx,
503 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100504 a.properties.Multilib.Both.Binaries,
505 a.properties.Multilib.Both.Tests,
506 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900507 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900508
Alex Light3d673592019-01-18 14:37:31 -0800509 isPrimaryAbi := i == 0
510 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900511 // When multilib.* is omitted for binaries, it implies
512 // multilib.first.
513 ctx.AddFarVariationDependencies([]blueprint.Variation{
514 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900515 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900516 }, executableTag, a.properties.Binaries...)
517
518 // Add native modules targetting the first ABI
519 addDependenciesForNativeModules(ctx,
520 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100521 a.properties.Multilib.First.Binaries,
522 a.properties.Multilib.First.Tests,
523 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900524 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800525
526 // When multilib.* is omitted for prebuilts, it implies multilib.first.
527 ctx.AddFarVariationDependencies([]blueprint.Variation{
528 {Mutator: "arch", Variation: target.String()},
529 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900530 }
531
532 switch target.Arch.ArchType.Multilib {
533 case "lib32":
534 // Add native modules targetting 32-bit ABI
535 addDependenciesForNativeModules(ctx,
536 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100537 a.properties.Multilib.Lib32.Binaries,
538 a.properties.Multilib.Lib32.Tests,
539 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900540 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900541
542 addDependenciesForNativeModules(ctx,
543 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100544 a.properties.Multilib.Prefer32.Binaries,
545 a.properties.Multilib.Prefer32.Tests,
546 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900547 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900548 case "lib64":
549 // Add native modules targetting 64-bit ABI
550 addDependenciesForNativeModules(ctx,
551 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100552 a.properties.Multilib.Lib64.Binaries,
553 a.properties.Multilib.Lib64.Tests,
554 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900555 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900556
557 if !has32BitTarget {
558 addDependenciesForNativeModules(ctx,
559 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100560 a.properties.Multilib.Prefer32.Binaries,
561 a.properties.Multilib.Prefer32.Tests,
562 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900563 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900564 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700565
566 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
567 for _, sanitizer := range ctx.Config().SanitizeDevice() {
568 if sanitizer == "hwaddress" {
569 addDependenciesForNativeModules(ctx,
570 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100571 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700572 break
573 }
574 }
575 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900576 }
577
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900578 }
579
Jiyong Parkff1458f2018-10-12 21:49:38 +0900580 ctx.AddFarVariationDependencies([]blueprint.Variation{
581 {Mutator: "arch", Variation: "android_common"},
582 }, javaLibTag, a.properties.Java_libs...)
583
Jiyong Park23c52b02019-02-02 13:13:47 +0900584 if String(a.properties.Key) == "" {
585 ctx.ModuleErrorf("key is missing")
586 return
587 }
588 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900589
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900590 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900591 if cert != "" {
592 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900593 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900594}
595
Colin Cross0ea8ba82019-06-06 14:33:29 -0700596func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900597 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
598 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000599 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900600 }
601 return String(a.properties.Certificate)
602}
603
Colin Cross41955e82019-05-29 14:40:35 -0700604func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
605 switch tag {
606 case "":
607 if file, ok := a.outputFiles[imageApex]; ok {
608 return android.Paths{file}, nil
609 } else {
610 return nil, nil
611 }
612 default:
613 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900614 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900615}
616
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900617func (a *apexBundle) installable() bool {
618 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
619}
620
Jiyong Park7c1dc612019-01-05 11:15:24 +0900621func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
622 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900623 return "vendor"
624 } else {
625 return "core"
626 }
627}
628
Jiyong Parkf97782b2019-02-13 20:28:58 +0900629func (a *apexBundle) EnableSanitizer(sanitizerName string) {
630 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
631 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
632 }
633}
634
Jiyong Park388ef3f2019-01-28 19:47:32 +0900635func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900636 if android.InList(sanitizerName, a.properties.SanitizerNames) {
637 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900638 }
639
640 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900641 globalSanitizerNames := []string{}
642 if a.Host() {
643 globalSanitizerNames = ctx.Config().SanitizeHost()
644 } else {
645 arches := ctx.Config().SanitizeDeviceArch()
646 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
647 globalSanitizerNames = ctx.Config().SanitizeDevice()
648 }
649 }
650 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900651}
652
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800653func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900654 // Decide the APEX-local directory by the multilib of the library
655 // In the future, we may query this to the module.
656 switch cc.Arch().ArchType.Multilib {
657 case "lib32":
658 dirInApex = "lib"
659 case "lib64":
660 dirInApex = "lib64"
661 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900662 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200663 if !cc.Arch().Native {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900664 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200665 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
666 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900667 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800668 if handleSpecialLibs {
669 switch cc.Name() {
670 case "libc", "libm", "libdl":
671 // Special case for bionic libs. This is to prevent the bionic libs
672 // from being included in the search path /apex/com.android.apex/lib.
673 // This exclusion is required because bionic libs in the runtime APEX
674 // are available via the legacy paths /system/lib/libc.so, etc. By the
675 // init process, the bionic libs in the APEX are bind-mounted to the
676 // legacy paths and thus will be loaded into the default linker namespace.
677 // If the bionic libs are directly in /apex/com.android.apex/lib then
678 // the same libs will be again loaded to the runtime linker namespace,
679 // which will result double loading of bionic libs that isn't supported.
680 dirInApex = filepath.Join(dirInApex, "bionic")
681 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900682 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900683
684 fileToCopy = cc.OutputFile().Path()
685 return
686}
687
688func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900689 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200690 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900691 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200692 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
693 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900694 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900695 fileToCopy = cc.OutputFile().Path()
696 return
697}
698
Roland Levillain9b5fde92019-06-28 15:41:19 +0100699func getCopyManifestForTestPerSrcExecutables(cc *cc.Module) (filesToCopy []android.Path, dirInApex string) {
700 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
701 filesToCopy = cc.TestPerSrcOutputFiles()
702 return
703}
704
Alex Light778127a2019-02-27 14:19:50 -0800705func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
706 dirInApex = "bin"
707 fileToCopy = py.HostToolPath().Path()
708 return
709}
710func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
711 dirInApex = "bin"
712 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
713 if err != nil {
714 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
715 return
716 }
717 fileToCopy = android.PathForOutput(ctx, s)
718 return
719}
720
Jiyong Park04480cf2019-02-06 00:16:29 +0900721func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
722 dirInApex = filepath.Join("bin", sh.SubDir())
723 fileToCopy = sh.OutputFile()
724 return
725}
726
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900727func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
728 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900729 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900730 return
731}
732
733func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
734 dirInApex = filepath.Join("etc", prebuilt.SubDir())
735 fileToCopy = prebuilt.OutputFile()
736 return
737}
738
739func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900740 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900741
Alex Light5098a612018-11-29 17:12:15 -0800742 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
743 a.apexTypes = imageApex
744 } else if *a.properties.Payload_type == "zip" {
745 a.apexTypes = zipApex
746 } else if *a.properties.Payload_type == "both" {
747 a.apexTypes = both
748 } else {
749 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
750 return
751 }
752
Roland Levillain630846d2019-06-26 12:48:34 +0100753 if len(a.properties.Tests) > 0 && !a.testApex {
754 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
755 return
756 }
757
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800758 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
759
Jooyung Han5c998b92019-06-27 11:30:33 +0900760 // Check if "uses" requirements are met with dependent apexBundles
761 var providedNativeSharedLibs []string
762 useVendor := proptools.Bool(a.properties.Use_vendor)
763 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
764 if ctx.OtherModuleDependencyTag(m) != usesTag {
765 return
766 }
767 otherName := ctx.OtherModuleName(m)
768 other, ok := m.(*apexBundle)
769 if !ok {
770 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
771 return
772 }
773 if proptools.Bool(other.properties.Use_vendor) != useVendor {
774 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
775 return
776 }
777 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
778 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
779 return
780 }
781 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
782 })
783
Alex Light778127a2019-02-27 14:19:50 -0800784 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900785 if _, ok := parent.(*apexBundle); ok {
786 // direct dependencies
787 depTag := ctx.OtherModuleDependencyTag(child)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900788 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900789 switch depTag {
790 case sharedLibTag:
791 if cc, ok := child.(*cc.Module); ok {
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800792 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900793 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900794 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900795 } else {
796 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900797 }
798 case executableTag:
799 if cc, ok := child.(*cc.Module); ok {
800 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900801 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900802 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900803 } else if sh, ok := child.(*android.ShBinary); ok {
804 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
805 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -0800806 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
807 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
808 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
809 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
810 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
811 // NB: Since go binaries are static we don't need the module for anything here, which is
812 // good since the go tool is a blueprint.Module not an android.Module like we would
813 // normally use.
814 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900815 } else {
Alex Light778127a2019-02-27 14:19:50 -0800816 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 +0900817 }
818 case javaLibTag:
819 if java, ok := child.(*java.Library); ok {
820 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java)
Jiyong Park8fd61922018-11-08 02:50:25 +0900821 if fileToCopy == nil {
822 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
823 } else {
Jiyong Park719b4462019-01-13 00:39:51 +0900824 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900825 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900826 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900827 } else {
828 ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900829 }
830 case prebuiltTag:
831 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
832 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900833 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900834 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900835 } else {
836 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
837 }
Roland Levillain630846d2019-06-26 12:48:34 +0100838 case testTag:
839 if cc, ok := child.(*cc.Module); ok {
Roland Levillain9b5fde92019-06-28 15:41:19 +0100840 if cc.TestPerSrcOutputFiles() != nil {
841 // Multiple-output test module (using `test_per_src`).
842 filesToCopy, dirInApex := getCopyManifestForTestPerSrcExecutables(cc)
843 for _, fileToCopy := range filesToCopy {
844 // Handle modules created as `test_per_src` variations of a single test module:
845 // replace the name of the original test module (`depName`, shared by all
846 // `test_per_src` variants of that module) with the name of the generated test
847 // binary.
848 moduleName := filepath.Base(fileToCopy.String())
849 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
850 }
851 } else {
852 // Single-output test module (not using `test_per_src`).
853 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
854 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, cc, nil})
855 }
Roland Levillain630846d2019-06-26 12:48:34 +0100856 return true
857 } else {
858 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
859 }
Jiyong Parkff1458f2018-10-12 21:49:38 +0900860 case keyTag:
861 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900862 a.private_key_file = key.private_key_file
863 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +0900864 return false
865 } else {
866 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900867 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900868 case certificateTag:
869 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900870 a.container_certificate_file = dep.Certificate.Pem
871 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900872 return false
873 } else {
874 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
875 }
Jiyong Park03b68dd2019-07-26 23:20:40 +0900876 case android.PrebuiltDepTag:
877 // If the prebuilt is force disabled, remember to delete the prebuilt file
878 // that might have been installed in the previous builds
879 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
880 a.prebuiltFileToDelete = prebuilt.InstallFilename()
881 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900882 }
883 } else {
884 // indirect dependencies
885 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() {
886 if cc, ok := child.(*cc.Module); ok {
Jooyung Han5c998b92019-06-27 11:30:33 +0900887 if android.InList(cc.Name(), providedNativeSharedLibs) {
888 // If we're using a shared library which is provided from other APEX,
889 // don't include it in this APEX
890 return false
891 }
Alex Light49ae3d92019-02-21 14:02:46 -0800892 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900893 // If the dependency is a stubs lib, don't include it in this APEX,
894 // but make sure that the lib is installed on the device.
895 // In case no APEX is having the lib, the lib is installed to the system
896 // partition.
Alex Light49ae3d92019-02-21 14:02:46 -0800897 //
898 // Always include if we are a host-apex however since those won't have any
899 // system libraries.
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900900 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
901 a.externalDeps = append(a.externalDeps, cc.Name())
902 }
903 // Don't track further
Jiyong Park25fc6a92018-11-18 18:02:45 +0900904 return false
905 }
Jiyong Park8fd61922018-11-08 02:50:25 +0900906 depName := ctx.OtherModuleName(child)
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800907 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900908 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900909 return true
910 }
911 }
912 }
913 return false
914 })
915
Jiyong Park9335a262018-12-24 11:31:58 +0900916 a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900917 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +0900918 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
919 return
920 }
921
Jiyong Park8fd61922018-11-08 02:50:25 +0900922 // remove duplicates in filesInfo
923 removeDup := func(filesInfo []apexFile) []apexFile {
924 encountered := make(map[android.Path]bool)
925 result := []apexFile{}
926 for _, f := range filesInfo {
927 if !encountered[f.builtFile] {
928 encountered[f.builtFile] = true
929 result = append(result, f)
930 }
931 }
932 return result
933 }
934 filesInfo = removeDup(filesInfo)
935
936 // to have consistent build rules
937 sort.Slice(filesInfo, func(i, j int) bool {
938 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
939 })
940
941 // prepend the name of this APEX to the module names. These names will be the names of
942 // modules that will be defined if the APEX is flattened.
943 for i := range filesInfo {
944 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
945 }
946
Jiyong Park8fd61922018-11-08 02:50:25 +0900947 a.installDir = android.PathForModuleInstall(ctx, "apex")
948 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -0800949
950 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900951 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -0800952 }
953 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +0900954 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +0100955 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +0900956 // in other modules. It is in AndroidMk where the selection of flattened
957 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900958 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +0900959 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +0900960 }
961}
962
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700963func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +0900964 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +0900965 for _, f := range a.filesInfo {
966 if f.module != nil {
967 notice := f.module.NoticeFile()
968 if notice.Valid() {
969 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +0900970 }
971 }
972 }
973 // append the notice file specified in the apex module itself
974 if a.NoticeFile().Valid() {
975 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +0900976 }
977
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700978 if len(noticeFiles) == 0 {
979 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +0900980 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700981
Jaewoong Jung98772792019-07-01 17:15:13 -0700982 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +0900983}
984
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900985func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900986 cert := String(a.properties.Certificate)
987 if cert != "" && android.SrcIsModule(cert) == "" {
988 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900989 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
990 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900991 } else if cert == "" {
992 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900993 a.container_certificate_file = pem
994 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900995 }
996
Colin Cross8a497952019-03-05 22:25:09 -0800997 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900998
Alex Light5098a612018-11-29 17:12:15 -0800999 var abis []string
1000 for _, target := range ctx.MultiTargets() {
1001 if len(target.Arch.Abi) > 0 {
1002 abis = append(abis, target.Arch.Abi[0])
1003 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001004 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001005
Alex Light5098a612018-11-29 17:12:15 -08001006 abis = android.FirstUniqueStrings(abis)
1007
1008 suffix := apexType.suffix()
1009 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001010
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001011 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001012 for _, f := range a.filesInfo {
1013 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001014 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001015
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016 copyCommands := []string{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001017 for i, src := range filesToCopy {
1018 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Alex Light5098a612018-11-29 17:12:15 -08001019 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001020 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1021 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001022 for _, sym := range a.filesInfo[i].symlinks {
1023 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1024 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1025 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001027 implicitInputs := append(android.Paths(nil), filesToCopy...)
Alex Light5098a612018-11-29 17:12:15 -08001028 implicitInputs = append(implicitInputs, manifest)
1029
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001030 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1031 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001032
Alex Light5098a612018-11-29 17:12:15 -08001033 if apexType.image() {
1034 // files and dirs that will be created in APEX
1035 var readOnlyPaths []string
1036 var executablePaths []string // this also includes dirs
1037 for _, f := range a.filesInfo {
1038 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001039 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001040 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001041 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001042 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001043 }
Alex Light5098a612018-11-29 17:12:15 -08001044 } else {
1045 readOnlyPaths = append(readOnlyPaths, pathInApex)
1046 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001047 dir := f.installDir
1048 for !android.InList(dir, executablePaths) && dir != "" {
1049 executablePaths = append(executablePaths, dir)
1050 dir, _ = filepath.Split(dir) // move up to the parent
1051 if len(dir) > 0 {
1052 // remove trailing slash
1053 dir = dir[:len(dir)-1]
1054 }
Alex Light5098a612018-11-29 17:12:15 -08001055 }
1056 }
1057 sort.Strings(readOnlyPaths)
1058 sort.Strings(executablePaths)
1059 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1060 ctx.Build(pctx, android.BuildParams{
1061 Rule: generateFsConfig,
1062 Output: cannedFsConfig,
1063 Description: "generate fs config",
1064 Args: map[string]string{
1065 "ro_paths": strings.Join(readOnlyPaths, " "),
1066 "exec_paths": strings.Join(executablePaths, " "),
1067 },
1068 })
1069
1070 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1071 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1072 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1073 if !fileContextsOptionalPath.Valid() {
1074 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1075 return
1076 }
1077 fileContexts := fileContextsOptionalPath.Path()
1078
Jiyong Park835d82b2018-12-27 16:04:18 +09001079 optFlags := []string{}
1080
Alex Light5098a612018-11-29 17:12:15 -08001081 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001082 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1083 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001084
Jiyong Park7f67f482019-01-05 12:57:48 +09001085 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1086 if overridden {
1087 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1088 }
1089
Jiyong Park40e26a22019-02-08 02:53:06 +09001090 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001091 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001092 implicitInputs = append(implicitInputs, androidManifestFile)
1093 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1094 }
1095
Jiyong Park71b519d2019-04-18 17:25:49 +09001096 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1097 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1098 ctx.Config().UnbundledBuild() &&
1099 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1100 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1101 apiFingerprint := java.ApiFingerprintPath(ctx)
1102 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1103 implicitInputs = append(implicitInputs, apiFingerprint)
1104 }
1105 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1106
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001107 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1108 if noticeFile.Valid() {
1109 // If there's a NOTICE file, embed it as an asset file in the APEX.
1110 implicitInputs = append(implicitInputs, noticeFile.Path())
1111 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1112 }
1113
Alex Light5098a612018-11-29 17:12:15 -08001114 ctx.Build(pctx, android.BuildParams{
1115 Rule: apexRule,
1116 Implicits: implicitInputs,
1117 Output: unsignedOutputFile,
1118 Description: "apex (" + apexType.name() + ")",
1119 Args: map[string]string{
1120 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1121 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1122 "copy_commands": strings.Join(copyCommands, " && "),
1123 "manifest": manifest.String(),
1124 "file_contexts": fileContexts.String(),
1125 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001126 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001127 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001128 },
1129 })
1130
1131 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1132 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1133 a.bundleModuleFile = bundleModuleFile
1134
1135 ctx.Build(pctx, android.BuildParams{
1136 Rule: apexProtoConvertRule,
1137 Input: unsignedOutputFile,
1138 Output: apexProtoFile,
1139 Description: "apex proto convert",
1140 })
1141
1142 ctx.Build(pctx, android.BuildParams{
1143 Rule: apexBundleRule,
1144 Input: apexProtoFile,
1145 Output: a.bundleModuleFile,
1146 Description: "apex bundle module",
1147 Args: map[string]string{
1148 "abi": strings.Join(abis, "."),
1149 },
1150 })
1151 } else {
1152 ctx.Build(pctx, android.BuildParams{
1153 Rule: zipApexRule,
1154 Implicits: implicitInputs,
1155 Output: unsignedOutputFile,
1156 Description: "apex (" + apexType.name() + ")",
1157 Args: map[string]string{
1158 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1159 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1160 "copy_commands": strings.Join(copyCommands, " && "),
1161 "manifest": manifest.String(),
1162 },
1163 })
Colin Crossa4925902018-11-16 11:36:28 -08001164 }
Colin Crossa4925902018-11-16 11:36:28 -08001165
Alex Light5098a612018-11-29 17:12:15 -08001166 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001167 ctx.Build(pctx, android.BuildParams{
1168 Rule: java.Signapk,
1169 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001170 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001171 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001172 Implicits: []android.Path{
1173 a.container_certificate_file,
1174 a.container_private_key_file,
1175 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001176 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001177 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001178 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001179 },
1180 })
Alex Light5098a612018-11-29 17:12:15 -08001181
1182 // Install to $OUT/soong/{target,host}/.../apex
Alex Light2a2561f2019-02-12 16:59:09 -08001183 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001184 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001185 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001186}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001187
Jiyong Park8fd61922018-11-08 02:50:25 +09001188func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001189 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001190 // 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 +09001191 // with other ordinary files.
Colin Cross8a497952019-03-05 22:25:09 -08001192 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd699cb92019-01-10 00:23:16 +09001193
1194 // rename to apex_manifest.json
1195 copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json")
1196 ctx.Build(pctx, android.BuildParams{
1197 Rule: android.Cp,
1198 Input: manifest,
1199 Output: copiedManifest,
1200 })
Jiyong Park719b4462019-01-13 00:39:51 +09001201 a.filesInfo = append(a.filesInfo, apexFile{copiedManifest, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001202
Jiyong Park42cca6c2019-04-01 11:15:50 +09001203 // rename to apex_pubkey
1204 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1205 ctx.Build(pctx, android.BuildParams{
1206 Rule: android.Cp,
1207 Input: a.public_key_file,
1208 Output: copiedPubkey,
1209 })
1210 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1211
Jiyong Park23c52b02019-02-02 13:13:47 +09001212 if ctx.Config().FlattenApex() {
1213 for _, fi := range a.filesInfo {
1214 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001215 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1216 for _, sym := range fi.symlinks {
1217 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1218 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001219 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001220 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001221 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001222}
1223
1224func (a *apexBundle) AndroidMk() android.AndroidMkData {
Alex Light5098a612018-11-29 17:12:15 -08001225 writers := []android.AndroidMkData{}
1226 if a.apexTypes.image() {
1227 writers = append(writers, a.androidMkForType(imageApex))
1228 }
1229 if a.apexTypes.zip() {
1230 writers = append(writers, a.androidMkForType(zipApex))
1231 }
1232 return android.AndroidMkData{
1233 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1234 for _, data := range writers {
1235 data.Custom(w, name, prefix, moduleDir, data)
1236 }
1237 }}
1238}
1239
Alex Lightf1801bc2019-02-13 11:10:07 -08001240func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001241 moduleNames := []string{}
1242
1243 for _, fi := range a.filesInfo {
1244 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1245 continue
1246 }
1247 if !android.InList(fi.moduleName, moduleNames) {
1248 moduleNames = append(moduleNames, fi.moduleName)
1249 }
1250 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1251 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1252 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
Jiyong Park05e70dd2019-03-18 14:26:32 +09001253 // /apex/<name>/{lib|framework|...}
1254 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1255 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Alex Lightf1801bc2019-02-13 11:10:07 -08001256 if a.flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001257 // /system/apex/<name>/{lib|framework|...}
1258 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1259 a.installDir.RelPathString(), name, fi.installDir))
Jiyong Park05e70dd2019-03-18 14:26:32 +09001260 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
Alex Lightf4857cf2019-02-22 13:00:04 -08001261 if len(fi.symlinks) > 0 {
1262 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1263 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001264
1265 if fi.module != nil && fi.module.NoticeFile().Valid() {
1266 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1267 }
Jiyong Park94427262019-02-05 23:18:47 +09001268 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001269 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001270 }
1271 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1272 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1273 if fi.module != nil {
1274 archStr := fi.module.Target().Arch.ArchType.String()
1275 host := false
1276 switch fi.module.Target().Os.Class {
1277 case android.Host:
1278 if archStr != "common" {
1279 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1280 }
1281 host = true
1282 case android.HostCross:
1283 if archStr != "common" {
1284 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1285 }
1286 host = true
1287 case android.Device:
1288 if archStr != "common" {
1289 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1290 }
1291 }
1292 if host {
1293 makeOs := fi.module.Target().Os.String()
1294 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1295 makeOs = "linux"
1296 }
1297 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1298 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1299 }
1300 }
1301 if fi.class == javaSharedLib {
1302 javaModule := fi.module.(*java.Library)
1303 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1304 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1305 // we will have foo.jar.jar
1306 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1307 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1308 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1309 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1310 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1311 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
1312 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable {
1313 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001314 if cc, ok := fi.module.(*cc.Module); ok {
1315 if cc.UnstrippedOutputFile() != nil {
1316 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1317 }
1318 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Park94427262019-02-05 23:18:47 +09001319 }
1320 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1321 } else {
1322 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1323 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1324 }
1325 }
1326 return moduleNames
1327}
1328
Alex Light5098a612018-11-29 17:12:15 -08001329func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001330 return android.AndroidMkData{
1331 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1332 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001333 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001334 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001335 }
1336
Jiyong Park719b4462019-01-13 00:39:51 +09001337 if a.flattened && apexType.image() {
1338 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001339 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1340 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1341 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001342 if len(moduleNames) > 0 {
1343 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1344 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001345 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park719b4462019-01-13 00:39:51 +09001346 } else {
Alex Light5098a612018-11-29 17:12:15 -08001347 // zip-apex is the less common type so have the name refer to the image-apex
1348 // only and use {name}.zip if you want the zip-apex
1349 if apexType == zipApex && a.apexTypes == both {
1350 name = name + ".zip"
1351 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001352 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1353 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1354 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1355 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001356 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001357 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001358 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001359 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001360 if len(moduleNames) > 0 {
1361 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1362 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001363 if len(a.externalDeps) > 0 {
1364 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1365 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001366 if a.prebuiltFileToDelete != "" {
1367 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1368 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1369 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001370 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001371
Alex Light5098a612018-11-29 17:12:15 -08001372 if apexType == imageApex {
1373 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1374 }
Jiyong Park719b4462019-01-13 00:39:51 +09001375 }
1376 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001377}
1378
Alex Light0851b882019-02-07 13:20:53 -08001379func testApexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001380 return ApexBundleFactory(true /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001381}
1382
1383func apexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001384 return ApexBundleFactory(false /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001385}
1386
1387func ApexBundleFactory(testApex bool) android.Module {
Alex Light5098a612018-11-29 17:12:15 -08001388 module := &apexBundle{
1389 outputFiles: map[apexPackaging]android.WritablePath{},
Alex Light0851b882019-02-07 13:20:53 -08001390 testApex: testApex,
Alex Light5098a612018-11-29 17:12:15 -08001391 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001392 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001393 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001394 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001395 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1396 })
Alex Light5098a612018-11-29 17:12:15 -08001397 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001398 android.InitDefaultableModule(module)
1399 return module
1400}
Jiyong Park30ca9372019-02-07 16:27:23 +09001401
1402//
1403// Defaults
1404//
1405type Defaults struct {
1406 android.ModuleBase
1407 android.DefaultsModuleBase
1408}
1409
Jiyong Park30ca9372019-02-07 16:27:23 +09001410func defaultsFactory() android.Module {
1411 return DefaultsFactory()
1412}
1413
1414func DefaultsFactory(props ...interface{}) android.Module {
1415 module := &Defaults{}
1416
1417 module.AddProperties(props...)
1418 module.AddProperties(
1419 &apexBundleProperties{},
1420 &apexTargetBundleProperties{},
1421 )
1422
1423 android.InitDefaultsModule(module)
1424 return module
1425}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001426
1427//
1428// Prebuilt APEX
1429//
1430type Prebuilt struct {
1431 android.ModuleBase
1432 prebuilt android.Prebuilt
1433
1434 properties PrebuiltProperties
1435
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001436 inputApex android.Path
1437 installDir android.OutputPath
1438 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001439 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001440}
1441
1442type PrebuiltProperties struct {
1443 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001444 Source string `blueprint:"mutated"`
1445 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001446
1447 Src *string
1448 Arch struct {
1449 Arm struct {
1450 Src *string
1451 }
1452 Arm64 struct {
1453 Src *string
1454 }
1455 X86 struct {
1456 Src *string
1457 }
1458 X86_64 struct {
1459 Src *string
1460 }
1461 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001462
1463 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001464 // Optional name for the installed apex. If unspecified, name of the
1465 // module is used as the file name
1466 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001467
1468 // Names of modules to be overridden. Listed modules can only be other binaries
1469 // (in Make or Soong).
1470 // This does not completely prevent installation of the overridden binaries, but if both
1471 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1472 // from PRODUCT_PACKAGES.
1473 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001474}
1475
1476func (p *Prebuilt) installable() bool {
1477 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001478}
1479
1480func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001481 // If the device is configured to use flattened APEX, force disable the prebuilt because
1482 // the prebuilt is a non-flattened one.
1483 forceDisable := ctx.Config().FlattenApex()
1484
1485 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1486 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001487 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001488
1489 // b/137216042 don't use prebuilts when address sanitizer is on
1490 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1491 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1492
1493 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001494 p.properties.ForceDisable = true
1495 return
1496 }
1497
Jiyong Parkc95714e2019-03-29 14:23:10 +09001498 // This is called before prebuilt_select and prebuilt_postdeps mutators
1499 // The mutators requires that src to be set correctly for each arch so that
1500 // arch variants are disabled when src is not provided for the arch.
1501 if len(ctx.MultiTargets()) != 1 {
1502 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1503 return
1504 }
1505 var src string
1506 switch ctx.MultiTargets()[0].Arch.ArchType {
1507 case android.Arm:
1508 src = String(p.properties.Arch.Arm.Src)
1509 case android.Arm64:
1510 src = String(p.properties.Arch.Arm64.Src)
1511 case android.X86:
1512 src = String(p.properties.Arch.X86.Src)
1513 case android.X86_64:
1514 src = String(p.properties.Arch.X86_64.Src)
1515 default:
1516 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1517 return
1518 }
1519 if src == "" {
1520 src = String(p.properties.Src)
1521 }
1522 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001523}
1524
Jiyong Park03b68dd2019-07-26 23:20:40 +09001525func (p *Prebuilt) isForceDisabled() bool {
1526 return p.properties.ForceDisable
1527}
1528
Colin Cross41955e82019-05-29 14:40:35 -07001529func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1530 switch tag {
1531 case "":
1532 return android.Paths{p.outputApex}, nil
1533 default:
1534 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1535 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001536}
1537
Jiyong Park4d277042019-04-23 18:00:10 +09001538func (p *Prebuilt) InstallFilename() string {
1539 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1540}
1541
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001542func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001543 if p.properties.ForceDisable {
1544 return
1545 }
1546
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001547 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001548 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001549 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001550 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001551 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1552 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1553 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001554 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1555 ctx.Build(pctx, android.BuildParams{
1556 Rule: android.Cp,
1557 Input: p.inputApex,
1558 Output: p.outputApex,
1559 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001560 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001561 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001562 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001563}
1564
1565func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1566 return &p.prebuilt
1567}
1568
1569func (p *Prebuilt) Name() string {
1570 return p.prebuilt.Name(p.ModuleBase.Name())
1571}
1572
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001573func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1574 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001575 Class: "ETC",
1576 OutputFile: android.OptionalPathForPath(p.inputApex),
1577 Include: "$(BUILD_PREBUILT)",
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001578 AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
1579 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1580 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1581 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1582 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001583 },
1584 }
1585}
1586
1587// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1588func PrebuiltFactory() android.Module {
1589 module := &Prebuilt{}
1590 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001591 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001592 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001593 return module
1594}