blob: c1f52a60362b6eb1d9c6f791ba57adf6800b61a4 [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 Park52818fc2019-03-18 12:01:38 +090093
94 apexMergeNoticeRule = pctx.StaticRule("apexMergeNoticeRule", blueprint.RuleParams{
95 Command: `${mergenotice} --output $out $inputs`,
96 CommandDeps: []string{"${mergenotice}"},
97 Description: "merge notice files into $out",
98 }, "inputs")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090099)
100
Alex Light5098a612018-11-29 17:12:15 -0800101var imageApexSuffix = ".apex"
102var zipApexSuffix = ".zipapex"
103
104var imageApexType = "image"
105var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900106
107type dependencyTag struct {
108 blueprint.BaseDependencyTag
109 name string
110}
111
112var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900113 sharedLibTag = dependencyTag{name: "sharedLib"}
114 executableTag = dependencyTag{name: "executable"}
115 javaLibTag = dependencyTag{name: "javaLib"}
116 prebuiltTag = dependencyTag{name: "prebuilt"}
117 keyTag = dependencyTag{name: "key"}
118 certificateTag = dependencyTag{name: "certificate"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900119)
120
121func init() {
122 pctx.Import("android/soong/common")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900123 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900124 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100125 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
126 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
127 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
128 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000129 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100130 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
131 } else {
132 return pctx.HostBinToolPath(ctx, tool).String()
133 }
134 })
135 }
136 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900137 pctx.HostBinToolVariable("avbtool", "avbtool")
138 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
139 pctx.HostBinToolVariable("merge_zips", "merge_zips")
140 pctx.HostBinToolVariable("mke2fs", "mke2fs")
141 pctx.HostBinToolVariable("resize2fs", "resize2fs")
142 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
143 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800144 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900145 pctx.HostBinToolVariable("zipalign", "zipalign")
146
Jiyong Park52818fc2019-03-18 12:01:38 +0900147 pctx.SourcePathVariable("mergenotice", "build/soong/scripts/mergenotice.py")
148
Alex Light0851b882019-02-07 13:20:53 -0800149 android.RegisterModuleType("apex", apexBundleFactory)
150 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900151 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900152
153 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
154 ctx.TopDown("apex_deps", apexDepsMutator)
155 ctx.BottomUp("apex", apexMutator)
156 })
157}
158
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900159// Mark the direct and transitive dependencies of apex bundles so that they
160// can be built for the apex bundles.
161func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800162 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800163 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900164 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900165 depName := mctx.OtherModuleName(child)
166 // If the parent is apexBundle, this child is directly depended.
167 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800168 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800169 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
170 // non-installable apex's cannot be installed and so should not prevent libraries from being
171 // installed to the system.
172 android.UpdateApexDependency(apexBundleName, depName, directDep)
173 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900174
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900175 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900176 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900177 return true
178 } else {
179 return false
180 }
181 })
182 }
183}
184
185// Create apex variations if a module is included in APEX(s).
186func apexMutator(mctx android.BottomUpMutatorContext) {
187 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900188 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900189 } else if _, ok := mctx.Module().(*apexBundle); ok {
190 // apex bundle itself is mutated so that it and its modules have same
191 // apex variant.
192 apexBundleName := mctx.ModuleName()
193 mctx.CreateVariations(apexBundleName)
194 }
195}
196
Alex Light9670d332019-01-29 18:07:33 -0800197type apexNativeDependencies struct {
198 // List of native libraries
199 Native_shared_libs []string
200 // List of native executables
201 Binaries []string
202}
203type apexMultilibProperties struct {
204 // Native dependencies whose compile_multilib is "first"
205 First apexNativeDependencies
206
207 // Native dependencies whose compile_multilib is "both"
208 Both apexNativeDependencies
209
210 // Native dependencies whose compile_multilib is "prefer32"
211 Prefer32 apexNativeDependencies
212
213 // Native dependencies whose compile_multilib is "32"
214 Lib32 apexNativeDependencies
215
216 // Native dependencies whose compile_multilib is "64"
217 Lib64 apexNativeDependencies
218}
219
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900220type apexBundleProperties struct {
221 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000222 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800223 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900224
Jiyong Park40e26a22019-02-08 02:53:06 +0900225 // AndroidManifest.xml file used for the zip container of this APEX bundle.
226 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800227 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900228
Jiyong Park05e70dd2019-03-18 14:26:32 +0900229 // Canonical name of the APEX bundle in the manifest file.
230 // If unspecified, defaults to the value of name
231 Apex_name *string
232
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900233 // Determines the file contexts file for setting security context to each file in this APEX bundle.
234 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
235 // used.
236 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900237 File_contexts *string
238
239 // List of native shared libs that are embedded inside this APEX bundle
240 Native_shared_libs []string
241
242 // List of native executables that are embedded inside this APEX bundle
243 Binaries []string
244
245 // List of java libraries that are embedded inside this APEX bundle
246 Java_libs []string
247
248 // List of prebuilt files that are embedded inside this APEX bundle
249 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900250
251 // Name of the apex_key module that provides the private key to sign APEX
252 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900253
Alex Light5098a612018-11-29 17:12:15 -0800254 // The type of APEX to build. Controls what the APEX payload is. Either
255 // 'image', 'zip' or 'both'. Default: 'image'.
256 Payload_type *string
257
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900258 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
259 // or an android_app_certificate module name in the form ":module".
260 Certificate *string
261
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900262 // Whether this APEX is installable to one of the partitions. Default: true.
263 Installable *bool
264
Jiyong Parkda6eb592018-12-19 17:12:36 +0900265 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
266 // Default is false.
267 Use_vendor *bool
268
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800269 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
270 Ignore_system_library_special_case *bool
271
Alex Light9670d332019-01-29 18:07:33 -0800272 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900273
Jiyong Parkf97782b2019-02-13 20:28:58 +0900274 // List of sanitizer names that this APEX is enabled for
275 SanitizerNames []string `blueprint:"mutated"`
Alex Light9670d332019-01-29 18:07:33 -0800276}
277
278type apexTargetBundleProperties struct {
279 Target struct {
280 // Multilib properties only for android.
281 Android struct {
282 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900283 }
Alex Light9670d332019-01-29 18:07:33 -0800284 // Multilib properties only for host.
285 Host struct {
286 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900287 }
Alex Light9670d332019-01-29 18:07:33 -0800288 // Multilib properties only for host linux_bionic.
289 Linux_bionic struct {
290 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900291 }
Alex Light9670d332019-01-29 18:07:33 -0800292 // Multilib properties only for host linux_glibc.
293 Linux_glibc struct {
294 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900295 }
296 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900297}
298
Jiyong Park8fd61922018-11-08 02:50:25 +0900299type apexFileClass int
300
301const (
302 etc apexFileClass = iota
303 nativeSharedLib
304 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900305 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800306 pyBinary
307 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900308 javaSharedLib
309)
310
Alex Light5098a612018-11-29 17:12:15 -0800311type apexPackaging int
312
313const (
314 imageApex apexPackaging = iota
315 zipApex
316 both
317)
318
319func (a apexPackaging) image() bool {
320 switch a {
321 case imageApex, both:
322 return true
323 }
324 return false
325}
326
327func (a apexPackaging) zip() bool {
328 switch a {
329 case zipApex, both:
330 return true
331 }
332 return false
333}
334
335func (a apexPackaging) suffix() string {
336 switch a {
337 case imageApex:
338 return imageApexSuffix
339 case zipApex:
340 return zipApexSuffix
341 case both:
342 panic(fmt.Errorf("must be either zip or image"))
343 default:
344 panic(fmt.Errorf("unkonwn APEX type %d", a))
345 }
346}
347
348func (a apexPackaging) name() string {
349 switch a {
350 case imageApex:
351 return imageApexType
352 case zipApex:
353 return zipApexType
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
Jiyong Park8fd61922018-11-08 02:50:25 +0900361func (class apexFileClass) NameInMake() string {
362 switch class {
363 case etc:
364 return "ETC"
365 case nativeSharedLib:
366 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800367 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900368 return "EXECUTABLES"
369 case javaSharedLib:
370 return "JAVA_LIBRARIES"
371 default:
372 panic(fmt.Errorf("unkonwn class %d", class))
373 }
374}
375
376type apexFile struct {
377 builtFile android.Path
378 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900379 installDir string
380 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900381 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800382 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900383}
384
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900385type apexBundle struct {
386 android.ModuleBase
387 android.DefaultableModuleBase
388
Alex Light9670d332019-01-29 18:07:33 -0800389 properties apexBundleProperties
390 targetProperties apexTargetBundleProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900391
Alex Light5098a612018-11-29 17:12:15 -0800392 apexTypes apexPackaging
393
Colin Crossa4925902018-11-16 11:36:28 -0800394 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800395 outputFiles map[apexPackaging]android.WritablePath
Colin Crossa4925902018-11-16 11:36:28 -0800396 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900397
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900398 public_key_file android.Path
399 private_key_file android.Path
400 bundle_public_key bool
401
402 container_certificate_file android.Path
403 container_private_key_file android.Path
404
Jiyong Park52818fc2019-03-18 12:01:38 +0900405 mergedNoticeFile android.WritablePath
406
Jiyong Park8fd61922018-11-08 02:50:25 +0900407 // list of files to be included in this apex
408 filesInfo []apexFile
409
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900410 // list of module names that this APEX is depending on
411 externalDeps []string
412
Jiyong Park8fd61922018-11-08 02:50:25 +0900413 flattened bool
Alex Light0851b882019-02-07 13:20:53 -0800414
415 testApex bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900416}
417
Jiyong Park397e55e2018-10-24 21:09:55 +0900418func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900419 native_shared_libs []string, binaries []string, arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900420 // Use *FarVariation* to be able to depend on modules having
421 // conflicting variations with this module. This is required since
422 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
423 // for native shared libs.
424 ctx.AddFarVariationDependencies([]blueprint.Variation{
425 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900426 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900427 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900428 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900429 }, sharedLibTag, native_shared_libs...)
430
431 ctx.AddFarVariationDependencies([]blueprint.Variation{
432 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900433 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900434 }, executableTag, binaries...)
435}
436
Alex Light9670d332019-01-29 18:07:33 -0800437func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
438 if ctx.Os().Class == android.Device {
439 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
440 } else {
441 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
442 if ctx.Os().Bionic() {
443 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
444 } else {
445 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
446 }
447 }
448}
449
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900450func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800451
Jiyong Park397e55e2018-10-24 21:09:55 +0900452 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900453 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800454
455 a.combineProperties(ctx)
456
Jiyong Park397e55e2018-10-24 21:09:55 +0900457 has32BitTarget := false
458 for _, target := range targets {
459 if target.Arch.ArchType.Multilib == "lib32" {
460 has32BitTarget = true
461 }
462 }
463 for i, target := range targets {
464 // When multilib.* is omitted for native_shared_libs, it implies
465 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900466 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900467 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900468 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900469 {Mutator: "link", Variation: "shared"},
470 }, sharedLibTag, a.properties.Native_shared_libs...)
471
Jiyong Park397e55e2018-10-24 21:09:55 +0900472 // Add native modules targetting both ABIs
473 addDependenciesForNativeModules(ctx,
474 a.properties.Multilib.Both.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900475 a.properties.Multilib.Both.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900476 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900477
Alex Light3d673592019-01-18 14:37:31 -0800478 isPrimaryAbi := i == 0
479 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900480 // When multilib.* is omitted for binaries, it implies
481 // multilib.first.
482 ctx.AddFarVariationDependencies([]blueprint.Variation{
483 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900484 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900485 }, executableTag, a.properties.Binaries...)
486
487 // Add native modules targetting the first ABI
488 addDependenciesForNativeModules(ctx,
489 a.properties.Multilib.First.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900490 a.properties.Multilib.First.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900491 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800492
493 // When multilib.* is omitted for prebuilts, it implies multilib.first.
494 ctx.AddFarVariationDependencies([]blueprint.Variation{
495 {Mutator: "arch", Variation: target.String()},
496 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900497 }
498
499 switch target.Arch.ArchType.Multilib {
500 case "lib32":
501 // Add native modules targetting 32-bit ABI
502 addDependenciesForNativeModules(ctx,
503 a.properties.Multilib.Lib32.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900504 a.properties.Multilib.Lib32.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900505 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900506
507 addDependenciesForNativeModules(ctx,
508 a.properties.Multilib.Prefer32.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900509 a.properties.Multilib.Prefer32.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900510 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900511 case "lib64":
512 // Add native modules targetting 64-bit ABI
513 addDependenciesForNativeModules(ctx,
514 a.properties.Multilib.Lib64.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900515 a.properties.Multilib.Lib64.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900516 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900517
518 if !has32BitTarget {
519 addDependenciesForNativeModules(ctx,
520 a.properties.Multilib.Prefer32.Native_shared_libs,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900521 a.properties.Multilib.Prefer32.Binaries, target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900522 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900523 }
524 }
525
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900526 }
527
Jiyong Parkff1458f2018-10-12 21:49:38 +0900528 ctx.AddFarVariationDependencies([]blueprint.Variation{
529 {Mutator: "arch", Variation: "android_common"},
530 }, javaLibTag, a.properties.Java_libs...)
531
Jiyong Park23c52b02019-02-02 13:13:47 +0900532 if String(a.properties.Key) == "" {
533 ctx.ModuleErrorf("key is missing")
534 return
535 }
536 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900537
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900538 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900539 if cert != "" {
540 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900541 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900542}
543
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900544func (a *apexBundle) getCertString(ctx android.BaseContext) string {
545 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
546 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000547 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900548 }
549 return String(a.properties.Certificate)
550}
551
Jiyong Park74e240b2018-11-27 21:27:08 +0900552func (a *apexBundle) Srcs() android.Paths {
Jiyong Park5a832022018-12-20 09:54:35 +0900553 if file, ok := a.outputFiles[imageApex]; ok {
554 return android.Paths{file}
555 } else {
556 return nil
557 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900558}
559
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900560func (a *apexBundle) installable() bool {
561 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
562}
563
Jiyong Park7c1dc612019-01-05 11:15:24 +0900564func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
565 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900566 return "vendor"
567 } else {
568 return "core"
569 }
570}
571
Jiyong Parkf97782b2019-02-13 20:28:58 +0900572func (a *apexBundle) EnableSanitizer(sanitizerName string) {
573 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
574 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
575 }
576}
577
Jiyong Park388ef3f2019-01-28 19:47:32 +0900578func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900579 if android.InList(sanitizerName, a.properties.SanitizerNames) {
580 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900581 }
582
583 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900584 globalSanitizerNames := []string{}
585 if a.Host() {
586 globalSanitizerNames = ctx.Config().SanitizeHost()
587 } else {
588 arches := ctx.Config().SanitizeDeviceArch()
589 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
590 globalSanitizerNames = ctx.Config().SanitizeDevice()
591 }
592 }
593 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900594}
595
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800596func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900597 // Decide the APEX-local directory by the multilib of the library
598 // In the future, we may query this to the module.
599 switch cc.Arch().ArchType.Multilib {
600 case "lib32":
601 dirInApex = "lib"
602 case "lib64":
603 dirInApex = "lib64"
604 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900605 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900606 if !cc.Arch().Native {
607 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
608 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800609 if handleSpecialLibs {
610 switch cc.Name() {
611 case "libc", "libm", "libdl":
612 // Special case for bionic libs. This is to prevent the bionic libs
613 // from being included in the search path /apex/com.android.apex/lib.
614 // This exclusion is required because bionic libs in the runtime APEX
615 // are available via the legacy paths /system/lib/libc.so, etc. By the
616 // init process, the bionic libs in the APEX are bind-mounted to the
617 // legacy paths and thus will be loaded into the default linker namespace.
618 // If the bionic libs are directly in /apex/com.android.apex/lib then
619 // the same libs will be again loaded to the runtime linker namespace,
620 // which will result double loading of bionic libs that isn't supported.
621 dirInApex = filepath.Join(dirInApex, "bionic")
622 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900623 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900624
625 fileToCopy = cc.OutputFile().Path()
626 return
627}
628
629func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900630 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900631 fileToCopy = cc.OutputFile().Path()
632 return
633}
634
Alex Light778127a2019-02-27 14:19:50 -0800635func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
636 dirInApex = "bin"
637 fileToCopy = py.HostToolPath().Path()
638 return
639}
640func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
641 dirInApex = "bin"
642 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
643 if err != nil {
644 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
645 return
646 }
647 fileToCopy = android.PathForOutput(ctx, s)
648 return
649}
650
Jiyong Park04480cf2019-02-06 00:16:29 +0900651func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
652 dirInApex = filepath.Join("bin", sh.SubDir())
653 fileToCopy = sh.OutputFile()
654 return
655}
656
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900657func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
658 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900659 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900660 return
661}
662
663func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
664 dirInApex = filepath.Join("etc", prebuilt.SubDir())
665 fileToCopy = prebuilt.OutputFile()
666 return
667}
668
669func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900670 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900671
Alex Light5098a612018-11-29 17:12:15 -0800672 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
673 a.apexTypes = imageApex
674 } else if *a.properties.Payload_type == "zip" {
675 a.apexTypes = zipApex
676 } else if *a.properties.Payload_type == "both" {
677 a.apexTypes = both
678 } else {
679 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
680 return
681 }
682
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800683 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
684
Alex Light778127a2019-02-27 14:19:50 -0800685 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900686 if _, ok := parent.(*apexBundle); ok {
687 // direct dependencies
688 depTag := ctx.OtherModuleDependencyTag(child)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900689 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900690 switch depTag {
691 case sharedLibTag:
692 if cc, ok := child.(*cc.Module); ok {
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800693 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900694 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900695 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900696 } else {
697 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900698 }
699 case executableTag:
700 if cc, ok := child.(*cc.Module); ok {
Alex Light16df4e82019-01-24 11:37:55 -0800701 if !cc.Arch().Native {
702 // There is only one 'bin' directory so we shouldn't bother copying in
703 // native-bridge'd binaries and only use main ones.
704 return true
705 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900706 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900707 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900708 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900709 } else if sh, ok := child.(*android.ShBinary); ok {
710 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
711 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -0800712 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
713 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
714 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
715 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
716 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
717 // NB: Since go binaries are static we don't need the module for anything here, which is
718 // good since the go tool is a blueprint.Module not an android.Module like we would
719 // normally use.
720 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900721 } else {
Alex Light778127a2019-02-27 14:19:50 -0800722 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 +0900723 }
724 case javaLibTag:
725 if java, ok := child.(*java.Library); ok {
726 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java)
Jiyong Park8fd61922018-11-08 02:50:25 +0900727 if fileToCopy == nil {
728 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
729 } else {
Jiyong Park719b4462019-01-13 00:39:51 +0900730 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900731 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900732 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900733 } else {
734 ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900735 }
736 case prebuiltTag:
737 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
738 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900739 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900740 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900741 } else {
742 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
743 }
744 case keyTag:
745 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900746 a.private_key_file = key.private_key_file
747 a.public_key_file = key.public_key_file
748 // If the key is not installed, bundled it with the APEX.
749 // Note: this bundled key is valid only for non-production builds
750 // (eng/userdebug).
751 a.bundle_public_key = !key.installable() && ctx.Config().Debuggable()
Jiyong Parkff1458f2018-10-12 21:49:38 +0900752 return false
753 } else {
754 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900755 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900756 case certificateTag:
757 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900758 a.container_certificate_file = dep.Certificate.Pem
759 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900760 return false
761 } else {
762 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
763 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900764 }
765 } else {
766 // indirect dependencies
767 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() {
768 if cc, ok := child.(*cc.Module); ok {
Alex Light49ae3d92019-02-21 14:02:46 -0800769 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900770 // If the dependency is a stubs lib, don't include it in this APEX,
771 // but make sure that the lib is installed on the device.
772 // In case no APEX is having the lib, the lib is installed to the system
773 // partition.
Alex Light49ae3d92019-02-21 14:02:46 -0800774 //
775 // Always include if we are a host-apex however since those won't have any
776 // system libraries.
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900777 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
778 a.externalDeps = append(a.externalDeps, cc.Name())
779 }
780 // Don't track further
Jiyong Park25fc6a92018-11-18 18:02:45 +0900781 return false
782 }
Jiyong Park8fd61922018-11-08 02:50:25 +0900783 depName := ctx.OtherModuleName(child)
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800784 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900785 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900786 return true
787 }
788 }
789 }
790 return false
791 })
792
Jiyong Park9335a262018-12-24 11:31:58 +0900793 a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900794 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +0900795 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
796 return
797 }
798
Jiyong Park8fd61922018-11-08 02:50:25 +0900799 // remove duplicates in filesInfo
800 removeDup := func(filesInfo []apexFile) []apexFile {
801 encountered := make(map[android.Path]bool)
802 result := []apexFile{}
803 for _, f := range filesInfo {
804 if !encountered[f.builtFile] {
805 encountered[f.builtFile] = true
806 result = append(result, f)
807 }
808 }
809 return result
810 }
811 filesInfo = removeDup(filesInfo)
812
813 // to have consistent build rules
814 sort.Slice(filesInfo, func(i, j int) bool {
815 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
816 })
817
818 // prepend the name of this APEX to the module names. These names will be the names of
819 // modules that will be defined if the APEX is flattened.
820 for i := range filesInfo {
821 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
822 }
823
Jiyong Park8fd61922018-11-08 02:50:25 +0900824 a.installDir = android.PathForModuleInstall(ctx, "apex")
825 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -0800826
Jiyong Park52818fc2019-03-18 12:01:38 +0900827 a.buildNoticeFile(ctx)
828
Alex Light5098a612018-11-29 17:12:15 -0800829 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900830 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -0800831 }
832 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +0900833 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
834 // is true. This is to support referencing APEX via ":<module_name" syntax
835 // in other modules. It is in AndroidMk where the selection of flattened
836 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900837 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +0900838 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +0900839 }
840}
841
Jiyong Park52818fc2019-03-18 12:01:38 +0900842func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext) {
843 noticeFiles := []android.Path{}
844 noticeFilesString := []string{}
845 for _, f := range a.filesInfo {
846 if f.module != nil {
847 notice := f.module.NoticeFile()
848 if notice.Valid() {
849 noticeFiles = append(noticeFiles, notice.Path())
850 noticeFilesString = append(noticeFilesString, notice.Path().String())
851 }
852 }
853 }
854 // append the notice file specified in the apex module itself
855 if a.NoticeFile().Valid() {
856 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
857 noticeFilesString = append(noticeFilesString, a.NoticeFile().Path().String())
858 }
859
860 if len(noticeFiles) > 0 {
861 a.mergedNoticeFile = android.PathForModuleOut(ctx, "NOTICE")
862 ctx.Build(pctx, android.BuildParams{
863 Rule: apexMergeNoticeRule,
864 Inputs: noticeFiles,
865 Output: a.mergedNoticeFile,
866 Args: map[string]string{
867 "inputs": strings.Join(noticeFilesString, " "),
868 },
869 })
870 }
871}
872
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900873func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900874 cert := String(a.properties.Certificate)
875 if cert != "" && android.SrcIsModule(cert) == "" {
876 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900877 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
878 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900879 } else if cert == "" {
880 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900881 a.container_certificate_file = pem
882 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900883 }
884
Colin Cross8a497952019-03-05 22:25:09 -0800885 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900886
Alex Light5098a612018-11-29 17:12:15 -0800887 var abis []string
888 for _, target := range ctx.MultiTargets() {
889 if len(target.Arch.Abi) > 0 {
890 abis = append(abis, target.Arch.Abi[0])
891 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900892 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900893
Alex Light5098a612018-11-29 17:12:15 -0800894 abis = android.FirstUniqueStrings(abis)
895
896 suffix := apexType.suffix()
897 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900898
Jiyong Parkab3ceb32018-10-10 14:05:29 +0900899 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +0900900 for _, f := range a.filesInfo {
901 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900902 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +0900903
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900904 copyCommands := []string{}
Jiyong Park8fd61922018-11-08 02:50:25 +0900905 for i, src := range filesToCopy {
906 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Alex Light5098a612018-11-29 17:12:15 -0800907 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900908 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
909 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -0800910 for _, sym := range a.filesInfo[i].symlinks {
911 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
912 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
913 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900914 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +0900915 implicitInputs := append(android.Paths(nil), filesToCopy...)
Alex Light5098a612018-11-29 17:12:15 -0800916 implicitInputs = append(implicitInputs, manifest)
917
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900918 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
919 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900920
Alex Light5098a612018-11-29 17:12:15 -0800921 if apexType.image() {
922 // files and dirs that will be created in APEX
923 var readOnlyPaths []string
924 var executablePaths []string // this also includes dirs
925 for _, f := range a.filesInfo {
926 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
927 if f.installDir == "bin" {
928 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -0800929 for _, s := range f.symlinks {
930 executablePaths = append(executablePaths, filepath.Join("bin", s))
931 }
Alex Light5098a612018-11-29 17:12:15 -0800932 } else {
933 readOnlyPaths = append(readOnlyPaths, pathInApex)
934 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900935 dir := f.installDir
936 for !android.InList(dir, executablePaths) && dir != "" {
937 executablePaths = append(executablePaths, dir)
938 dir, _ = filepath.Split(dir) // move up to the parent
939 if len(dir) > 0 {
940 // remove trailing slash
941 dir = dir[:len(dir)-1]
942 }
Alex Light5098a612018-11-29 17:12:15 -0800943 }
944 }
945 sort.Strings(readOnlyPaths)
946 sort.Strings(executablePaths)
947 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
948 ctx.Build(pctx, android.BuildParams{
949 Rule: generateFsConfig,
950 Output: cannedFsConfig,
951 Description: "generate fs config",
952 Args: map[string]string{
953 "ro_paths": strings.Join(readOnlyPaths, " "),
954 "exec_paths": strings.Join(executablePaths, " "),
955 },
956 })
957
958 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
959 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
960 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
961 if !fileContextsOptionalPath.Valid() {
962 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
963 return
964 }
965 fileContexts := fileContextsOptionalPath.Path()
966
Jiyong Park835d82b2018-12-27 16:04:18 +0900967 optFlags := []string{}
968
Alex Light5098a612018-11-29 17:12:15 -0800969 // Additional implicit inputs.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900970 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file)
971 if a.bundle_public_key {
972 implicitInputs = append(implicitInputs, a.public_key_file)
973 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Jiyong Park835d82b2018-12-27 16:04:18 +0900974 }
Alex Light5098a612018-11-29 17:12:15 -0800975
Jiyong Park7f67f482019-01-05 12:57:48 +0900976 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
977 if overridden {
978 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
979 }
980
Jiyong Park40e26a22019-02-08 02:53:06 +0900981 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -0800982 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +0900983 implicitInputs = append(implicitInputs, androidManifestFile)
984 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
985 }
986
Alex Light5098a612018-11-29 17:12:15 -0800987 ctx.Build(pctx, android.BuildParams{
988 Rule: apexRule,
989 Implicits: implicitInputs,
990 Output: unsignedOutputFile,
991 Description: "apex (" + apexType.name() + ")",
992 Args: map[string]string{
993 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
994 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
995 "copy_commands": strings.Join(copyCommands, " && "),
996 "manifest": manifest.String(),
997 "file_contexts": fileContexts.String(),
998 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900999 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001000 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001001 },
1002 })
1003
1004 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1005 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1006 a.bundleModuleFile = bundleModuleFile
1007
1008 ctx.Build(pctx, android.BuildParams{
1009 Rule: apexProtoConvertRule,
1010 Input: unsignedOutputFile,
1011 Output: apexProtoFile,
1012 Description: "apex proto convert",
1013 })
1014
1015 ctx.Build(pctx, android.BuildParams{
1016 Rule: apexBundleRule,
1017 Input: apexProtoFile,
1018 Output: a.bundleModuleFile,
1019 Description: "apex bundle module",
1020 Args: map[string]string{
1021 "abi": strings.Join(abis, "."),
1022 },
1023 })
1024 } else {
1025 ctx.Build(pctx, android.BuildParams{
1026 Rule: zipApexRule,
1027 Implicits: implicitInputs,
1028 Output: unsignedOutputFile,
1029 Description: "apex (" + apexType.name() + ")",
1030 Args: map[string]string{
1031 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1032 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1033 "copy_commands": strings.Join(copyCommands, " && "),
1034 "manifest": manifest.String(),
1035 },
1036 })
Colin Crossa4925902018-11-16 11:36:28 -08001037 }
Colin Crossa4925902018-11-16 11:36:28 -08001038
Alex Light5098a612018-11-29 17:12:15 -08001039 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001040 ctx.Build(pctx, android.BuildParams{
1041 Rule: java.Signapk,
1042 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001043 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001044 Input: unsignedOutputFile,
1045 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001046 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001047 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001048 },
1049 })
Alex Light5098a612018-11-29 17:12:15 -08001050
1051 // Install to $OUT/soong/{target,host}/.../apex
Alex Light2a2561f2019-02-12 16:59:09 -08001052 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001053 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001054 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001055}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001056
Jiyong Park8fd61922018-11-08 02:50:25 +09001057func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001058 if a.installable() {
1059 // For flattened APEX, do nothing but make sure that apex_manifest.json file is also copied along
1060 // with other ordinary files.
Colin Cross8a497952019-03-05 22:25:09 -08001061 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd699cb92019-01-10 00:23:16 +09001062
1063 // rename to apex_manifest.json
1064 copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json")
1065 ctx.Build(pctx, android.BuildParams{
1066 Rule: android.Cp,
1067 Input: manifest,
1068 Output: copiedManifest,
1069 })
Jiyong Park719b4462019-01-13 00:39:51 +09001070 a.filesInfo = append(a.filesInfo, apexFile{copiedManifest, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001071
Jiyong Park23c52b02019-02-02 13:13:47 +09001072 if ctx.Config().FlattenApex() {
1073 for _, fi := range a.filesInfo {
1074 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001075 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1076 for _, sym := range fi.symlinks {
1077 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1078 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001079 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001080 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001081 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001082}
1083
1084func (a *apexBundle) AndroidMk() android.AndroidMkData {
Alex Light5098a612018-11-29 17:12:15 -08001085 writers := []android.AndroidMkData{}
1086 if a.apexTypes.image() {
1087 writers = append(writers, a.androidMkForType(imageApex))
1088 }
1089 if a.apexTypes.zip() {
1090 writers = append(writers, a.androidMkForType(zipApex))
1091 }
1092 return android.AndroidMkData{
1093 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1094 for _, data := range writers {
1095 data.Custom(w, name, prefix, moduleDir, data)
1096 }
1097 }}
1098}
1099
Alex Lightf1801bc2019-02-13 11:10:07 -08001100func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001101 moduleNames := []string{}
1102
1103 for _, fi := range a.filesInfo {
1104 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1105 continue
1106 }
1107 if !android.InList(fi.moduleName, moduleNames) {
1108 moduleNames = append(moduleNames, fi.moduleName)
1109 }
1110 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1111 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1112 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
Jiyong Park05e70dd2019-03-18 14:26:32 +09001113 // /apex/<name>/{lib|framework|...}
1114 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1115 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Alex Lightf1801bc2019-02-13 11:10:07 -08001116 if a.flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001117 // /system/apex/<name>/{lib|framework|...}
1118 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1119 a.installDir.RelPathString(), name, fi.installDir))
Jiyong Park05e70dd2019-03-18 14:26:32 +09001120 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
Alex Lightf4857cf2019-02-22 13:00:04 -08001121 if len(fi.symlinks) > 0 {
1122 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1123 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001124
1125 if fi.module != nil && fi.module.NoticeFile().Valid() {
1126 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1127 }
Jiyong Park94427262019-02-05 23:18:47 +09001128 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001129 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001130 }
1131 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1132 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1133 if fi.module != nil {
1134 archStr := fi.module.Target().Arch.ArchType.String()
1135 host := false
1136 switch fi.module.Target().Os.Class {
1137 case android.Host:
1138 if archStr != "common" {
1139 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1140 }
1141 host = true
1142 case android.HostCross:
1143 if archStr != "common" {
1144 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1145 }
1146 host = true
1147 case android.Device:
1148 if archStr != "common" {
1149 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1150 }
1151 }
1152 if host {
1153 makeOs := fi.module.Target().Os.String()
1154 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1155 makeOs = "linux"
1156 }
1157 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1158 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1159 }
1160 }
1161 if fi.class == javaSharedLib {
1162 javaModule := fi.module.(*java.Library)
1163 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1164 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1165 // we will have foo.jar.jar
1166 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1167 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1168 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1169 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1170 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1171 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
1172 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable {
1173 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1174 if cc, ok := fi.module.(*cc.Module); ok && cc.UnstrippedOutputFile() != nil {
1175 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1176 }
1177 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1178 } else {
1179 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1180 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1181 }
1182 }
1183 return moduleNames
1184}
1185
Alex Light5098a612018-11-29 17:12:15 -08001186func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001187 return android.AndroidMkData{
1188 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1189 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001190 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001191 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001192 }
1193
Jiyong Park719b4462019-01-13 00:39:51 +09001194 if a.flattened && apexType.image() {
1195 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001196 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1197 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1198 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001199 if len(moduleNames) > 0 {
1200 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1201 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001202 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park719b4462019-01-13 00:39:51 +09001203 } else {
Alex Light5098a612018-11-29 17:12:15 -08001204 // zip-apex is the less common type so have the name refer to the image-apex
1205 // only and use {name}.zip if you want the zip-apex
1206 if apexType == zipApex && a.apexTypes == both {
1207 name = name + ".zip"
1208 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001209 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1210 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1211 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1212 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001213 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001214 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001215 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001216 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park8fd61922018-11-08 02:50:25 +09001217 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", String(a.properties.Key))
Jiyong Park52818fc2019-03-18 12:01:38 +09001218 if a.installable() && a.mergedNoticeFile != nil {
1219 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", a.mergedNoticeFile.String())
1220 }
Jiyong Park94427262019-02-05 23:18:47 +09001221 if len(moduleNames) > 0 {
1222 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1223 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001224 if len(a.externalDeps) > 0 {
1225 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1226 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001227 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001228
Alex Light5098a612018-11-29 17:12:15 -08001229 if apexType == imageApex {
1230 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1231 }
Jiyong Park719b4462019-01-13 00:39:51 +09001232 }
1233 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001234}
1235
Alex Light0851b882019-02-07 13:20:53 -08001236func testApexBundleFactory() android.Module {
1237 return ApexBundleFactory( /*testApex*/ true)
1238}
1239
1240func apexBundleFactory() android.Module {
1241 return ApexBundleFactory( /*testApex*/ false)
1242}
1243
1244func ApexBundleFactory(testApex bool) android.Module {
Alex Light5098a612018-11-29 17:12:15 -08001245 module := &apexBundle{
1246 outputFiles: map[apexPackaging]android.WritablePath{},
Alex Light0851b882019-02-07 13:20:53 -08001247 testApex: testApex,
Alex Light5098a612018-11-29 17:12:15 -08001248 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001249 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001250 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001251 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001252 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1253 })
Alex Light5098a612018-11-29 17:12:15 -08001254 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001255 android.InitDefaultableModule(module)
1256 return module
1257}
Jiyong Park30ca9372019-02-07 16:27:23 +09001258
1259//
1260// Defaults
1261//
1262type Defaults struct {
1263 android.ModuleBase
1264 android.DefaultsModuleBase
1265}
1266
1267func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1268}
1269
1270func defaultsFactory() android.Module {
1271 return DefaultsFactory()
1272}
1273
1274func DefaultsFactory(props ...interface{}) android.Module {
1275 module := &Defaults{}
1276
1277 module.AddProperties(props...)
1278 module.AddProperties(
1279 &apexBundleProperties{},
1280 &apexTargetBundleProperties{},
1281 )
1282
1283 android.InitDefaultsModule(module)
1284 return module
1285}