blob: f72eef3a9b829625748317266f08bb80b13c7b51 [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}",
64 "${soong_zip}", "${zipalign}", "${aapt2}"},
65 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"}
111 keyTag = dependencyTag{name: "key"}
112 certificateTag = dependencyTag{name: "certificate"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900113)
114
115func init() {
116 pctx.Import("android/soong/common")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900117 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900118 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100119 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
120 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
121 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
122 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000123 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100124 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
125 } else {
126 return pctx.HostBinToolPath(ctx, tool).String()
127 }
128 })
129 }
130 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900131 pctx.HostBinToolVariable("avbtool", "avbtool")
132 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
133 pctx.HostBinToolVariable("merge_zips", "merge_zips")
134 pctx.HostBinToolVariable("mke2fs", "mke2fs")
135 pctx.HostBinToolVariable("resize2fs", "resize2fs")
136 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
137 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800138 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900139 pctx.HostBinToolVariable("zipalign", "zipalign")
140
Alex Light0851b882019-02-07 13:20:53 -0800141 android.RegisterModuleType("apex", apexBundleFactory)
142 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900143 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900144
145 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
146 ctx.TopDown("apex_deps", apexDepsMutator)
147 ctx.BottomUp("apex", apexMutator)
148 })
149}
150
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900151// Mark the direct and transitive dependencies of apex bundles so that they
152// can be built for the apex bundles.
153func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800154 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800155 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900156 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900157 depName := mctx.OtherModuleName(child)
158 // If the parent is apexBundle, this child is directly depended.
159 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800160 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800161 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
162 // non-installable apex's cannot be installed and so should not prevent libraries from being
163 // installed to the system.
164 android.UpdateApexDependency(apexBundleName, depName, directDep)
165 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900166
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900167 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900168 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900169 return true
170 } else {
171 return false
172 }
173 })
174 }
175}
176
177// Create apex variations if a module is included in APEX(s).
178func apexMutator(mctx android.BottomUpMutatorContext) {
179 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900180 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900181 } else if _, ok := mctx.Module().(*apexBundle); ok {
182 // apex bundle itself is mutated so that it and its modules have same
183 // apex variant.
184 apexBundleName := mctx.ModuleName()
185 mctx.CreateVariations(apexBundleName)
186 }
187}
188
Alex Light9670d332019-01-29 18:07:33 -0800189type apexNativeDependencies struct {
190 // List of native libraries
191 Native_shared_libs []string
192 // List of native executables
193 Binaries []string
194}
195type apexMultilibProperties struct {
196 // Native dependencies whose compile_multilib is "first"
197 First apexNativeDependencies
198
199 // Native dependencies whose compile_multilib is "both"
200 Both apexNativeDependencies
201
202 // Native dependencies whose compile_multilib is "prefer32"
203 Prefer32 apexNativeDependencies
204
205 // Native dependencies whose compile_multilib is "32"
206 Lib32 apexNativeDependencies
207
208 // Native dependencies whose compile_multilib is "64"
209 Lib64 apexNativeDependencies
210}
211
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900212type apexBundleProperties struct {
213 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000214 // "apex_manifest.json"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900215 Manifest *string
216
Jiyong Park40e26a22019-02-08 02:53:06 +0900217 // AndroidManifest.xml file used for the zip container of this APEX bundle.
218 // If unspecified, a default one is automatically generated.
219 AndroidManifest *string
220
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900221 // Determines the file contexts file for setting security context to each file in this APEX bundle.
222 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
223 // used.
224 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900225 File_contexts *string
226
227 // List of native shared libs that are embedded inside this APEX bundle
228 Native_shared_libs []string
229
230 // List of native executables that are embedded inside this APEX bundle
231 Binaries []string
232
233 // List of java libraries that are embedded inside this APEX bundle
234 Java_libs []string
235
236 // List of prebuilt files that are embedded inside this APEX bundle
237 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900238
239 // Name of the apex_key module that provides the private key to sign APEX
240 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900241
Alex Light5098a612018-11-29 17:12:15 -0800242 // The type of APEX to build. Controls what the APEX payload is. Either
243 // 'image', 'zip' or 'both'. Default: 'image'.
244 Payload_type *string
245
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900246 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
247 // or an android_app_certificate module name in the form ":module".
248 Certificate *string
249
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900250 // Whether this APEX is installable to one of the partitions. Default: true.
251 Installable *bool
252
Jiyong Parkda6eb592018-12-19 17:12:36 +0900253 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
254 // Default is false.
255 Use_vendor *bool
256
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800257 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
258 Ignore_system_library_special_case *bool
259
Alex Light9670d332019-01-29 18:07:33 -0800260 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900261
Jiyong Parkf97782b2019-02-13 20:28:58 +0900262 // List of sanitizer names that this APEX is enabled for
263 SanitizerNames []string `blueprint:"mutated"`
Alex Light9670d332019-01-29 18:07:33 -0800264}
265
266type apexTargetBundleProperties struct {
267 Target struct {
268 // Multilib properties only for android.
269 Android struct {
270 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900271 }
Alex Light9670d332019-01-29 18:07:33 -0800272 // Multilib properties only for host.
273 Host struct {
274 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900275 }
Alex Light9670d332019-01-29 18:07:33 -0800276 // Multilib properties only for host linux_bionic.
277 Linux_bionic struct {
278 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900279 }
Alex Light9670d332019-01-29 18:07:33 -0800280 // Multilib properties only for host linux_glibc.
281 Linux_glibc struct {
282 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900283 }
284 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900285}
286
Jiyong Park8fd61922018-11-08 02:50:25 +0900287type apexFileClass int
288
289const (
290 etc apexFileClass = iota
291 nativeSharedLib
292 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900293 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800294 pyBinary
295 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900296 javaSharedLib
297)
298
Alex Light5098a612018-11-29 17:12:15 -0800299type apexPackaging int
300
301const (
302 imageApex apexPackaging = iota
303 zipApex
304 both
305)
306
307func (a apexPackaging) image() bool {
308 switch a {
309 case imageApex, both:
310 return true
311 }
312 return false
313}
314
315func (a apexPackaging) zip() bool {
316 switch a {
317 case zipApex, both:
318 return true
319 }
320 return false
321}
322
323func (a apexPackaging) suffix() string {
324 switch a {
325 case imageApex:
326 return imageApexSuffix
327 case zipApex:
328 return zipApexSuffix
329 case both:
330 panic(fmt.Errorf("must be either zip or image"))
331 default:
332 panic(fmt.Errorf("unkonwn APEX type %d", a))
333 }
334}
335
336func (a apexPackaging) name() string {
337 switch a {
338 case imageApex:
339 return imageApexType
340 case zipApex:
341 return zipApexType
342 case both:
343 panic(fmt.Errorf("must be either zip or image"))
344 default:
345 panic(fmt.Errorf("unkonwn APEX type %d", a))
346 }
347}
348
Jiyong Park8fd61922018-11-08 02:50:25 +0900349func (class apexFileClass) NameInMake() string {
350 switch class {
351 case etc:
352 return "ETC"
353 case nativeSharedLib:
354 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800355 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900356 return "EXECUTABLES"
357 case javaSharedLib:
358 return "JAVA_LIBRARIES"
359 default:
360 panic(fmt.Errorf("unkonwn class %d", class))
361 }
362}
363
364type apexFile struct {
365 builtFile android.Path
366 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900367 installDir string
368 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900369 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800370 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900371}
372
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900373type apexBundle struct {
374 android.ModuleBase
375 android.DefaultableModuleBase
376
Alex Light9670d332019-01-29 18:07:33 -0800377 properties apexBundleProperties
378 targetProperties apexTargetBundleProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900379
Alex Light5098a612018-11-29 17:12:15 -0800380 apexTypes apexPackaging
381
Colin Crossa4925902018-11-16 11:36:28 -0800382 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800383 outputFiles map[apexPackaging]android.WritablePath
Colin Crossa4925902018-11-16 11:36:28 -0800384 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900385
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900386 public_key_file android.Path
387 private_key_file android.Path
388 bundle_public_key bool
389
390 container_certificate_file android.Path
391 container_private_key_file android.Path
392
Jiyong Park8fd61922018-11-08 02:50:25 +0900393 // list of files to be included in this apex
394 filesInfo []apexFile
395
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900396 // list of module names that this APEX is depending on
397 externalDeps []string
398
Jiyong Park8fd61922018-11-08 02:50:25 +0900399 flattened bool
Alex Light0851b882019-02-07 13:20:53 -0800400
401 testApex bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900402}
403
Jiyong Park397e55e2018-10-24 21:09:55 +0900404func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900405 native_shared_libs []string, binaries []string, arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900406 // Use *FarVariation* to be able to depend on modules having
407 // conflicting variations with this module. This is required since
408 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
409 // for native shared libs.
410 ctx.AddFarVariationDependencies([]blueprint.Variation{
411 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900412 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900413 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900414 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900415 }, sharedLibTag, native_shared_libs...)
416
417 ctx.AddFarVariationDependencies([]blueprint.Variation{
418 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900419 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900420 }, executableTag, binaries...)
421}
422
Alex Light9670d332019-01-29 18:07:33 -0800423func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
424 if ctx.Os().Class == android.Device {
425 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
426 } else {
427 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
428 if ctx.Os().Bionic() {
429 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
430 } else {
431 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
432 }
433 }
434}
435
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900436func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800437
Jiyong Park397e55e2018-10-24 21:09:55 +0900438 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900439 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800440
441 a.combineProperties(ctx)
442
Jiyong Park397e55e2018-10-24 21:09:55 +0900443 has32BitTarget := false
444 for _, target := range targets {
445 if target.Arch.ArchType.Multilib == "lib32" {
446 has32BitTarget = true
447 }
448 }
449 for i, target := range targets {
450 // When multilib.* is omitted for native_shared_libs, it implies
451 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900452 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900453 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900454 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900455 {Mutator: "link", Variation: "shared"},
456 }, sharedLibTag, a.properties.Native_shared_libs...)
457
Jiyong Park397e55e2018-10-24 21:09:55 +0900458 // Add native modules targetting both ABIs
459 addDependenciesForNativeModules(ctx,
460 a.properties.Multilib.Both.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900461 a.properties.Multilib.Both.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900462 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900463
Alex Light3d673592019-01-18 14:37:31 -0800464 isPrimaryAbi := i == 0
465 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900466 // When multilib.* is omitted for binaries, it implies
467 // multilib.first.
468 ctx.AddFarVariationDependencies([]blueprint.Variation{
469 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900470 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900471 }, executableTag, a.properties.Binaries...)
472
473 // Add native modules targetting the first ABI
474 addDependenciesForNativeModules(ctx,
475 a.properties.Multilib.First.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900476 a.properties.Multilib.First.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900477 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800478
479 // When multilib.* is omitted for prebuilts, it implies multilib.first.
480 ctx.AddFarVariationDependencies([]blueprint.Variation{
481 {Mutator: "arch", Variation: target.String()},
482 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900483 }
484
485 switch target.Arch.ArchType.Multilib {
486 case "lib32":
487 // Add native modules targetting 32-bit ABI
488 addDependenciesForNativeModules(ctx,
489 a.properties.Multilib.Lib32.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900490 a.properties.Multilib.Lib32.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900491 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900492
493 addDependenciesForNativeModules(ctx,
494 a.properties.Multilib.Prefer32.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900495 a.properties.Multilib.Prefer32.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900496 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900497 case "lib64":
498 // Add native modules targetting 64-bit ABI
499 addDependenciesForNativeModules(ctx,
500 a.properties.Multilib.Lib64.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900501 a.properties.Multilib.Lib64.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900502 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900503
504 if !has32BitTarget {
505 addDependenciesForNativeModules(ctx,
506 a.properties.Multilib.Prefer32.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900507 a.properties.Multilib.Prefer32.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900508 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900509 }
510 }
511
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900512 }
513
Jiyong Parkff1458f2018-10-12 21:49:38 +0900514 ctx.AddFarVariationDependencies([]blueprint.Variation{
515 {Mutator: "arch", Variation: "android_common"},
516 }, javaLibTag, a.properties.Java_libs...)
517
Jiyong Park23c52b02019-02-02 13:13:47 +0900518 if String(a.properties.Key) == "" {
519 ctx.ModuleErrorf("key is missing")
520 return
521 }
522 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900523
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900524 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900525 if cert != "" {
526 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900527 }
Jiyong Park809bb722019-02-13 21:33:49 +0900528
529 if String(a.properties.Manifest) != "" {
530 android.ExtractSourceDeps(ctx, a.properties.Manifest)
531 }
532
533 if String(a.properties.AndroidManifest) != "" {
534 android.ExtractSourceDeps(ctx, a.properties.AndroidManifest)
535 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900536}
537
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900538func (a *apexBundle) getCertString(ctx android.BaseContext) string {
539 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
540 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000541 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900542 }
543 return String(a.properties.Certificate)
544}
545
Jiyong Park74e240b2018-11-27 21:27:08 +0900546func (a *apexBundle) Srcs() android.Paths {
Jiyong Park5a832022018-12-20 09:54:35 +0900547 if file, ok := a.outputFiles[imageApex]; ok {
548 return android.Paths{file}
549 } else {
550 return nil
551 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900552}
553
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900554func (a *apexBundle) installable() bool {
555 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
556}
557
Jiyong Park7c1dc612019-01-05 11:15:24 +0900558func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
559 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900560 return "vendor"
561 } else {
562 return "core"
563 }
564}
565
Jiyong Parkf97782b2019-02-13 20:28:58 +0900566func (a *apexBundle) EnableSanitizer(sanitizerName string) {
567 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
568 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
569 }
570}
571
Jiyong Park388ef3f2019-01-28 19:47:32 +0900572func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900573 if android.InList(sanitizerName, a.properties.SanitizerNames) {
574 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900575 }
576
577 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900578 globalSanitizerNames := []string{}
579 if a.Host() {
580 globalSanitizerNames = ctx.Config().SanitizeHost()
581 } else {
582 arches := ctx.Config().SanitizeDeviceArch()
583 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
584 globalSanitizerNames = ctx.Config().SanitizeDevice()
585 }
586 }
587 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900588}
589
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800590func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900591 // Decide the APEX-local directory by the multilib of the library
592 // In the future, we may query this to the module.
593 switch cc.Arch().ArchType.Multilib {
594 case "lib32":
595 dirInApex = "lib"
596 case "lib64":
597 dirInApex = "lib64"
598 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900599 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900600 if !cc.Arch().Native {
601 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
602 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800603 if handleSpecialLibs {
604 switch cc.Name() {
605 case "libc", "libm", "libdl":
606 // Special case for bionic libs. This is to prevent the bionic libs
607 // from being included in the search path /apex/com.android.apex/lib.
608 // This exclusion is required because bionic libs in the runtime APEX
609 // are available via the legacy paths /system/lib/libc.so, etc. By the
610 // init process, the bionic libs in the APEX are bind-mounted to the
611 // legacy paths and thus will be loaded into the default linker namespace.
612 // If the bionic libs are directly in /apex/com.android.apex/lib then
613 // the same libs will be again loaded to the runtime linker namespace,
614 // which will result double loading of bionic libs that isn't supported.
615 dirInApex = filepath.Join(dirInApex, "bionic")
616 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900617 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900618
619 fileToCopy = cc.OutputFile().Path()
620 return
621}
622
623func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900624 // TODO(b/123721777) respect relative_install_path also for binaries
625 // dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900626 dirInApex = "bin"
627 fileToCopy = cc.OutputFile().Path()
628 return
629}
630
Alex Light778127a2019-02-27 14:19:50 -0800631func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
632 dirInApex = "bin"
633 fileToCopy = py.HostToolPath().Path()
634 return
635}
636func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
637 dirInApex = "bin"
638 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
639 if err != nil {
640 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
641 return
642 }
643 fileToCopy = android.PathForOutput(ctx, s)
644 return
645}
646
Jiyong Park04480cf2019-02-06 00:16:29 +0900647func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
648 dirInApex = filepath.Join("bin", sh.SubDir())
649 fileToCopy = sh.OutputFile()
650 return
651}
652
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900653func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
654 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900655 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900656 return
657}
658
659func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
660 dirInApex = filepath.Join("etc", prebuilt.SubDir())
661 fileToCopy = prebuilt.OutputFile()
662 return
663}
664
665func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900666 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900667
Alex Light5098a612018-11-29 17:12:15 -0800668 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
669 a.apexTypes = imageApex
670 } else if *a.properties.Payload_type == "zip" {
671 a.apexTypes = zipApex
672 } else if *a.properties.Payload_type == "both" {
673 a.apexTypes = both
674 } else {
675 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
676 return
677 }
678
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800679 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
680
Alex Light778127a2019-02-27 14:19:50 -0800681 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900682 if _, ok := parent.(*apexBundle); ok {
683 // direct dependencies
684 depTag := ctx.OtherModuleDependencyTag(child)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900685 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900686 switch depTag {
687 case sharedLibTag:
688 if cc, ok := child.(*cc.Module); ok {
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800689 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900690 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900691 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900692 } else {
693 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900694 }
695 case executableTag:
696 if cc, ok := child.(*cc.Module); ok {
Alex Light16df4e82019-01-24 11:37:55 -0800697 if !cc.Arch().Native {
698 // There is only one 'bin' directory so we shouldn't bother copying in
699 // native-bridge'd binaries and only use main ones.
700 return true
701 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900702 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900703 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900704 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900705 } else if sh, ok := child.(*android.ShBinary); ok {
706 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
707 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -0800708 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
709 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
710 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
711 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
712 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
713 // NB: Since go binaries are static we don't need the module for anything here, which is
714 // good since the go tool is a blueprint.Module not an android.Module like we would
715 // normally use.
716 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900717 } else {
Alex Light778127a2019-02-27 14:19:50 -0800718 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 +0900719 }
720 case javaLibTag:
721 if java, ok := child.(*java.Library); ok {
722 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java)
Jiyong Park8fd61922018-11-08 02:50:25 +0900723 if fileToCopy == nil {
724 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
725 } else {
Jiyong Park719b4462019-01-13 00:39:51 +0900726 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900727 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900728 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900729 } else {
730 ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900731 }
732 case prebuiltTag:
733 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
734 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900735 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900736 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900737 } else {
738 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
739 }
740 case keyTag:
741 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900742 a.private_key_file = key.private_key_file
743 a.public_key_file = key.public_key_file
744 // If the key is not installed, bundled it with the APEX.
745 // Note: this bundled key is valid only for non-production builds
746 // (eng/userdebug).
747 a.bundle_public_key = !key.installable() && ctx.Config().Debuggable()
Jiyong Parkff1458f2018-10-12 21:49:38 +0900748 return false
749 } else {
750 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900751 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900752 case certificateTag:
753 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900754 a.container_certificate_file = dep.Certificate.Pem
755 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900756 return false
757 } else {
758 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
759 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900760 }
761 } else {
762 // indirect dependencies
763 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() {
764 if cc, ok := child.(*cc.Module); ok {
Alex Light49ae3d92019-02-21 14:02:46 -0800765 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900766 // If the dependency is a stubs lib, don't include it in this APEX,
767 // but make sure that the lib is installed on the device.
768 // In case no APEX is having the lib, the lib is installed to the system
769 // partition.
Alex Light49ae3d92019-02-21 14:02:46 -0800770 //
771 // Always include if we are a host-apex however since those won't have any
772 // system libraries.
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900773 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
774 a.externalDeps = append(a.externalDeps, cc.Name())
775 }
776 // Don't track further
Jiyong Park25fc6a92018-11-18 18:02:45 +0900777 return false
778 }
Jiyong Park8fd61922018-11-08 02:50:25 +0900779 depName := ctx.OtherModuleName(child)
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800780 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900781 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900782 return true
783 }
784 }
785 }
786 return false
787 })
788
Jiyong Park9335a262018-12-24 11:31:58 +0900789 a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900790 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +0900791 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
792 return
793 }
794
Jiyong Park8fd61922018-11-08 02:50:25 +0900795 // remove duplicates in filesInfo
796 removeDup := func(filesInfo []apexFile) []apexFile {
797 encountered := make(map[android.Path]bool)
798 result := []apexFile{}
799 for _, f := range filesInfo {
800 if !encountered[f.builtFile] {
801 encountered[f.builtFile] = true
802 result = append(result, f)
803 }
804 }
805 return result
806 }
807 filesInfo = removeDup(filesInfo)
808
809 // to have consistent build rules
810 sort.Slice(filesInfo, func(i, j int) bool {
811 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
812 })
813
814 // prepend the name of this APEX to the module names. These names will be the names of
815 // modules that will be defined if the APEX is flattened.
816 for i := range filesInfo {
817 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
818 }
819
Jiyong Park8fd61922018-11-08 02:50:25 +0900820 a.installDir = android.PathForModuleInstall(ctx, "apex")
821 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -0800822
823 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900824 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -0800825 }
826 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +0900827 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
828 // is true. This is to support referencing APEX via ":<module_name" syntax
829 // in other modules. It is in AndroidMk where the selection of flattened
830 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900831 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +0900832 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +0900833 }
834}
835
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900836func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900837 cert := String(a.properties.Certificate)
838 if cert != "" && android.SrcIsModule(cert) == "" {
839 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900840 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
841 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900842 } else if cert == "" {
843 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900844 a.container_certificate_file = pem
845 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900846 }
847
Jiyong Park809bb722019-02-13 21:33:49 +0900848 manifest := ctx.ExpandSource(proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"), "manifest")
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900849
Alex Light5098a612018-11-29 17:12:15 -0800850 var abis []string
851 for _, target := range ctx.MultiTargets() {
852 if len(target.Arch.Abi) > 0 {
853 abis = append(abis, target.Arch.Abi[0])
854 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900855 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900856
Alex Light5098a612018-11-29 17:12:15 -0800857 abis = android.FirstUniqueStrings(abis)
858
859 suffix := apexType.suffix()
860 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861
Jiyong Parkab3ceb32018-10-10 14:05:29 +0900862 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +0900863 for _, f := range a.filesInfo {
864 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900865 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +0900866
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900867 copyCommands := []string{}
Jiyong Park8fd61922018-11-08 02:50:25 +0900868 for i, src := range filesToCopy {
869 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Alex Light5098a612018-11-29 17:12:15 -0800870 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900871 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
872 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -0800873 for _, sym := range a.filesInfo[i].symlinks {
874 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
875 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
876 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +0900878 implicitInputs := append(android.Paths(nil), filesToCopy...)
Alex Light5098a612018-11-29 17:12:15 -0800879 implicitInputs = append(implicitInputs, manifest)
880
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900881 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
882 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900883
Alex Light5098a612018-11-29 17:12:15 -0800884 if apexType.image() {
885 // files and dirs that will be created in APEX
886 var readOnlyPaths []string
887 var executablePaths []string // this also includes dirs
888 for _, f := range a.filesInfo {
889 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
890 if f.installDir == "bin" {
891 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -0800892 for _, s := range f.symlinks {
893 executablePaths = append(executablePaths, filepath.Join("bin", s))
894 }
Alex Light5098a612018-11-29 17:12:15 -0800895 } else {
896 readOnlyPaths = append(readOnlyPaths, pathInApex)
897 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900898 dir := f.installDir
899 for !android.InList(dir, executablePaths) && dir != "" {
900 executablePaths = append(executablePaths, dir)
901 dir, _ = filepath.Split(dir) // move up to the parent
902 if len(dir) > 0 {
903 // remove trailing slash
904 dir = dir[:len(dir)-1]
905 }
Alex Light5098a612018-11-29 17:12:15 -0800906 }
907 }
908 sort.Strings(readOnlyPaths)
909 sort.Strings(executablePaths)
910 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
911 ctx.Build(pctx, android.BuildParams{
912 Rule: generateFsConfig,
913 Output: cannedFsConfig,
914 Description: "generate fs config",
915 Args: map[string]string{
916 "ro_paths": strings.Join(readOnlyPaths, " "),
917 "exec_paths": strings.Join(executablePaths, " "),
918 },
919 })
920
921 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
922 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
923 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
924 if !fileContextsOptionalPath.Valid() {
925 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
926 return
927 }
928 fileContexts := fileContextsOptionalPath.Path()
929
Jiyong Park835d82b2018-12-27 16:04:18 +0900930 optFlags := []string{}
931
Alex Light5098a612018-11-29 17:12:15 -0800932 // Additional implicit inputs.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900933 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file)
934 if a.bundle_public_key {
935 implicitInputs = append(implicitInputs, a.public_key_file)
936 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Jiyong Park835d82b2018-12-27 16:04:18 +0900937 }
Alex Light5098a612018-11-29 17:12:15 -0800938
Jiyong Park7f67f482019-01-05 12:57:48 +0900939 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
940 if overridden {
941 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
942 }
943
Jiyong Park40e26a22019-02-08 02:53:06 +0900944 if a.properties.AndroidManifest != nil {
Jiyong Park809bb722019-02-13 21:33:49 +0900945 androidManifestFile := ctx.ExpandSource(proptools.String(a.properties.AndroidManifest), "androidManifest")
Jiyong Park40e26a22019-02-08 02:53:06 +0900946 implicitInputs = append(implicitInputs, androidManifestFile)
947 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
948 }
949
Alex Light5098a612018-11-29 17:12:15 -0800950 ctx.Build(pctx, android.BuildParams{
951 Rule: apexRule,
952 Implicits: implicitInputs,
953 Output: unsignedOutputFile,
954 Description: "apex (" + apexType.name() + ")",
955 Args: map[string]string{
956 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
957 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
958 "copy_commands": strings.Join(copyCommands, " && "),
959 "manifest": manifest.String(),
960 "file_contexts": fileContexts.String(),
961 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900962 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +0900963 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -0800964 },
965 })
966
967 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
968 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
969 a.bundleModuleFile = bundleModuleFile
970
971 ctx.Build(pctx, android.BuildParams{
972 Rule: apexProtoConvertRule,
973 Input: unsignedOutputFile,
974 Output: apexProtoFile,
975 Description: "apex proto convert",
976 })
977
978 ctx.Build(pctx, android.BuildParams{
979 Rule: apexBundleRule,
980 Input: apexProtoFile,
981 Output: a.bundleModuleFile,
982 Description: "apex bundle module",
983 Args: map[string]string{
984 "abi": strings.Join(abis, "."),
985 },
986 })
987 } else {
988 ctx.Build(pctx, android.BuildParams{
989 Rule: zipApexRule,
990 Implicits: implicitInputs,
991 Output: unsignedOutputFile,
992 Description: "apex (" + apexType.name() + ")",
993 Args: map[string]string{
994 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
995 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
996 "copy_commands": strings.Join(copyCommands, " && "),
997 "manifest": manifest.String(),
998 },
999 })
Colin Crossa4925902018-11-16 11:36:28 -08001000 }
Colin Crossa4925902018-11-16 11:36:28 -08001001
Alex Light5098a612018-11-29 17:12:15 -08001002 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001003 ctx.Build(pctx, android.BuildParams{
1004 Rule: java.Signapk,
1005 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001006 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001007 Input: unsignedOutputFile,
1008 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001009 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001010 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001011 },
1012 })
Alex Light5098a612018-11-29 17:12:15 -08001013
1014 // Install to $OUT/soong/{target,host}/.../apex
Alex Light2a2561f2019-02-12 16:59:09 -08001015 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001016 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001017 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001018}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001019
Jiyong Park8fd61922018-11-08 02:50:25 +09001020func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001021 if a.installable() {
1022 // For flattened APEX, do nothing but make sure that apex_manifest.json file is also copied along
1023 // with other ordinary files.
Jiyong Park809bb722019-02-13 21:33:49 +09001024 manifest := ctx.ExpandSource(proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"), "manifest")
Jiyong Parkd699cb92019-01-10 00:23:16 +09001025
1026 // rename to apex_manifest.json
1027 copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json")
1028 ctx.Build(pctx, android.BuildParams{
1029 Rule: android.Cp,
1030 Input: manifest,
1031 Output: copiedManifest,
1032 })
Jiyong Park719b4462019-01-13 00:39:51 +09001033 a.filesInfo = append(a.filesInfo, apexFile{copiedManifest, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001034
Jiyong Park23c52b02019-02-02 13:13:47 +09001035 if ctx.Config().FlattenApex() {
1036 for _, fi := range a.filesInfo {
1037 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001038 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1039 for _, sym := range fi.symlinks {
1040 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1041 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001042 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001043 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001044 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001045}
1046
1047func (a *apexBundle) AndroidMk() android.AndroidMkData {
Alex Light5098a612018-11-29 17:12:15 -08001048 writers := []android.AndroidMkData{}
1049 if a.apexTypes.image() {
1050 writers = append(writers, a.androidMkForType(imageApex))
1051 }
1052 if a.apexTypes.zip() {
1053 writers = append(writers, a.androidMkForType(zipApex))
1054 }
1055 return android.AndroidMkData{
1056 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1057 for _, data := range writers {
1058 data.Custom(w, name, prefix, moduleDir, data)
1059 }
1060 }}
1061}
1062
Alex Lightf1801bc2019-02-13 11:10:07 -08001063func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001064 moduleNames := []string{}
1065
1066 for _, fi := range a.filesInfo {
1067 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1068 continue
1069 }
1070 if !android.InList(fi.moduleName, moduleNames) {
1071 moduleNames = append(moduleNames, fi.moduleName)
1072 }
1073 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1074 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1075 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
Alex Lightf1801bc2019-02-13 11:10:07 -08001076 if a.flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001077 // /system/apex/<name>/{lib|framework|...}
1078 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1079 a.installDir.RelPathString(), name, fi.installDir))
Alex Lightf4857cf2019-02-22 13:00:04 -08001080 if len(fi.symlinks) > 0 {
1081 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1082 }
Jiyong Park94427262019-02-05 23:18:47 +09001083 } else {
1084 // /apex/<name>/{lib|framework|...}
1085 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(PRODUCT_OUT)",
1086 "apex", name, fi.installDir))
1087 }
1088 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1089 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1090 if fi.module != nil {
1091 archStr := fi.module.Target().Arch.ArchType.String()
1092 host := false
1093 switch fi.module.Target().Os.Class {
1094 case android.Host:
1095 if archStr != "common" {
1096 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1097 }
1098 host = true
1099 case android.HostCross:
1100 if archStr != "common" {
1101 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1102 }
1103 host = true
1104 case android.Device:
1105 if archStr != "common" {
1106 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1107 }
1108 }
1109 if host {
1110 makeOs := fi.module.Target().Os.String()
1111 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1112 makeOs = "linux"
1113 }
1114 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1115 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1116 }
1117 }
1118 if fi.class == javaSharedLib {
1119 javaModule := fi.module.(*java.Library)
1120 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1121 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1122 // we will have foo.jar.jar
1123 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1124 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1125 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1126 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1127 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1128 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
1129 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable {
1130 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1131 if cc, ok := fi.module.(*cc.Module); ok && cc.UnstrippedOutputFile() != nil {
1132 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1133 }
1134 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1135 } else {
1136 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1137 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1138 }
1139 }
1140 return moduleNames
1141}
1142
Alex Light5098a612018-11-29 17:12:15 -08001143func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001144 return android.AndroidMkData{
1145 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1146 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001147 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001148 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001149 }
1150
Jiyong Park719b4462019-01-13 00:39:51 +09001151 if a.flattened && apexType.image() {
1152 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001153 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1154 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1155 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001156 if len(moduleNames) > 0 {
1157 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1158 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001159 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park719b4462019-01-13 00:39:51 +09001160 } else {
Alex Light5098a612018-11-29 17:12:15 -08001161 // zip-apex is the less common type so have the name refer to the image-apex
1162 // only and use {name}.zip if you want the zip-apex
1163 if apexType == zipApex && a.apexTypes == both {
1164 name = name + ".zip"
1165 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001166 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1167 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1168 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1169 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001170 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001171 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001172 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001173 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park8fd61922018-11-08 02:50:25 +09001174 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", String(a.properties.Key))
Jiyong Park94427262019-02-05 23:18:47 +09001175 if len(moduleNames) > 0 {
1176 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1177 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001178 if len(a.externalDeps) > 0 {
1179 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1180 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001181 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001182
Alex Light5098a612018-11-29 17:12:15 -08001183 if apexType == imageApex {
1184 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1185 }
Jiyong Park719b4462019-01-13 00:39:51 +09001186 }
1187 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001188}
1189
Alex Light0851b882019-02-07 13:20:53 -08001190func testApexBundleFactory() android.Module {
1191 return ApexBundleFactory( /*testApex*/ true)
1192}
1193
1194func apexBundleFactory() android.Module {
1195 return ApexBundleFactory( /*testApex*/ false)
1196}
1197
1198func ApexBundleFactory(testApex bool) android.Module {
Alex Light5098a612018-11-29 17:12:15 -08001199 module := &apexBundle{
1200 outputFiles: map[apexPackaging]android.WritablePath{},
Alex Light0851b882019-02-07 13:20:53 -08001201 testApex: testApex,
Alex Light5098a612018-11-29 17:12:15 -08001202 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001203 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001204 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001205 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001206 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1207 })
Alex Light5098a612018-11-29 17:12:15 -08001208 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001209 android.InitDefaultableModule(module)
1210 return module
1211}
Jiyong Park30ca9372019-02-07 16:27:23 +09001212
1213//
1214// Defaults
1215//
1216type Defaults struct {
1217 android.ModuleBase
1218 android.DefaultsModuleBase
1219}
1220
1221func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1222}
1223
1224func defaultsFactory() android.Module {
1225 return DefaultsFactory()
1226}
1227
1228func DefaultsFactory(props ...interface{}) android.Module {
1229 module := &Defaults{}
1230
1231 module.AddProperties(props...)
1232 module.AddProperties(
1233 &apexBundleProperties{},
1234 &apexTargetBundleProperties{},
1235 )
1236
1237 android.InitDefaultsModule(module)
1238 return module
1239}