blob: 441911b3aa7da118bacc736f0e1b2700fe32c875 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
19 "io"
20 "path/filepath"
21 "runtime"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
24
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
35var (
36 pctx = android.NewPackageContext("android/apex")
37
38 // Create a canned fs config file where all files and directories are
39 // by default set to (uid/gid/mode) = (1000/1000/0644)
40 // TODO(b/113082813) make this configurable using config.fs syntax
41 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000042 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000043 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090044 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090045 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090047 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090048
49 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
50 // against the binary policy using sefcontext_compiler -p <policy>.
51
52 // TODO(b/114327326): automate the generation of file_contexts
53 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
54 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
55 `(${copy_commands}) && ` +
56 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090057 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090058 `--file_contexts ${file_contexts} ` +
59 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080060 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090061 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090062 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
63 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000064 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Jiyong Park48ca7dc2018-10-10 14:01:00 +090065 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090066 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080067
Alex Light5098a612018-11-29 17:12:15 -080068 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
69 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
70 `(${copy_commands}) && ` +
71 `APEXER_TOOL_PATH=${tool_path} ` +
72 `${apexer} --force --manifest ${manifest} ` +
73 `--payload_type zip ` +
74 `${image_dir} ${out} `,
75 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
76 Description: "ZipAPEX ${image_dir} => ${out}",
77 }, "tool_path", "image_dir", "copy_commands", "manifest")
78
Colin Crossa4925902018-11-16 11:36:28 -080079 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
80 blueprint.RuleParams{
81 Command: `${aapt2} convert --output-format proto $in -o $out`,
82 CommandDeps: []string{"${aapt2}"},
83 })
84
85 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090086 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000087 `apex_payload.img:apex/${abi}.img ` +
88 `apex_manifest.json:root/apex_manifest.json ` +
Shahar Amitai328b0772018-11-26 14:12:02 +000089 `AndroidManifest.xml:manifest/AndroidManifest.xml`,
Colin Crossa4925902018-11-16 11:36:28 -080090 CommandDeps: []string{"${zip2zip}"},
91 Description: "app bundle",
92 }, "abi")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090093)
94
Alex Light5098a612018-11-29 17:12:15 -080095var imageApexSuffix = ".apex"
96var zipApexSuffix = ".zipapex"
97
98var imageApexType = "image"
99var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900100
101type dependencyTag struct {
102 blueprint.BaseDependencyTag
103 name string
104}
105
106var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900107 sharedLibTag = dependencyTag{name: "sharedLib"}
108 executableTag = dependencyTag{name: "executable"}
109 javaLibTag = dependencyTag{name: "javaLib"}
110 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100111 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900112 keyTag = dependencyTag{name: "key"}
113 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900114 usesTag = dependencyTag{name: "uses"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900115)
116
117func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700118 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900119 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900120 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100121 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
122 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
123 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
124 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000125 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100126 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
127 } else {
128 return pctx.HostBinToolPath(ctx, tool).String()
129 }
130 })
131 }
132 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900133 pctx.HostBinToolVariable("avbtool", "avbtool")
134 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
135 pctx.HostBinToolVariable("merge_zips", "merge_zips")
136 pctx.HostBinToolVariable("mke2fs", "mke2fs")
137 pctx.HostBinToolVariable("resize2fs", "resize2fs")
138 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
139 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800140 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900141 pctx.HostBinToolVariable("zipalign", "zipalign")
142
Alex Light0851b882019-02-07 13:20:53 -0800143 android.RegisterModuleType("apex", apexBundleFactory)
144 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900145 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700146 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900147
148 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
149 ctx.TopDown("apex_deps", apexDepsMutator)
Colin Cross643614d2019-06-19 22:51:38 -0700150 ctx.BottomUp("apex", apexMutator).Parallel()
Jooyung Han5c998b92019-06-27 11:30:33 +0900151 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900152 })
153}
154
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900155// Mark the direct and transitive dependencies of apex bundles so that they
156// can be built for the apex bundles.
157func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800158 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800159 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900160 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900161 depName := mctx.OtherModuleName(child)
162 // If the parent is apexBundle, this child is directly depended.
163 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800164 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800165 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
166 // non-installable apex's cannot be installed and so should not prevent libraries from being
167 // installed to the system.
168 android.UpdateApexDependency(apexBundleName, depName, directDep)
169 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900170
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900171 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900172 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900173 return true
174 } else {
175 return false
176 }
177 })
178 }
179}
180
181// Create apex variations if a module is included in APEX(s).
182func apexMutator(mctx android.BottomUpMutatorContext) {
183 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900184 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900185 } else if _, ok := mctx.Module().(*apexBundle); ok {
186 // apex bundle itself is mutated so that it and its modules have same
187 // apex variant.
188 apexBundleName := mctx.ModuleName()
189 mctx.CreateVariations(apexBundleName)
190 }
191}
Jooyung Han5c998b92019-06-27 11:30:33 +0900192func apexUsesMutator(mctx android.BottomUpMutatorContext) {
193 if ab, ok := mctx.Module().(*apexBundle); ok {
194 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
195 }
196}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900197
Alex Light9670d332019-01-29 18:07:33 -0800198type apexNativeDependencies struct {
199 // List of native libraries
200 Native_shared_libs []string
201 // List of native executables
202 Binaries []string
Roland Levillain630846d2019-06-26 12:48:34 +0100203 // List of native tests
204 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800205}
206type apexMultilibProperties struct {
207 // Native dependencies whose compile_multilib is "first"
208 First apexNativeDependencies
209
210 // Native dependencies whose compile_multilib is "both"
211 Both apexNativeDependencies
212
213 // Native dependencies whose compile_multilib is "prefer32"
214 Prefer32 apexNativeDependencies
215
216 // Native dependencies whose compile_multilib is "32"
217 Lib32 apexNativeDependencies
218
219 // Native dependencies whose compile_multilib is "64"
220 Lib64 apexNativeDependencies
221}
222
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900223type apexBundleProperties struct {
224 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000225 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800226 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900227
Jiyong Park40e26a22019-02-08 02:53:06 +0900228 // AndroidManifest.xml file used for the zip container of this APEX bundle.
229 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800230 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900231
Jiyong Park05e70dd2019-03-18 14:26:32 +0900232 // Canonical name of the APEX bundle in the manifest file.
233 // If unspecified, defaults to the value of name
234 Apex_name *string
235
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900236 // Determines the file contexts file for setting security context to each file in this APEX bundle.
237 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
238 // used.
239 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900240 File_contexts *string
241
242 // List of native shared libs that are embedded inside this APEX bundle
243 Native_shared_libs []string
244
Roland Levillain630846d2019-06-26 12:48:34 +0100245 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900246 Binaries []string
247
248 // List of java libraries that are embedded inside this APEX bundle
249 Java_libs []string
250
251 // List of prebuilt files that are embedded inside this APEX bundle
252 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900253
Roland Levillain630846d2019-06-26 12:48:34 +0100254 // List of tests that are embedded inside this APEX bundle
255 Tests []string
256
Jiyong Parkff1458f2018-10-12 21:49:38 +0900257 // Name of the apex_key module that provides the private key to sign APEX
258 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900259
Alex Light5098a612018-11-29 17:12:15 -0800260 // The type of APEX to build. Controls what the APEX payload is. Either
261 // 'image', 'zip' or 'both'. Default: 'image'.
262 Payload_type *string
263
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900264 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
265 // or an android_app_certificate module name in the form ":module".
266 Certificate *string
267
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900268 // Whether this APEX is installable to one of the partitions. Default: true.
269 Installable *bool
270
Jiyong Parkda6eb592018-12-19 17:12:36 +0900271 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
272 // Default is false.
273 Use_vendor *bool
274
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800275 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
276 Ignore_system_library_special_case *bool
277
Alex Light9670d332019-01-29 18:07:33 -0800278 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900279
Jiyong Parkf97782b2019-02-13 20:28:58 +0900280 // List of sanitizer names that this APEX is enabled for
281 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900282
283 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
284 Provide_cpp_shared_libs *bool
285
286 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
287 Uses []string
Alex Light9670d332019-01-29 18:07:33 -0800288}
289
290type apexTargetBundleProperties struct {
291 Target struct {
292 // Multilib properties only for android.
293 Android struct {
294 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900295 }
Alex Light9670d332019-01-29 18:07:33 -0800296 // Multilib properties only for host.
297 Host struct {
298 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900299 }
Alex Light9670d332019-01-29 18:07:33 -0800300 // Multilib properties only for host linux_bionic.
301 Linux_bionic struct {
302 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900303 }
Alex Light9670d332019-01-29 18:07:33 -0800304 // Multilib properties only for host linux_glibc.
305 Linux_glibc struct {
306 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900307 }
308 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900309}
310
Jiyong Park8fd61922018-11-08 02:50:25 +0900311type apexFileClass int
312
313const (
314 etc apexFileClass = iota
315 nativeSharedLib
316 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900317 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800318 pyBinary
319 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900320 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100321 nativeTest
Jiyong Park8fd61922018-11-08 02:50:25 +0900322)
323
Alex Light5098a612018-11-29 17:12:15 -0800324type apexPackaging int
325
326const (
327 imageApex apexPackaging = iota
328 zipApex
329 both
330)
331
332func (a apexPackaging) image() bool {
333 switch a {
334 case imageApex, both:
335 return true
336 }
337 return false
338}
339
340func (a apexPackaging) zip() bool {
341 switch a {
342 case zipApex, both:
343 return true
344 }
345 return false
346}
347
348func (a apexPackaging) suffix() string {
349 switch a {
350 case imageApex:
351 return imageApexSuffix
352 case zipApex:
353 return zipApexSuffix
354 case both:
355 panic(fmt.Errorf("must be either zip or image"))
356 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100357 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800358 }
359}
360
361func (a apexPackaging) name() string {
362 switch a {
363 case imageApex:
364 return imageApexType
365 case zipApex:
366 return zipApexType
367 case both:
368 panic(fmt.Errorf("must be either zip or image"))
369 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100370 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800371 }
372}
373
Jiyong Park8fd61922018-11-08 02:50:25 +0900374func (class apexFileClass) NameInMake() string {
375 switch class {
376 case etc:
377 return "ETC"
378 case nativeSharedLib:
379 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800380 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900381 return "EXECUTABLES"
382 case javaSharedLib:
383 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100384 case nativeTest:
385 return "NATIVE_TESTS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900386 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100387 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900388 }
389}
390
391type apexFile struct {
392 builtFile android.Path
393 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900394 installDir string
395 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900396 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800397 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900398}
399
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900400type apexBundle struct {
401 android.ModuleBase
402 android.DefaultableModuleBase
403
Alex Light9670d332019-01-29 18:07:33 -0800404 properties apexBundleProperties
405 targetProperties apexTargetBundleProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900406
Alex Light5098a612018-11-29 17:12:15 -0800407 apexTypes apexPackaging
408
Colin Crossa4925902018-11-16 11:36:28 -0800409 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800410 outputFiles map[apexPackaging]android.WritablePath
Colin Crossa4925902018-11-16 11:36:28 -0800411 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900412
Jiyong Park03b68dd2019-07-26 23:20:40 +0900413 prebuiltFileToDelete string
414
Jiyong Park42cca6c2019-04-01 11:15:50 +0900415 public_key_file android.Path
416 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900417
418 container_certificate_file android.Path
419 container_private_key_file android.Path
420
Jiyong Park8fd61922018-11-08 02:50:25 +0900421 // list of files to be included in this apex
422 filesInfo []apexFile
423
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900424 // list of module names that this APEX is depending on
425 externalDeps []string
426
Jiyong Park8fd61922018-11-08 02:50:25 +0900427 flattened bool
Alex Light0851b882019-02-07 13:20:53 -0800428
429 testApex bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900430}
431
Jiyong Park397e55e2018-10-24 21:09:55 +0900432func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100433 native_shared_libs []string, binaries []string, tests []string,
434 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900435 // Use *FarVariation* to be able to depend on modules having
436 // conflicting variations with this module. This is required since
437 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
438 // for native shared libs.
439 ctx.AddFarVariationDependencies([]blueprint.Variation{
440 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900441 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900442 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900443 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900444 }, sharedLibTag, native_shared_libs...)
445
446 ctx.AddFarVariationDependencies([]blueprint.Variation{
447 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900448 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900449 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100450
451 ctx.AddFarVariationDependencies([]blueprint.Variation{
452 {Mutator: "arch", Variation: arch},
453 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100454 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100455 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900456}
457
Alex Light9670d332019-01-29 18:07:33 -0800458func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
459 if ctx.Os().Class == android.Device {
460 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
461 } else {
462 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
463 if ctx.Os().Bionic() {
464 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
465 } else {
466 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
467 }
468 }
469}
470
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900471func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800472
Jiyong Park397e55e2018-10-24 21:09:55 +0900473 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900474 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800475
476 a.combineProperties(ctx)
477
Jiyong Park397e55e2018-10-24 21:09:55 +0900478 has32BitTarget := false
479 for _, target := range targets {
480 if target.Arch.ArchType.Multilib == "lib32" {
481 has32BitTarget = true
482 }
483 }
484 for i, target := range targets {
485 // When multilib.* is omitted for native_shared_libs, it implies
486 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900487 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900488 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900489 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900490 {Mutator: "link", Variation: "shared"},
491 }, sharedLibTag, a.properties.Native_shared_libs...)
492
Roland Levillain630846d2019-06-26 12:48:34 +0100493 // When multilib.* is omitted for tests, it implies
494 // multilib.both.
495 ctx.AddFarVariationDependencies([]blueprint.Variation{
496 {Mutator: "arch", Variation: target.String()},
497 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100498 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100499 }, testTag, a.properties.Tests...)
500
Jiyong Park397e55e2018-10-24 21:09:55 +0900501 // Add native modules targetting both ABIs
502 addDependenciesForNativeModules(ctx,
503 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100504 a.properties.Multilib.Both.Binaries,
505 a.properties.Multilib.Both.Tests,
506 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900507 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900508
Alex Light3d673592019-01-18 14:37:31 -0800509 isPrimaryAbi := i == 0
510 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900511 // When multilib.* is omitted for binaries, it implies
512 // multilib.first.
513 ctx.AddFarVariationDependencies([]blueprint.Variation{
514 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900515 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900516 }, executableTag, a.properties.Binaries...)
517
518 // Add native modules targetting the first ABI
519 addDependenciesForNativeModules(ctx,
520 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100521 a.properties.Multilib.First.Binaries,
522 a.properties.Multilib.First.Tests,
523 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900524 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800525
526 // When multilib.* is omitted for prebuilts, it implies multilib.first.
527 ctx.AddFarVariationDependencies([]blueprint.Variation{
528 {Mutator: "arch", Variation: target.String()},
529 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900530 }
531
532 switch target.Arch.ArchType.Multilib {
533 case "lib32":
534 // Add native modules targetting 32-bit ABI
535 addDependenciesForNativeModules(ctx,
536 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100537 a.properties.Multilib.Lib32.Binaries,
538 a.properties.Multilib.Lib32.Tests,
539 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900540 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900541
542 addDependenciesForNativeModules(ctx,
543 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100544 a.properties.Multilib.Prefer32.Binaries,
545 a.properties.Multilib.Prefer32.Tests,
546 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900547 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900548 case "lib64":
549 // Add native modules targetting 64-bit ABI
550 addDependenciesForNativeModules(ctx,
551 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100552 a.properties.Multilib.Lib64.Binaries,
553 a.properties.Multilib.Lib64.Tests,
554 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900555 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900556
557 if !has32BitTarget {
558 addDependenciesForNativeModules(ctx,
559 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100560 a.properties.Multilib.Prefer32.Binaries,
561 a.properties.Multilib.Prefer32.Tests,
562 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900563 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900564 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700565
566 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
567 for _, sanitizer := range ctx.Config().SanitizeDevice() {
568 if sanitizer == "hwaddress" {
569 addDependenciesForNativeModules(ctx,
570 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100571 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700572 break
573 }
574 }
575 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900576 }
577
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900578 }
579
Jiyong Parkff1458f2018-10-12 21:49:38 +0900580 ctx.AddFarVariationDependencies([]blueprint.Variation{
581 {Mutator: "arch", Variation: "android_common"},
582 }, javaLibTag, a.properties.Java_libs...)
583
Jiyong Park23c52b02019-02-02 13:13:47 +0900584 if String(a.properties.Key) == "" {
585 ctx.ModuleErrorf("key is missing")
586 return
587 }
588 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900589
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900590 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900591 if cert != "" {
592 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900593 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900594}
595
Colin Cross0ea8ba82019-06-06 14:33:29 -0700596func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900597 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
598 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000599 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900600 }
601 return String(a.properties.Certificate)
602}
603
Colin Cross41955e82019-05-29 14:40:35 -0700604func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
605 switch tag {
606 case "":
607 if file, ok := a.outputFiles[imageApex]; ok {
608 return android.Paths{file}, nil
609 } else {
610 return nil, nil
611 }
612 default:
613 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900614 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900615}
616
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900617func (a *apexBundle) installable() bool {
618 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
619}
620
Jiyong Park7c1dc612019-01-05 11:15:24 +0900621func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
622 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900623 return "vendor"
624 } else {
625 return "core"
626 }
627}
628
Jiyong Parkf97782b2019-02-13 20:28:58 +0900629func (a *apexBundle) EnableSanitizer(sanitizerName string) {
630 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
631 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
632 }
633}
634
Jiyong Park388ef3f2019-01-28 19:47:32 +0900635func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900636 if android.InList(sanitizerName, a.properties.SanitizerNames) {
637 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900638 }
639
640 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900641 globalSanitizerNames := []string{}
642 if a.Host() {
643 globalSanitizerNames = ctx.Config().SanitizeHost()
644 } else {
645 arches := ctx.Config().SanitizeDeviceArch()
646 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
647 globalSanitizerNames = ctx.Config().SanitizeDevice()
648 }
649 }
650 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900651}
652
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800653func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900654 // Decide the APEX-local directory by the multilib of the library
655 // In the future, we may query this to the module.
656 switch cc.Arch().ArchType.Multilib {
657 case "lib32":
658 dirInApex = "lib"
659 case "lib64":
660 dirInApex = "lib64"
661 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900662 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200663 if !cc.Arch().Native {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900664 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200665 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
666 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900667 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800668 if handleSpecialLibs {
669 switch cc.Name() {
670 case "libc", "libm", "libdl":
671 // Special case for bionic libs. This is to prevent the bionic libs
672 // from being included in the search path /apex/com.android.apex/lib.
673 // This exclusion is required because bionic libs in the runtime APEX
674 // are available via the legacy paths /system/lib/libc.so, etc. By the
675 // init process, the bionic libs in the APEX are bind-mounted to the
676 // legacy paths and thus will be loaded into the default linker namespace.
677 // If the bionic libs are directly in /apex/com.android.apex/lib then
678 // the same libs will be again loaded to the runtime linker namespace,
679 // which will result double loading of bionic libs that isn't supported.
680 dirInApex = filepath.Join(dirInApex, "bionic")
681 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900682 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900683
684 fileToCopy = cc.OutputFile().Path()
685 return
686}
687
688func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900689 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200690 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900691 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200692 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
693 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900694 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900695 fileToCopy = cc.OutputFile().Path()
696 return
697}
698
Alex Light778127a2019-02-27 14:19:50 -0800699func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
700 dirInApex = "bin"
701 fileToCopy = py.HostToolPath().Path()
702 return
703}
704func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
705 dirInApex = "bin"
706 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
707 if err != nil {
708 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
709 return
710 }
711 fileToCopy = android.PathForOutput(ctx, s)
712 return
713}
714
Jiyong Park04480cf2019-02-06 00:16:29 +0900715func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
716 dirInApex = filepath.Join("bin", sh.SubDir())
717 fileToCopy = sh.OutputFile()
718 return
719}
720
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900721func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
722 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900723 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900724 return
725}
726
727func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
728 dirInApex = filepath.Join("etc", prebuilt.SubDir())
729 fileToCopy = prebuilt.OutputFile()
730 return
731}
732
733func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900734 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900735
Alex Light5098a612018-11-29 17:12:15 -0800736 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
737 a.apexTypes = imageApex
738 } else if *a.properties.Payload_type == "zip" {
739 a.apexTypes = zipApex
740 } else if *a.properties.Payload_type == "both" {
741 a.apexTypes = both
742 } else {
743 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
744 return
745 }
746
Roland Levillain630846d2019-06-26 12:48:34 +0100747 if len(a.properties.Tests) > 0 && !a.testApex {
748 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
749 return
750 }
751
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800752 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
753
Jooyung Han5c998b92019-06-27 11:30:33 +0900754 // Check if "uses" requirements are met with dependent apexBundles
755 var providedNativeSharedLibs []string
756 useVendor := proptools.Bool(a.properties.Use_vendor)
757 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
758 if ctx.OtherModuleDependencyTag(m) != usesTag {
759 return
760 }
761 otherName := ctx.OtherModuleName(m)
762 other, ok := m.(*apexBundle)
763 if !ok {
764 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
765 return
766 }
767 if proptools.Bool(other.properties.Use_vendor) != useVendor {
768 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
769 return
770 }
771 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
772 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
773 return
774 }
775 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
776 })
777
Alex Light778127a2019-02-27 14:19:50 -0800778 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +0100779 depTag := ctx.OtherModuleDependencyTag(child)
780 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900781 if _, ok := parent.(*apexBundle); ok {
782 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900783 switch depTag {
784 case sharedLibTag:
785 if cc, ok := child.(*cc.Module); ok {
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800786 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900787 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900788 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900789 } else {
790 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900791 }
792 case executableTag:
793 if cc, ok := child.(*cc.Module); ok {
794 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900795 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900796 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900797 } else if sh, ok := child.(*android.ShBinary); ok {
798 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
799 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -0800800 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
801 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
802 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
803 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
804 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
805 // NB: Since go binaries are static we don't need the module for anything here, which is
806 // good since the go tool is a blueprint.Module not an android.Module like we would
807 // normally use.
808 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900809 } else {
Alex Light778127a2019-02-27 14:19:50 -0800810 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 +0900811 }
812 case javaLibTag:
813 if java, ok := child.(*java.Library); ok {
814 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java)
Jiyong Park8fd61922018-11-08 02:50:25 +0900815 if fileToCopy == nil {
816 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
817 } else {
Jiyong Park719b4462019-01-13 00:39:51 +0900818 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900819 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900820 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900821 } else {
822 ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900823 }
824 case prebuiltTag:
825 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
826 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900827 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900828 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900829 } else {
830 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
831 }
Roland Levillain630846d2019-06-26 12:48:34 +0100832 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +0100833 if ccTest, ok := child.(*cc.Module); ok {
834 if ccTest.IsTestPerSrcAllTestsVariation() {
835 // Multiple-output test module (where `test_per_src: true`).
836 //
837 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
838 // We do not add this variation to `filesInfo`, as it has no output;
839 // however, we do add the other variations of this module as indirect
840 // dependencies (see below).
841 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +0100842 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +0100843 // Single-output test module (where `test_per_src: false`).
844 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
845 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +0100846 }
Roland Levillain630846d2019-06-26 12:48:34 +0100847 return true
848 } else {
849 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
850 }
Jiyong Parkff1458f2018-10-12 21:49:38 +0900851 case keyTag:
852 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900853 a.private_key_file = key.private_key_file
854 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +0900855 return false
856 } else {
857 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900858 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900859 case certificateTag:
860 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900861 a.container_certificate_file = dep.Certificate.Pem
862 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900863 return false
864 } else {
865 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
866 }
Jiyong Park03b68dd2019-07-26 23:20:40 +0900867 case android.PrebuiltDepTag:
868 // If the prebuilt is force disabled, remember to delete the prebuilt file
869 // that might have been installed in the previous builds
870 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
871 a.prebuiltFileToDelete = prebuilt.InstallFilename()
872 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900873 }
874 } else {
875 // indirect dependencies
876 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +0100877 // We cannot use a switch statement on `depTag` here as the checked
878 // tags used below are private (e.g. `cc.sharedDepTag`).
879 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
880 if cc, ok := child.(*cc.Module); ok {
881 if android.InList(cc.Name(), providedNativeSharedLibs) {
882 // If we're using a shared library which is provided from other APEX,
883 // don't include it in this APEX
884 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900885 }
Roland Levillainf89cd092019-07-29 16:22:59 +0100886 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
887 // If the dependency is a stubs lib, don't include it in this APEX,
888 // but make sure that the lib is installed on the device.
889 // In case no APEX is having the lib, the lib is installed to the system
890 // partition.
891 //
892 // Always include if we are a host-apex however since those won't have any
893 // system libraries.
894 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
895 a.externalDeps = append(a.externalDeps, cc.Name())
896 }
897 // Don't track further
898 return false
899 }
900 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
901 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
902 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900903 }
Roland Levillainf89cd092019-07-29 16:22:59 +0100904 } else if cc.IsTestPerSrcDepTag(depTag) {
905 if cc, ok := child.(*cc.Module); ok {
906 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
907 // Handle modules created as `test_per_src` variations of a single test module:
908 // use the name of the generated test binary (`fileToCopy`) instead of the name
909 // of the original test module (`depName`, shared by all `test_per_src`
910 // variations of that module).
911 moduleName := filepath.Base(fileToCopy.String())
912 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
913 return true
914 }
915 } else {
916 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900917 }
918 }
919 }
920 return false
921 })
922
Jiyong Park9335a262018-12-24 11:31:58 +0900923 a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900924 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +0900925 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
926 return
927 }
928
Jiyong Park8fd61922018-11-08 02:50:25 +0900929 // remove duplicates in filesInfo
930 removeDup := func(filesInfo []apexFile) []apexFile {
931 encountered := make(map[android.Path]bool)
932 result := []apexFile{}
933 for _, f := range filesInfo {
934 if !encountered[f.builtFile] {
935 encountered[f.builtFile] = true
936 result = append(result, f)
937 }
938 }
939 return result
940 }
941 filesInfo = removeDup(filesInfo)
942
943 // to have consistent build rules
944 sort.Slice(filesInfo, func(i, j int) bool {
945 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
946 })
947
948 // prepend the name of this APEX to the module names. These names will be the names of
949 // modules that will be defined if the APEX is flattened.
950 for i := range filesInfo {
951 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
952 }
953
Jiyong Park8fd61922018-11-08 02:50:25 +0900954 a.installDir = android.PathForModuleInstall(ctx, "apex")
955 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -0800956
957 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900958 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -0800959 }
960 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +0900961 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +0100962 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +0900963 // in other modules. It is in AndroidMk where the selection of flattened
964 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900965 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +0900966 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +0900967 }
968}
969
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700970func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +0900971 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +0900972 for _, f := range a.filesInfo {
973 if f.module != nil {
974 notice := f.module.NoticeFile()
975 if notice.Valid() {
976 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +0900977 }
978 }
979 }
980 // append the notice file specified in the apex module itself
981 if a.NoticeFile().Valid() {
982 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +0900983 }
984
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700985 if len(noticeFiles) == 0 {
986 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +0900987 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700988
Jaewoong Jung98772792019-07-01 17:15:13 -0700989 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +0900990}
991
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900992func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900993 cert := String(a.properties.Certificate)
994 if cert != "" && android.SrcIsModule(cert) == "" {
995 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900996 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
997 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900998 } else if cert == "" {
999 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001000 a.container_certificate_file = pem
1001 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001002 }
1003
Colin Cross8a497952019-03-05 22:25:09 -08001004 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001005
Alex Light5098a612018-11-29 17:12:15 -08001006 var abis []string
1007 for _, target := range ctx.MultiTargets() {
1008 if len(target.Arch.Abi) > 0 {
1009 abis = append(abis, target.Arch.Abi[0])
1010 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001011 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001012
Alex Light5098a612018-11-29 17:12:15 -08001013 abis = android.FirstUniqueStrings(abis)
1014
1015 suffix := apexType.suffix()
1016 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001018 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001019 for _, f := range a.filesInfo {
1020 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001021 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001022
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001023 copyCommands := []string{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001024 for i, src := range filesToCopy {
1025 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Alex Light5098a612018-11-29 17:12:15 -08001026 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001027 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1028 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001029 for _, sym := range a.filesInfo[i].symlinks {
1030 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1031 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1032 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001034 implicitInputs := append(android.Paths(nil), filesToCopy...)
Alex Light5098a612018-11-29 17:12:15 -08001035 implicitInputs = append(implicitInputs, manifest)
1036
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001037 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1038 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001039
Alex Light5098a612018-11-29 17:12:15 -08001040 if apexType.image() {
1041 // files and dirs that will be created in APEX
1042 var readOnlyPaths []string
1043 var executablePaths []string // this also includes dirs
1044 for _, f := range a.filesInfo {
1045 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001046 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001047 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001048 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001049 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001050 }
Alex Light5098a612018-11-29 17:12:15 -08001051 } else {
1052 readOnlyPaths = append(readOnlyPaths, pathInApex)
1053 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001054 dir := f.installDir
1055 for !android.InList(dir, executablePaths) && dir != "" {
1056 executablePaths = append(executablePaths, dir)
1057 dir, _ = filepath.Split(dir) // move up to the parent
1058 if len(dir) > 0 {
1059 // remove trailing slash
1060 dir = dir[:len(dir)-1]
1061 }
Alex Light5098a612018-11-29 17:12:15 -08001062 }
1063 }
1064 sort.Strings(readOnlyPaths)
1065 sort.Strings(executablePaths)
1066 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1067 ctx.Build(pctx, android.BuildParams{
1068 Rule: generateFsConfig,
1069 Output: cannedFsConfig,
1070 Description: "generate fs config",
1071 Args: map[string]string{
1072 "ro_paths": strings.Join(readOnlyPaths, " "),
1073 "exec_paths": strings.Join(executablePaths, " "),
1074 },
1075 })
1076
1077 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1078 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1079 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1080 if !fileContextsOptionalPath.Valid() {
1081 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1082 return
1083 }
1084 fileContexts := fileContextsOptionalPath.Path()
1085
Jiyong Park835d82b2018-12-27 16:04:18 +09001086 optFlags := []string{}
1087
Alex Light5098a612018-11-29 17:12:15 -08001088 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001089 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1090 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001091
Jiyong Park7f67f482019-01-05 12:57:48 +09001092 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1093 if overridden {
1094 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1095 }
1096
Jiyong Park40e26a22019-02-08 02:53:06 +09001097 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001098 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001099 implicitInputs = append(implicitInputs, androidManifestFile)
1100 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1101 }
1102
Jiyong Park71b519d2019-04-18 17:25:49 +09001103 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1104 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1105 ctx.Config().UnbundledBuild() &&
1106 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1107 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1108 apiFingerprint := java.ApiFingerprintPath(ctx)
1109 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1110 implicitInputs = append(implicitInputs, apiFingerprint)
1111 }
1112 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1113
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001114 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1115 if noticeFile.Valid() {
1116 // If there's a NOTICE file, embed it as an asset file in the APEX.
1117 implicitInputs = append(implicitInputs, noticeFile.Path())
1118 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1119 }
1120
Alex Light5098a612018-11-29 17:12:15 -08001121 ctx.Build(pctx, android.BuildParams{
1122 Rule: apexRule,
1123 Implicits: implicitInputs,
1124 Output: unsignedOutputFile,
1125 Description: "apex (" + apexType.name() + ")",
1126 Args: map[string]string{
1127 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1128 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1129 "copy_commands": strings.Join(copyCommands, " && "),
1130 "manifest": manifest.String(),
1131 "file_contexts": fileContexts.String(),
1132 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001133 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001134 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001135 },
1136 })
1137
1138 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1139 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1140 a.bundleModuleFile = bundleModuleFile
1141
1142 ctx.Build(pctx, android.BuildParams{
1143 Rule: apexProtoConvertRule,
1144 Input: unsignedOutputFile,
1145 Output: apexProtoFile,
1146 Description: "apex proto convert",
1147 })
1148
1149 ctx.Build(pctx, android.BuildParams{
1150 Rule: apexBundleRule,
1151 Input: apexProtoFile,
1152 Output: a.bundleModuleFile,
1153 Description: "apex bundle module",
1154 Args: map[string]string{
1155 "abi": strings.Join(abis, "."),
1156 },
1157 })
1158 } else {
1159 ctx.Build(pctx, android.BuildParams{
1160 Rule: zipApexRule,
1161 Implicits: implicitInputs,
1162 Output: unsignedOutputFile,
1163 Description: "apex (" + apexType.name() + ")",
1164 Args: map[string]string{
1165 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1166 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1167 "copy_commands": strings.Join(copyCommands, " && "),
1168 "manifest": manifest.String(),
1169 },
1170 })
Colin Crossa4925902018-11-16 11:36:28 -08001171 }
Colin Crossa4925902018-11-16 11:36:28 -08001172
Alex Light5098a612018-11-29 17:12:15 -08001173 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001174 ctx.Build(pctx, android.BuildParams{
1175 Rule: java.Signapk,
1176 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001177 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001178 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001179 Implicits: []android.Path{
1180 a.container_certificate_file,
1181 a.container_private_key_file,
1182 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001183 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001184 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001185 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001186 },
1187 })
Alex Light5098a612018-11-29 17:12:15 -08001188
1189 // Install to $OUT/soong/{target,host}/.../apex
Alex Light2a2561f2019-02-12 16:59:09 -08001190 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001191 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001192 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001193}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001194
Jiyong Park8fd61922018-11-08 02:50:25 +09001195func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001196 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001197 // 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 +09001198 // with other ordinary files.
Colin Cross8a497952019-03-05 22:25:09 -08001199 manifest := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jiyong Parkd699cb92019-01-10 00:23:16 +09001200
1201 // rename to apex_manifest.json
1202 copiedManifest := android.PathForModuleOut(ctx, "apex_manifest.json")
1203 ctx.Build(pctx, android.BuildParams{
1204 Rule: android.Cp,
1205 Input: manifest,
1206 Output: copiedManifest,
1207 })
Jiyong Park719b4462019-01-13 00:39:51 +09001208 a.filesInfo = append(a.filesInfo, apexFile{copiedManifest, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001209
Jiyong Park42cca6c2019-04-01 11:15:50 +09001210 // rename to apex_pubkey
1211 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1212 ctx.Build(pctx, android.BuildParams{
1213 Rule: android.Cp,
1214 Input: a.public_key_file,
1215 Output: copiedPubkey,
1216 })
1217 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1218
Jiyong Park23c52b02019-02-02 13:13:47 +09001219 if ctx.Config().FlattenApex() {
1220 for _, fi := range a.filesInfo {
1221 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001222 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1223 for _, sym := range fi.symlinks {
1224 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1225 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001226 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001227 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001228 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001229}
1230
1231func (a *apexBundle) AndroidMk() android.AndroidMkData {
Alex Light5098a612018-11-29 17:12:15 -08001232 writers := []android.AndroidMkData{}
1233 if a.apexTypes.image() {
1234 writers = append(writers, a.androidMkForType(imageApex))
1235 }
1236 if a.apexTypes.zip() {
1237 writers = append(writers, a.androidMkForType(zipApex))
1238 }
1239 return android.AndroidMkData{
1240 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1241 for _, data := range writers {
1242 data.Custom(w, name, prefix, moduleDir, data)
1243 }
1244 }}
1245}
1246
Alex Lightf1801bc2019-02-13 11:10:07 -08001247func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001248 moduleNames := []string{}
1249
1250 for _, fi := range a.filesInfo {
1251 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1252 continue
1253 }
1254 if !android.InList(fi.moduleName, moduleNames) {
1255 moduleNames = append(moduleNames, fi.moduleName)
1256 }
1257 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1258 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1259 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
Jiyong Park05e70dd2019-03-18 14:26:32 +09001260 // /apex/<name>/{lib|framework|...}
1261 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1262 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Alex Lightf1801bc2019-02-13 11:10:07 -08001263 if a.flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001264 // /system/apex/<name>/{lib|framework|...}
1265 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1266 a.installDir.RelPathString(), name, fi.installDir))
Jiyong Park05e70dd2019-03-18 14:26:32 +09001267 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
Alex Lightf4857cf2019-02-22 13:00:04 -08001268 if len(fi.symlinks) > 0 {
1269 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1270 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001271
1272 if fi.module != nil && fi.module.NoticeFile().Valid() {
1273 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1274 }
Jiyong Park94427262019-02-05 23:18:47 +09001275 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001276 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001277 }
1278 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1279 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1280 if fi.module != nil {
1281 archStr := fi.module.Target().Arch.ArchType.String()
1282 host := false
1283 switch fi.module.Target().Os.Class {
1284 case android.Host:
1285 if archStr != "common" {
1286 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1287 }
1288 host = true
1289 case android.HostCross:
1290 if archStr != "common" {
1291 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1292 }
1293 host = true
1294 case android.Device:
1295 if archStr != "common" {
1296 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1297 }
1298 }
1299 if host {
1300 makeOs := fi.module.Target().Os.String()
1301 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1302 makeOs = "linux"
1303 }
1304 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1305 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1306 }
1307 }
1308 if fi.class == javaSharedLib {
1309 javaModule := fi.module.(*java.Library)
1310 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1311 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1312 // we will have foo.jar.jar
1313 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1314 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1315 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1316 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1317 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1318 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
1319 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable {
1320 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001321 if cc, ok := fi.module.(*cc.Module); ok {
1322 if cc.UnstrippedOutputFile() != nil {
1323 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1324 }
1325 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Park94427262019-02-05 23:18:47 +09001326 }
1327 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1328 } else {
1329 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1330 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1331 }
1332 }
1333 return moduleNames
1334}
1335
Alex Light5098a612018-11-29 17:12:15 -08001336func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001337 return android.AndroidMkData{
1338 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1339 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001340 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001341 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001342 }
1343
Jiyong Park719b4462019-01-13 00:39:51 +09001344 if a.flattened && apexType.image() {
1345 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001346 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1347 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1348 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001349 if len(moduleNames) > 0 {
1350 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1351 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001352 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park719b4462019-01-13 00:39:51 +09001353 } else {
Alex Light5098a612018-11-29 17:12:15 -08001354 // zip-apex is the less common type so have the name refer to the image-apex
1355 // only and use {name}.zip if you want the zip-apex
1356 if apexType == zipApex && a.apexTypes == both {
1357 name = name + ".zip"
1358 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001359 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1360 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1361 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1362 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001363 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001364 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001365 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001366 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001367 if len(moduleNames) > 0 {
1368 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1369 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001370 if len(a.externalDeps) > 0 {
1371 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1372 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001373 if a.prebuiltFileToDelete != "" {
1374 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1375 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1376 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001377 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001378
Alex Light5098a612018-11-29 17:12:15 -08001379 if apexType == imageApex {
1380 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1381 }
Jiyong Park719b4462019-01-13 00:39:51 +09001382 }
1383 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001384}
1385
Alex Light0851b882019-02-07 13:20:53 -08001386func testApexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001387 return ApexBundleFactory(true /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001388}
1389
1390func apexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001391 return ApexBundleFactory(false /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001392}
1393
1394func ApexBundleFactory(testApex bool) android.Module {
Alex Light5098a612018-11-29 17:12:15 -08001395 module := &apexBundle{
1396 outputFiles: map[apexPackaging]android.WritablePath{},
Alex Light0851b882019-02-07 13:20:53 -08001397 testApex: testApex,
Alex Light5098a612018-11-29 17:12:15 -08001398 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001399 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001400 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001401 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001402 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1403 })
Alex Light5098a612018-11-29 17:12:15 -08001404 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001405 android.InitDefaultableModule(module)
1406 return module
1407}
Jiyong Park30ca9372019-02-07 16:27:23 +09001408
1409//
1410// Defaults
1411//
1412type Defaults struct {
1413 android.ModuleBase
1414 android.DefaultsModuleBase
1415}
1416
Jiyong Park30ca9372019-02-07 16:27:23 +09001417func defaultsFactory() android.Module {
1418 return DefaultsFactory()
1419}
1420
1421func DefaultsFactory(props ...interface{}) android.Module {
1422 module := &Defaults{}
1423
1424 module.AddProperties(props...)
1425 module.AddProperties(
1426 &apexBundleProperties{},
1427 &apexTargetBundleProperties{},
1428 )
1429
1430 android.InitDefaultsModule(module)
1431 return module
1432}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001433
1434//
1435// Prebuilt APEX
1436//
1437type Prebuilt struct {
1438 android.ModuleBase
1439 prebuilt android.Prebuilt
1440
1441 properties PrebuiltProperties
1442
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001443 inputApex android.Path
1444 installDir android.OutputPath
1445 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001446 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001447}
1448
1449type PrebuiltProperties struct {
1450 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001451 Source string `blueprint:"mutated"`
1452 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001453
1454 Src *string
1455 Arch struct {
1456 Arm struct {
1457 Src *string
1458 }
1459 Arm64 struct {
1460 Src *string
1461 }
1462 X86 struct {
1463 Src *string
1464 }
1465 X86_64 struct {
1466 Src *string
1467 }
1468 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001469
1470 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001471 // Optional name for the installed apex. If unspecified, name of the
1472 // module is used as the file name
1473 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001474
1475 // Names of modules to be overridden. Listed modules can only be other binaries
1476 // (in Make or Soong).
1477 // This does not completely prevent installation of the overridden binaries, but if both
1478 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1479 // from PRODUCT_PACKAGES.
1480 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001481}
1482
1483func (p *Prebuilt) installable() bool {
1484 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001485}
1486
1487func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001488 // If the device is configured to use flattened APEX, force disable the prebuilt because
1489 // the prebuilt is a non-flattened one.
1490 forceDisable := ctx.Config().FlattenApex()
1491
1492 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1493 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001494 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001495
1496 // b/137216042 don't use prebuilts when address sanitizer is on
1497 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1498 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1499
1500 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001501 p.properties.ForceDisable = true
1502 return
1503 }
1504
Jiyong Parkc95714e2019-03-29 14:23:10 +09001505 // This is called before prebuilt_select and prebuilt_postdeps mutators
1506 // The mutators requires that src to be set correctly for each arch so that
1507 // arch variants are disabled when src is not provided for the arch.
1508 if len(ctx.MultiTargets()) != 1 {
1509 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1510 return
1511 }
1512 var src string
1513 switch ctx.MultiTargets()[0].Arch.ArchType {
1514 case android.Arm:
1515 src = String(p.properties.Arch.Arm.Src)
1516 case android.Arm64:
1517 src = String(p.properties.Arch.Arm64.Src)
1518 case android.X86:
1519 src = String(p.properties.Arch.X86.Src)
1520 case android.X86_64:
1521 src = String(p.properties.Arch.X86_64.Src)
1522 default:
1523 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1524 return
1525 }
1526 if src == "" {
1527 src = String(p.properties.Src)
1528 }
1529 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001530}
1531
Jiyong Park03b68dd2019-07-26 23:20:40 +09001532func (p *Prebuilt) isForceDisabled() bool {
1533 return p.properties.ForceDisable
1534}
1535
Colin Cross41955e82019-05-29 14:40:35 -07001536func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1537 switch tag {
1538 case "":
1539 return android.Paths{p.outputApex}, nil
1540 default:
1541 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1542 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001543}
1544
Jiyong Park4d277042019-04-23 18:00:10 +09001545func (p *Prebuilt) InstallFilename() string {
1546 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1547}
1548
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001549func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001550 if p.properties.ForceDisable {
1551 return
1552 }
1553
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001554 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001555 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001556 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001557 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001558 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1559 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1560 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001561 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1562 ctx.Build(pctx, android.BuildParams{
1563 Rule: android.Cp,
1564 Input: p.inputApex,
1565 Output: p.outputApex,
1566 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001567 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001568 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001569 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001570}
1571
1572func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1573 return &p.prebuilt
1574}
1575
1576func (p *Prebuilt) Name() string {
1577 return p.prebuilt.Name(p.ModuleBase.Name())
1578}
1579
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001580func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1581 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001582 Class: "ETC",
1583 OutputFile: android.OptionalPathForPath(p.inputApex),
1584 Include: "$(BUILD_PREBUILT)",
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001585 AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
1586 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1587 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1588 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1589 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001590 },
1591 }
1592}
1593
1594// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1595func PrebuiltFactory() android.Module {
1596 module := &Prebuilt{}
1597 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001598 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001599 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001600 return module
1601}