blob: bdac2e3d3c61086d7bfada268ddf542472b87497 [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} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010055 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090056 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090057 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090058 `--file_contexts ${file_contexts} ` +
59 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080060 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090061 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090062 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
63 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000064 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010065 Rspfile: "${out}.copy_commands",
66 RspfileContent: "${copy_commands}",
67 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090068 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080069
Alex Light5098a612018-11-29 17:12:15 -080070 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
71 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010072 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080073 `APEXER_TOOL_PATH=${tool_path} ` +
74 `${apexer} --force --manifest ${manifest} ` +
75 `--payload_type zip ` +
76 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010077 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
78 Rspfile: "${out}.copy_commands",
79 RspfileContent: "${copy_commands}",
80 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080081 }, "tool_path", "image_dir", "copy_commands", "manifest")
82
Colin Crossa4925902018-11-16 11:36:28 -080083 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
84 blueprint.RuleParams{
85 Command: `${aapt2} convert --output-format proto $in -o $out`,
86 CommandDeps: []string{"${aapt2}"},
87 })
88
89 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090090 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000091 `apex_payload.img:apex/${abi}.img ` +
92 `apex_manifest.json:root/apex_manifest.json ` +
Shahar Amitai328b0772018-11-26 14:12:02 +000093 `AndroidManifest.xml:manifest/AndroidManifest.xml`,
Colin Crossa4925902018-11-16 11:36:28 -080094 CommandDeps: []string{"${zip2zip}"},
95 Description: "app bundle",
96 }, "abi")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090097)
98
Alex Light5098a612018-11-29 17:12:15 -080099var imageApexSuffix = ".apex"
100var zipApexSuffix = ".zipapex"
101
102var imageApexType = "image"
103var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900104
105type dependencyTag struct {
106 blueprint.BaseDependencyTag
107 name string
108}
109
110var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900111 sharedLibTag = dependencyTag{name: "sharedLib"}
112 executableTag = dependencyTag{name: "executable"}
113 javaLibTag = dependencyTag{name: "javaLib"}
114 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100115 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900116 keyTag = dependencyTag{name: "key"}
117 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900118 usesTag = dependencyTag{name: "uses"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900119)
120
121func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700122 pctx.Import("android/soong/android")
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
Alex Light0851b882019-02-07 13:20:53 -0800147 android.RegisterModuleType("apex", apexBundleFactory)
148 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900149 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700150 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900151
152 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
153 ctx.TopDown("apex_deps", apexDepsMutator)
Colin Cross643614d2019-06-19 22:51:38 -0700154 ctx.BottomUp("apex", apexMutator).Parallel()
Jooyung Han5c998b92019-06-27 11:30:33 +0900155 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900156 })
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}
Jooyung Han5c998b92019-06-27 11:30:33 +0900196func apexUsesMutator(mctx android.BottomUpMutatorContext) {
197 if ab, ok := mctx.Module().(*apexBundle); ok {
198 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
199 }
200}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900201
Alex Light9670d332019-01-29 18:07:33 -0800202type apexNativeDependencies struct {
203 // List of native libraries
204 Native_shared_libs []string
205 // List of native executables
206 Binaries []string
Roland Levillain630846d2019-06-26 12:48:34 +0100207 // List of native tests
208 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800209}
210type apexMultilibProperties struct {
211 // Native dependencies whose compile_multilib is "first"
212 First apexNativeDependencies
213
214 // Native dependencies whose compile_multilib is "both"
215 Both apexNativeDependencies
216
217 // Native dependencies whose compile_multilib is "prefer32"
218 Prefer32 apexNativeDependencies
219
220 // Native dependencies whose compile_multilib is "32"
221 Lib32 apexNativeDependencies
222
223 // Native dependencies whose compile_multilib is "64"
224 Lib64 apexNativeDependencies
225}
226
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900227type apexBundleProperties struct {
228 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000229 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800230 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900231
Jiyong Park40e26a22019-02-08 02:53:06 +0900232 // AndroidManifest.xml file used for the zip container of this APEX bundle.
233 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800234 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900235
Jiyong Park05e70dd2019-03-18 14:26:32 +0900236 // Canonical name of the APEX bundle in the manifest file.
237 // If unspecified, defaults to the value of name
238 Apex_name *string
239
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900240 // Determines the file contexts file for setting security context to each file in this APEX bundle.
241 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
242 // used.
243 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900244 File_contexts *string
245
246 // List of native shared libs that are embedded inside this APEX bundle
247 Native_shared_libs []string
248
Roland Levillain630846d2019-06-26 12:48:34 +0100249 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900250 Binaries []string
251
252 // List of java libraries that are embedded inside this APEX bundle
253 Java_libs []string
254
255 // List of prebuilt files that are embedded inside this APEX bundle
256 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900257
Roland Levillain630846d2019-06-26 12:48:34 +0100258 // List of tests that are embedded inside this APEX bundle
259 Tests []string
260
Jiyong Parkff1458f2018-10-12 21:49:38 +0900261 // Name of the apex_key module that provides the private key to sign APEX
262 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900263
Alex Light5098a612018-11-29 17:12:15 -0800264 // The type of APEX to build. Controls what the APEX payload is. Either
265 // 'image', 'zip' or 'both'. Default: 'image'.
266 Payload_type *string
267
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900268 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
269 // or an android_app_certificate module name in the form ":module".
270 Certificate *string
271
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900272 // Whether this APEX is installable to one of the partitions. Default: true.
273 Installable *bool
274
Jiyong Parkda6eb592018-12-19 17:12:36 +0900275 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
276 // Default is false.
277 Use_vendor *bool
278
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800279 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
280 Ignore_system_library_special_case *bool
281
Alex Light9670d332019-01-29 18:07:33 -0800282 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900283
Jiyong Parkf97782b2019-02-13 20:28:58 +0900284 // List of sanitizer names that this APEX is enabled for
285 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900286
287 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
288 Provide_cpp_shared_libs *bool
289
290 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
291 Uses []string
Alex Light9670d332019-01-29 18:07:33 -0800292}
293
294type apexTargetBundleProperties struct {
295 Target struct {
296 // Multilib properties only for android.
297 Android struct {
298 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900299 }
Alex Light9670d332019-01-29 18:07:33 -0800300 // Multilib properties only for host.
301 Host struct {
302 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900303 }
Alex Light9670d332019-01-29 18:07:33 -0800304 // Multilib properties only for host linux_bionic.
305 Linux_bionic struct {
306 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900307 }
Alex Light9670d332019-01-29 18:07:33 -0800308 // Multilib properties only for host linux_glibc.
309 Linux_glibc struct {
310 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900311 }
312 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900313}
314
Jiyong Park8fd61922018-11-08 02:50:25 +0900315type apexFileClass int
316
317const (
318 etc apexFileClass = iota
319 nativeSharedLib
320 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900321 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800322 pyBinary
323 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900324 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100325 nativeTest
Jiyong Park8fd61922018-11-08 02:50:25 +0900326)
327
Alex Light5098a612018-11-29 17:12:15 -0800328type apexPackaging int
329
330const (
331 imageApex apexPackaging = iota
332 zipApex
333 both
334)
335
336func (a apexPackaging) image() bool {
337 switch a {
338 case imageApex, both:
339 return true
340 }
341 return false
342}
343
344func (a apexPackaging) zip() bool {
345 switch a {
346 case zipApex, both:
347 return true
348 }
349 return false
350}
351
352func (a apexPackaging) suffix() string {
353 switch a {
354 case imageApex:
355 return imageApexSuffix
356 case zipApex:
357 return zipApexSuffix
358 case both:
359 panic(fmt.Errorf("must be either zip or image"))
360 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100361 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800362 }
363}
364
365func (a apexPackaging) name() string {
366 switch a {
367 case imageApex:
368 return imageApexType
369 case zipApex:
370 return zipApexType
371 case both:
372 panic(fmt.Errorf("must be either zip or image"))
373 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100374 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800375 }
376}
377
Jiyong Park8fd61922018-11-08 02:50:25 +0900378func (class apexFileClass) NameInMake() string {
379 switch class {
380 case etc:
381 return "ETC"
382 case nativeSharedLib:
383 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800384 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900385 return "EXECUTABLES"
386 case javaSharedLib:
387 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100388 case nativeTest:
389 return "NATIVE_TESTS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900390 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100391 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900392 }
393}
394
395type apexFile struct {
396 builtFile android.Path
397 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900398 installDir string
399 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900400 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800401 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900402}
403
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900404type apexBundle struct {
405 android.ModuleBase
406 android.DefaultableModuleBase
407
Alex Light9670d332019-01-29 18:07:33 -0800408 properties apexBundleProperties
409 targetProperties apexTargetBundleProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900410
Alex Light5098a612018-11-29 17:12:15 -0800411 apexTypes apexPackaging
412
Colin Crossa4925902018-11-16 11:36:28 -0800413 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800414 outputFiles map[apexPackaging]android.WritablePath
Colin Crossa4925902018-11-16 11:36:28 -0800415 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900416
Jiyong Park03b68dd2019-07-26 23:20:40 +0900417 prebuiltFileToDelete string
418
Jiyong Park42cca6c2019-04-01 11:15:50 +0900419 public_key_file android.Path
420 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900421
422 container_certificate_file android.Path
423 container_private_key_file android.Path
424
Jiyong Park8fd61922018-11-08 02:50:25 +0900425 // list of files to be included in this apex
426 filesInfo []apexFile
427
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900428 // list of module names that this APEX is depending on
429 externalDeps []string
430
Jiyong Park8fd61922018-11-08 02:50:25 +0900431 flattened bool
Alex Light0851b882019-02-07 13:20:53 -0800432
433 testApex bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900434}
435
Jiyong Park397e55e2018-10-24 21:09:55 +0900436func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100437 native_shared_libs []string, binaries []string, tests []string,
438 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900439 // Use *FarVariation* to be able to depend on modules having
440 // conflicting variations with this module. This is required since
441 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
442 // for native shared libs.
443 ctx.AddFarVariationDependencies([]blueprint.Variation{
444 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900445 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900446 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900447 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900448 }, sharedLibTag, native_shared_libs...)
449
450 ctx.AddFarVariationDependencies([]blueprint.Variation{
451 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900452 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900453 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100454
455 ctx.AddFarVariationDependencies([]blueprint.Variation{
456 {Mutator: "arch", Variation: arch},
457 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100458 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100459 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900460}
461
Alex Light9670d332019-01-29 18:07:33 -0800462func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
463 if ctx.Os().Class == android.Device {
464 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
465 } else {
466 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
467 if ctx.Os().Bionic() {
468 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
469 } else {
470 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
471 }
472 }
473}
474
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900475func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800476
Jiyong Park397e55e2018-10-24 21:09:55 +0900477 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900478 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800479
480 a.combineProperties(ctx)
481
Jiyong Park397e55e2018-10-24 21:09:55 +0900482 has32BitTarget := false
483 for _, target := range targets {
484 if target.Arch.ArchType.Multilib == "lib32" {
485 has32BitTarget = true
486 }
487 }
488 for i, target := range targets {
489 // When multilib.* is omitted for native_shared_libs, it implies
490 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900491 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900492 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900493 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900494 {Mutator: "link", Variation: "shared"},
495 }, sharedLibTag, a.properties.Native_shared_libs...)
496
Roland Levillain630846d2019-06-26 12:48:34 +0100497 // When multilib.* is omitted for tests, it implies
498 // multilib.both.
499 ctx.AddFarVariationDependencies([]blueprint.Variation{
500 {Mutator: "arch", Variation: target.String()},
501 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100502 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100503 }, testTag, a.properties.Tests...)
504
Jiyong Park397e55e2018-10-24 21:09:55 +0900505 // Add native modules targetting both ABIs
506 addDependenciesForNativeModules(ctx,
507 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100508 a.properties.Multilib.Both.Binaries,
509 a.properties.Multilib.Both.Tests,
510 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900511 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900512
Alex Light3d673592019-01-18 14:37:31 -0800513 isPrimaryAbi := i == 0
514 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900515 // When multilib.* is omitted for binaries, it implies
516 // multilib.first.
517 ctx.AddFarVariationDependencies([]blueprint.Variation{
518 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900519 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900520 }, executableTag, a.properties.Binaries...)
521
522 // Add native modules targetting the first ABI
523 addDependenciesForNativeModules(ctx,
524 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100525 a.properties.Multilib.First.Binaries,
526 a.properties.Multilib.First.Tests,
527 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900528 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800529
530 // When multilib.* is omitted for prebuilts, it implies multilib.first.
531 ctx.AddFarVariationDependencies([]blueprint.Variation{
532 {Mutator: "arch", Variation: target.String()},
533 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900534 }
535
536 switch target.Arch.ArchType.Multilib {
537 case "lib32":
538 // Add native modules targetting 32-bit ABI
539 addDependenciesForNativeModules(ctx,
540 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100541 a.properties.Multilib.Lib32.Binaries,
542 a.properties.Multilib.Lib32.Tests,
543 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900544 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900545
546 addDependenciesForNativeModules(ctx,
547 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100548 a.properties.Multilib.Prefer32.Binaries,
549 a.properties.Multilib.Prefer32.Tests,
550 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900551 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900552 case "lib64":
553 // Add native modules targetting 64-bit ABI
554 addDependenciesForNativeModules(ctx,
555 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100556 a.properties.Multilib.Lib64.Binaries,
557 a.properties.Multilib.Lib64.Tests,
558 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900559 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900560
561 if !has32BitTarget {
562 addDependenciesForNativeModules(ctx,
563 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100564 a.properties.Multilib.Prefer32.Binaries,
565 a.properties.Multilib.Prefer32.Tests,
566 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900567 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900568 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700569
570 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
571 for _, sanitizer := range ctx.Config().SanitizeDevice() {
572 if sanitizer == "hwaddress" {
573 addDependenciesForNativeModules(ctx,
574 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100575 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700576 break
577 }
578 }
579 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900580 }
581
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900582 }
583
Jiyong Parkff1458f2018-10-12 21:49:38 +0900584 ctx.AddFarVariationDependencies([]blueprint.Variation{
585 {Mutator: "arch", Variation: "android_common"},
586 }, javaLibTag, a.properties.Java_libs...)
587
Jiyong Park23c52b02019-02-02 13:13:47 +0900588 if String(a.properties.Key) == "" {
589 ctx.ModuleErrorf("key is missing")
590 return
591 }
592 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900593
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900594 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900595 if cert != "" {
596 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900597 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900598}
599
Colin Cross0ea8ba82019-06-06 14:33:29 -0700600func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900601 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
602 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000603 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900604 }
605 return String(a.properties.Certificate)
606}
607
Colin Cross41955e82019-05-29 14:40:35 -0700608func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
609 switch tag {
610 case "":
611 if file, ok := a.outputFiles[imageApex]; ok {
612 return android.Paths{file}, nil
613 } else {
614 return nil, nil
615 }
616 default:
617 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900618 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900619}
620
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900621func (a *apexBundle) installable() bool {
622 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
623}
624
Jiyong Park7c1dc612019-01-05 11:15:24 +0900625func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
626 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900627 return "vendor"
628 } else {
629 return "core"
630 }
631}
632
Jiyong Parkf97782b2019-02-13 20:28:58 +0900633func (a *apexBundle) EnableSanitizer(sanitizerName string) {
634 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
635 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
636 }
637}
638
Jiyong Park388ef3f2019-01-28 19:47:32 +0900639func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900640 if android.InList(sanitizerName, a.properties.SanitizerNames) {
641 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900642 }
643
644 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900645 globalSanitizerNames := []string{}
646 if a.Host() {
647 globalSanitizerNames = ctx.Config().SanitizeHost()
648 } else {
649 arches := ctx.Config().SanitizeDeviceArch()
650 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
651 globalSanitizerNames = ctx.Config().SanitizeDevice()
652 }
653 }
654 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900655}
656
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800657func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900658 // Decide the APEX-local directory by the multilib of the library
659 // In the future, we may query this to the module.
660 switch cc.Arch().ArchType.Multilib {
661 case "lib32":
662 dirInApex = "lib"
663 case "lib64":
664 dirInApex = "lib64"
665 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900666 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200667 if !cc.Arch().Native {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900668 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200669 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
670 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900671 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800672 if handleSpecialLibs {
673 switch cc.Name() {
674 case "libc", "libm", "libdl":
675 // Special case for bionic libs. This is to prevent the bionic libs
676 // from being included in the search path /apex/com.android.apex/lib.
677 // This exclusion is required because bionic libs in the runtime APEX
678 // are available via the legacy paths /system/lib/libc.so, etc. By the
679 // init process, the bionic libs in the APEX are bind-mounted to the
680 // legacy paths and thus will be loaded into the default linker namespace.
681 // If the bionic libs are directly in /apex/com.android.apex/lib then
682 // the same libs will be again loaded to the runtime linker namespace,
683 // which will result double loading of bionic libs that isn't supported.
684 dirInApex = filepath.Join(dirInApex, "bionic")
685 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900686 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900687
688 fileToCopy = cc.OutputFile().Path()
689 return
690}
691
692func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900693 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200694 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900695 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200696 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
697 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900698 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900699 fileToCopy = cc.OutputFile().Path()
700 return
701}
702
Alex Light778127a2019-02-27 14:19:50 -0800703func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
704 dirInApex = "bin"
705 fileToCopy = py.HostToolPath().Path()
706 return
707}
708func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
709 dirInApex = "bin"
710 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
711 if err != nil {
712 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
713 return
714 }
715 fileToCopy = android.PathForOutput(ctx, s)
716 return
717}
718
Jiyong Park04480cf2019-02-06 00:16:29 +0900719func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
720 dirInApex = filepath.Join("bin", sh.SubDir())
721 fileToCopy = sh.OutputFile()
722 return
723}
724
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900725func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
726 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900727 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900728 return
729}
730
731func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
732 dirInApex = filepath.Join("etc", prebuilt.SubDir())
733 fileToCopy = prebuilt.OutputFile()
734 return
735}
736
737func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900738 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900739
Alex Light5098a612018-11-29 17:12:15 -0800740 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
741 a.apexTypes = imageApex
742 } else if *a.properties.Payload_type == "zip" {
743 a.apexTypes = zipApex
744 } else if *a.properties.Payload_type == "both" {
745 a.apexTypes = both
746 } else {
747 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
748 return
749 }
750
Roland Levillain630846d2019-06-26 12:48:34 +0100751 if len(a.properties.Tests) > 0 && !a.testApex {
752 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
753 return
754 }
755
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800756 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
757
Jooyung Han5c998b92019-06-27 11:30:33 +0900758 // Check if "uses" requirements are met with dependent apexBundles
759 var providedNativeSharedLibs []string
760 useVendor := proptools.Bool(a.properties.Use_vendor)
761 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
762 if ctx.OtherModuleDependencyTag(m) != usesTag {
763 return
764 }
765 otherName := ctx.OtherModuleName(m)
766 other, ok := m.(*apexBundle)
767 if !ok {
768 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
769 return
770 }
771 if proptools.Bool(other.properties.Use_vendor) != useVendor {
772 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
773 return
774 }
775 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
776 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
777 return
778 }
779 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
780 })
781
Alex Light778127a2019-02-27 14:19:50 -0800782 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +0100783 depTag := ctx.OtherModuleDependencyTag(child)
784 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900785 if _, ok := parent.(*apexBundle); ok {
786 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900787 switch depTag {
788 case sharedLibTag:
789 if cc, ok := child.(*cc.Module); ok {
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800790 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900791 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900792 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900793 } else {
794 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900795 }
796 case executableTag:
797 if cc, ok := child.(*cc.Module); ok {
798 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900799 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900800 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900801 } else if sh, ok := child.(*android.ShBinary); ok {
802 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
803 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -0800804 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
805 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
806 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
807 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
808 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
809 // NB: Since go binaries are static we don't need the module for anything here, which is
810 // good since the go tool is a blueprint.Module not an android.Module like we would
811 // normally use.
812 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900813 } else {
Alex Light778127a2019-02-27 14:19:50 -0800814 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 +0900815 }
816 case javaLibTag:
817 if java, ok := child.(*java.Library); ok {
818 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java)
Jiyong Park8fd61922018-11-08 02:50:25 +0900819 if fileToCopy == nil {
820 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
821 } else {
Jiyong Park719b4462019-01-13 00:39:51 +0900822 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900823 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900824 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900825 } else {
826 ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900827 }
828 case prebuiltTag:
829 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
830 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900831 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900832 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900833 } else {
834 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
835 }
Roland Levillain630846d2019-06-26 12:48:34 +0100836 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +0100837 if ccTest, ok := child.(*cc.Module); ok {
838 if ccTest.IsTestPerSrcAllTestsVariation() {
839 // Multiple-output test module (where `test_per_src: true`).
840 //
841 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
842 // We do not add this variation to `filesInfo`, as it has no output;
843 // however, we do add the other variations of this module as indirect
844 // dependencies (see below).
845 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +0100846 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +0100847 // Single-output test module (where `test_per_src: false`).
848 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
849 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +0100850 }
Roland Levillain630846d2019-06-26 12:48:34 +0100851 return true
852 } else {
853 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
854 }
Jiyong Parkff1458f2018-10-12 21:49:38 +0900855 case keyTag:
856 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900857 a.private_key_file = key.private_key_file
858 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +0900859 return false
860 } else {
861 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900863 case certificateTag:
864 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900865 a.container_certificate_file = dep.Certificate.Pem
866 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900867 return false
868 } else {
869 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
870 }
Jiyong Park03b68dd2019-07-26 23:20:40 +0900871 case android.PrebuiltDepTag:
872 // If the prebuilt is force disabled, remember to delete the prebuilt file
873 // that might have been installed in the previous builds
874 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
875 a.prebuiltFileToDelete = prebuilt.InstallFilename()
876 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877 }
878 } else {
879 // indirect dependencies
880 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +0100881 // We cannot use a switch statement on `depTag` here as the checked
882 // tags used below are private (e.g. `cc.sharedDepTag`).
883 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
884 if cc, ok := child.(*cc.Module); ok {
885 if android.InList(cc.Name(), providedNativeSharedLibs) {
886 // If we're using a shared library which is provided from other APEX,
887 // don't include it in this APEX
888 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900889 }
Roland Levillainf89cd092019-07-29 16:22:59 +0100890 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
891 // If the dependency is a stubs lib, don't include it in this APEX,
892 // but make sure that the lib is installed on the device.
893 // In case no APEX is having the lib, the lib is installed to the system
894 // partition.
895 //
896 // Always include if we are a host-apex however since those won't have any
897 // system libraries.
898 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
899 a.externalDeps = append(a.externalDeps, cc.Name())
900 }
901 // Don't track further
902 return false
903 }
904 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
905 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
906 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900907 }
Roland Levillainf89cd092019-07-29 16:22:59 +0100908 } else if cc.IsTestPerSrcDepTag(depTag) {
909 if cc, ok := child.(*cc.Module); ok {
910 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
911 // Handle modules created as `test_per_src` variations of a single test module:
912 // use the name of the generated test binary (`fileToCopy`) instead of the name
913 // of the original test module (`depName`, shared by all `test_per_src`
914 // variations of that module).
915 moduleName := filepath.Base(fileToCopy.String())
916 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
917 return true
918 }
919 } else {
920 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900921 }
922 }
923 }
924 return false
925 })
926
Jiyong Park9335a262018-12-24 11:31:58 +0900927 a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900928 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +0900929 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
930 return
931 }
932
Jiyong Park8fd61922018-11-08 02:50:25 +0900933 // remove duplicates in filesInfo
934 removeDup := func(filesInfo []apexFile) []apexFile {
935 encountered := make(map[android.Path]bool)
936 result := []apexFile{}
937 for _, f := range filesInfo {
938 if !encountered[f.builtFile] {
939 encountered[f.builtFile] = true
940 result = append(result, f)
941 }
942 }
943 return result
944 }
945 filesInfo = removeDup(filesInfo)
946
947 // to have consistent build rules
948 sort.Slice(filesInfo, func(i, j int) bool {
949 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
950 })
951
952 // prepend the name of this APEX to the module names. These names will be the names of
953 // modules that will be defined if the APEX is flattened.
954 for i := range filesInfo {
955 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
956 }
957
Jiyong Park8fd61922018-11-08 02:50:25 +0900958 a.installDir = android.PathForModuleInstall(ctx, "apex")
959 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -0800960
961 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900962 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -0800963 }
964 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +0900965 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +0100966 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +0900967 // in other modules. It is in AndroidMk where the selection of flattened
968 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900969 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +0900970 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +0900971 }
972}
973
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700974func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +0900975 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +0900976 for _, f := range a.filesInfo {
977 if f.module != nil {
978 notice := f.module.NoticeFile()
979 if notice.Valid() {
980 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +0900981 }
982 }
983 }
984 // append the notice file specified in the apex module itself
985 if a.NoticeFile().Valid() {
986 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +0900987 }
988
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700989 if len(noticeFiles) == 0 {
990 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +0900991 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700992
Jaewoong Jung98772792019-07-01 17:15:13 -0700993 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +0900994}
995
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900996func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900997 cert := String(a.properties.Certificate)
998 if cert != "" && android.SrcIsModule(cert) == "" {
999 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001000 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1001 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001002 } else if cert == "" {
1003 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001004 a.container_certificate_file = pem
1005 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001006 }
1007
Colin Cross8a497952019-03-05 22:25:09 -08001008 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001009
Alex Light5098a612018-11-29 17:12:15 -08001010 var abis []string
1011 for _, target := range ctx.MultiTargets() {
1012 if len(target.Arch.Abi) > 0 {
1013 abis = append(abis, target.Arch.Abi[0])
1014 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001015 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016
Alex Light5098a612018-11-29 17:12:15 -08001017 abis = android.FirstUniqueStrings(abis)
1018
1019 suffix := apexType.suffix()
1020 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001021
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001022 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001023 for _, f := range a.filesInfo {
1024 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001025 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001026
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001027 copyCommands := []string{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001028 for i, src := range filesToCopy {
1029 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Alex Light5098a612018-11-29 17:12:15 -08001030 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1032 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001033 for _, sym := range a.filesInfo[i].symlinks {
1034 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1035 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1036 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001037 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001038 implicitInputs := append(android.Paths(nil), filesToCopy...)
Alex Light5098a612018-11-29 17:12:15 -08001039 implicitInputs = append(implicitInputs, manifest)
1040
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001041 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1042 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001043
Alex Light5098a612018-11-29 17:12:15 -08001044 if apexType.image() {
1045 // files and dirs that will be created in APEX
1046 var readOnlyPaths []string
1047 var executablePaths []string // this also includes dirs
1048 for _, f := range a.filesInfo {
1049 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001050 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001051 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001052 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001053 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001054 }
Alex Light5098a612018-11-29 17:12:15 -08001055 } else {
1056 readOnlyPaths = append(readOnlyPaths, pathInApex)
1057 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001058 dir := f.installDir
1059 for !android.InList(dir, executablePaths) && dir != "" {
1060 executablePaths = append(executablePaths, dir)
1061 dir, _ = filepath.Split(dir) // move up to the parent
1062 if len(dir) > 0 {
1063 // remove trailing slash
1064 dir = dir[:len(dir)-1]
1065 }
Alex Light5098a612018-11-29 17:12:15 -08001066 }
1067 }
1068 sort.Strings(readOnlyPaths)
1069 sort.Strings(executablePaths)
1070 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1071 ctx.Build(pctx, android.BuildParams{
1072 Rule: generateFsConfig,
1073 Output: cannedFsConfig,
1074 Description: "generate fs config",
1075 Args: map[string]string{
1076 "ro_paths": strings.Join(readOnlyPaths, " "),
1077 "exec_paths": strings.Join(executablePaths, " "),
1078 },
1079 })
1080
1081 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1082 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1083 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1084 if !fileContextsOptionalPath.Valid() {
1085 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1086 return
1087 }
1088 fileContexts := fileContextsOptionalPath.Path()
1089
Jiyong Park835d82b2018-12-27 16:04:18 +09001090 optFlags := []string{}
1091
Alex Light5098a612018-11-29 17:12:15 -08001092 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001093 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1094 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001095
Jiyong Park7f67f482019-01-05 12:57:48 +09001096 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1097 if overridden {
1098 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1099 }
1100
Jiyong Park40e26a22019-02-08 02:53:06 +09001101 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001102 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001103 implicitInputs = append(implicitInputs, androidManifestFile)
1104 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1105 }
1106
Jiyong Park71b519d2019-04-18 17:25:49 +09001107 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1108 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1109 ctx.Config().UnbundledBuild() &&
1110 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1111 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1112 apiFingerprint := java.ApiFingerprintPath(ctx)
1113 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1114 implicitInputs = append(implicitInputs, apiFingerprint)
1115 }
1116 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1117
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001118 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1119 if noticeFile.Valid() {
1120 // If there's a NOTICE file, embed it as an asset file in the APEX.
1121 implicitInputs = append(implicitInputs, noticeFile.Path())
1122 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1123 }
1124
Alex Light5098a612018-11-29 17:12:15 -08001125 ctx.Build(pctx, android.BuildParams{
1126 Rule: apexRule,
1127 Implicits: implicitInputs,
1128 Output: unsignedOutputFile,
1129 Description: "apex (" + apexType.name() + ")",
1130 Args: map[string]string{
1131 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1132 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1133 "copy_commands": strings.Join(copyCommands, " && "),
1134 "manifest": manifest.String(),
1135 "file_contexts": fileContexts.String(),
1136 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001137 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001138 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001139 },
1140 })
1141
1142 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1143 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1144 a.bundleModuleFile = bundleModuleFile
1145
1146 ctx.Build(pctx, android.BuildParams{
1147 Rule: apexProtoConvertRule,
1148 Input: unsignedOutputFile,
1149 Output: apexProtoFile,
1150 Description: "apex proto convert",
1151 })
1152
1153 ctx.Build(pctx, android.BuildParams{
1154 Rule: apexBundleRule,
1155 Input: apexProtoFile,
1156 Output: a.bundleModuleFile,
1157 Description: "apex bundle module",
1158 Args: map[string]string{
1159 "abi": strings.Join(abis, "."),
1160 },
1161 })
1162 } else {
1163 ctx.Build(pctx, android.BuildParams{
1164 Rule: zipApexRule,
1165 Implicits: implicitInputs,
1166 Output: unsignedOutputFile,
1167 Description: "apex (" + apexType.name() + ")",
1168 Args: map[string]string{
1169 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1170 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1171 "copy_commands": strings.Join(copyCommands, " && "),
1172 "manifest": manifest.String(),
1173 },
1174 })
Colin Crossa4925902018-11-16 11:36:28 -08001175 }
Colin Crossa4925902018-11-16 11:36:28 -08001176
Alex Light5098a612018-11-29 17:12:15 -08001177 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001178 ctx.Build(pctx, android.BuildParams{
1179 Rule: java.Signapk,
1180 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001181 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001182 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001183 Implicits: []android.Path{
1184 a.container_certificate_file,
1185 a.container_private_key_file,
1186 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001187 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001188 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001189 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001190 },
1191 })
Alex Light5098a612018-11-29 17:12:15 -08001192
1193 // Install to $OUT/soong/{target,host}/.../apex
Alex Light2a2561f2019-02-12 16:59:09 -08001194 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001195 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001196 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001197}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001198
Jiyong Park8fd61922018-11-08 02:50:25 +09001199func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001200 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001201 // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001202 // with other ordinary files.
Colin Cross8a497952019-03-05 22:25:09 -08001203 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd699cb92019-01-10 00:23:16 +09001204
1205 // rename to apex_manifest.json
1206 copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json")
1207 ctx.Build(pctx, android.BuildParams{
1208 Rule: android.Cp,
1209 Input: manifest,
1210 Output: copiedManifest,
1211 })
Jiyong Park719b4462019-01-13 00:39:51 +09001212 a.filesInfo = append(a.filesInfo, apexFile{copiedManifest, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001213
Jiyong Park42cca6c2019-04-01 11:15:50 +09001214 // rename to apex_pubkey
1215 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1216 ctx.Build(pctx, android.BuildParams{
1217 Rule: android.Cp,
1218 Input: a.public_key_file,
1219 Output: copiedPubkey,
1220 })
1221 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1222
Jiyong Park23c52b02019-02-02 13:13:47 +09001223 if ctx.Config().FlattenApex() {
1224 for _, fi := range a.filesInfo {
1225 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001226 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1227 for _, sym := range fi.symlinks {
1228 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1229 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001230 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001231 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001232 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001233}
1234
1235func (a *apexBundle) AndroidMk() android.AndroidMkData {
Alex Light5098a612018-11-29 17:12:15 -08001236 writers := []android.AndroidMkData{}
1237 if a.apexTypes.image() {
1238 writers = append(writers, a.androidMkForType(imageApex))
1239 }
1240 if a.apexTypes.zip() {
1241 writers = append(writers, a.androidMkForType(zipApex))
1242 }
1243 return android.AndroidMkData{
1244 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1245 for _, data := range writers {
1246 data.Custom(w, name, prefix, moduleDir, data)
1247 }
1248 }}
1249}
1250
Alex Lightf1801bc2019-02-13 11:10:07 -08001251func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001252 moduleNames := []string{}
1253
1254 for _, fi := range a.filesInfo {
1255 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1256 continue
1257 }
1258 if !android.InList(fi.moduleName, moduleNames) {
1259 moduleNames = append(moduleNames, fi.moduleName)
1260 }
1261 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1262 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1263 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
Jiyong Park05e70dd2019-03-18 14:26:32 +09001264 // /apex/<name>/{lib|framework|...}
1265 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1266 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Alex Lightf1801bc2019-02-13 11:10:07 -08001267 if a.flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001268 // /system/apex/<name>/{lib|framework|...}
1269 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1270 a.installDir.RelPathString(), name, fi.installDir))
Jiyong Park05e70dd2019-03-18 14:26:32 +09001271 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
Alex Lightf4857cf2019-02-22 13:00:04 -08001272 if len(fi.symlinks) > 0 {
1273 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1274 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001275
1276 if fi.module != nil && fi.module.NoticeFile().Valid() {
1277 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1278 }
Jiyong Park94427262019-02-05 23:18:47 +09001279 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001280 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001281 }
1282 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1283 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1284 if fi.module != nil {
1285 archStr := fi.module.Target().Arch.ArchType.String()
1286 host := false
1287 switch fi.module.Target().Os.Class {
1288 case android.Host:
1289 if archStr != "common" {
1290 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1291 }
1292 host = true
1293 case android.HostCross:
1294 if archStr != "common" {
1295 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1296 }
1297 host = true
1298 case android.Device:
1299 if archStr != "common" {
1300 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1301 }
1302 }
1303 if host {
1304 makeOs := fi.module.Target().Os.String()
1305 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1306 makeOs = "linux"
1307 }
1308 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1309 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1310 }
1311 }
1312 if fi.class == javaSharedLib {
1313 javaModule := fi.module.(*java.Library)
1314 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1315 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1316 // we will have foo.jar.jar
1317 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1318 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1319 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1320 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1321 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1322 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
1323 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable {
1324 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001325 if cc, ok := fi.module.(*cc.Module); ok {
1326 if cc.UnstrippedOutputFile() != nil {
1327 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1328 }
1329 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Park94427262019-02-05 23:18:47 +09001330 }
1331 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1332 } else {
1333 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1334 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1335 }
1336 }
1337 return moduleNames
1338}
1339
Alex Light5098a612018-11-29 17:12:15 -08001340func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001341 return android.AndroidMkData{
1342 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1343 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001344 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001345 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001346 }
1347
Jiyong Park719b4462019-01-13 00:39:51 +09001348 if a.flattened && apexType.image() {
1349 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001350 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1351 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1352 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001353 if len(moduleNames) > 0 {
1354 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1355 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001356 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park719b4462019-01-13 00:39:51 +09001357 } else {
Alex Light5098a612018-11-29 17:12:15 -08001358 // zip-apex is the less common type so have the name refer to the image-apex
1359 // only and use {name}.zip if you want the zip-apex
1360 if apexType == zipApex && a.apexTypes == both {
1361 name = name + ".zip"
1362 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001363 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1364 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1365 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1366 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001367 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001368 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001369 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001370 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001371 if len(moduleNames) > 0 {
1372 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1373 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001374 if len(a.externalDeps) > 0 {
1375 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1376 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001377 if a.prebuiltFileToDelete != "" {
1378 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1379 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1380 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001381 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001382
Alex Light5098a612018-11-29 17:12:15 -08001383 if apexType == imageApex {
1384 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1385 }
Jiyong Park719b4462019-01-13 00:39:51 +09001386 }
1387 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001388}
1389
Alex Light0851b882019-02-07 13:20:53 -08001390func testApexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001391 return ApexBundleFactory(true /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001392}
1393
1394func apexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001395 return ApexBundleFactory(false /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001396}
1397
1398func ApexBundleFactory(testApex bool) android.Module {
Alex Light5098a612018-11-29 17:12:15 -08001399 module := &apexBundle{
1400 outputFiles: map[apexPackaging]android.WritablePath{},
Alex Light0851b882019-02-07 13:20:53 -08001401 testApex: testApex,
Alex Light5098a612018-11-29 17:12:15 -08001402 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001403 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001404 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001405 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001406 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1407 })
Alex Light5098a612018-11-29 17:12:15 -08001408 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001409 android.InitDefaultableModule(module)
1410 return module
1411}
Jiyong Park30ca9372019-02-07 16:27:23 +09001412
1413//
1414// Defaults
1415//
1416type Defaults struct {
1417 android.ModuleBase
1418 android.DefaultsModuleBase
1419}
1420
Jiyong Park30ca9372019-02-07 16:27:23 +09001421func defaultsFactory() android.Module {
1422 return DefaultsFactory()
1423}
1424
1425func DefaultsFactory(props ...interface{}) android.Module {
1426 module := &Defaults{}
1427
1428 module.AddProperties(props...)
1429 module.AddProperties(
1430 &apexBundleProperties{},
1431 &apexTargetBundleProperties{},
1432 )
1433
1434 android.InitDefaultsModule(module)
1435 return module
1436}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001437
1438//
1439// Prebuilt APEX
1440//
1441type Prebuilt struct {
1442 android.ModuleBase
1443 prebuilt android.Prebuilt
1444
1445 properties PrebuiltProperties
1446
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001447 inputApex android.Path
1448 installDir android.OutputPath
1449 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001450 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001451}
1452
1453type PrebuiltProperties struct {
1454 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001455 Source string `blueprint:"mutated"`
1456 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001457
1458 Src *string
1459 Arch struct {
1460 Arm struct {
1461 Src *string
1462 }
1463 Arm64 struct {
1464 Src *string
1465 }
1466 X86 struct {
1467 Src *string
1468 }
1469 X86_64 struct {
1470 Src *string
1471 }
1472 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001473
1474 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001475 // Optional name for the installed apex. If unspecified, name of the
1476 // module is used as the file name
1477 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001478
1479 // Names of modules to be overridden. Listed modules can only be other binaries
1480 // (in Make or Soong).
1481 // This does not completely prevent installation of the overridden binaries, but if both
1482 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1483 // from PRODUCT_PACKAGES.
1484 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001485}
1486
1487func (p *Prebuilt) installable() bool {
1488 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001489}
1490
1491func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001492 // If the device is configured to use flattened APEX, force disable the prebuilt because
1493 // the prebuilt is a non-flattened one.
1494 forceDisable := ctx.Config().FlattenApex()
1495
1496 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1497 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001498 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001499
1500 // b/137216042 don't use prebuilts when address sanitizer is on
1501 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1502 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1503
1504 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001505 p.properties.ForceDisable = true
1506 return
1507 }
1508
Jiyong Parkc95714e2019-03-29 14:23:10 +09001509 // This is called before prebuilt_select and prebuilt_postdeps mutators
1510 // The mutators requires that src to be set correctly for each arch so that
1511 // arch variants are disabled when src is not provided for the arch.
1512 if len(ctx.MultiTargets()) != 1 {
1513 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1514 return
1515 }
1516 var src string
1517 switch ctx.MultiTargets()[0].Arch.ArchType {
1518 case android.Arm:
1519 src = String(p.properties.Arch.Arm.Src)
1520 case android.Arm64:
1521 src = String(p.properties.Arch.Arm64.Src)
1522 case android.X86:
1523 src = String(p.properties.Arch.X86.Src)
1524 case android.X86_64:
1525 src = String(p.properties.Arch.X86_64.Src)
1526 default:
1527 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1528 return
1529 }
1530 if src == "" {
1531 src = String(p.properties.Src)
1532 }
1533 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001534}
1535
Jiyong Park03b68dd2019-07-26 23:20:40 +09001536func (p *Prebuilt) isForceDisabled() bool {
1537 return p.properties.ForceDisable
1538}
1539
Colin Cross41955e82019-05-29 14:40:35 -07001540func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1541 switch tag {
1542 case "":
1543 return android.Paths{p.outputApex}, nil
1544 default:
1545 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1546 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001547}
1548
Jiyong Park4d277042019-04-23 18:00:10 +09001549func (p *Prebuilt) InstallFilename() string {
1550 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1551}
1552
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001553func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001554 if p.properties.ForceDisable {
1555 return
1556 }
1557
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001558 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001559 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001560 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001561 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001562 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1563 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1564 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001565 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1566 ctx.Build(pctx, android.BuildParams{
1567 Rule: android.Cp,
1568 Input: p.inputApex,
1569 Output: p.outputApex,
1570 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001571 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001572 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001573 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001574}
1575
1576func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1577 return &p.prebuilt
1578}
1579
1580func (p *Prebuilt) Name() string {
1581 return p.prebuilt.Name(p.ModuleBase.Name())
1582}
1583
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001584func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1585 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001586 Class: "ETC",
1587 OutputFile: android.OptionalPathForPath(p.inputApex),
1588 Include: "$(BUILD_PREBUILT)",
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001589 AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
1590 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1591 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1592 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1593 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001594 },
1595 }
1596}
1597
1598// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1599func PrebuiltFactory() android.Module {
1600 module := &Prebuilt{}
1601 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001602 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001603 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001604 return module
1605}