blob: 5ca9d7d818512e98a8f16a87f016f38c4166158b [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
Jooyung Hane1633032019-08-01 17:41:43 +090049 injectApexDependency = pctx.StaticRule("injectApexDependency", blueprint.RuleParams{
50 Command: `rm -f $out && ${jsonmodify} $in ` +
51 `-a provideNativeLibs ${provideNativeLibs} ` +
52 `-a requireNativeLibs ${requireNativeLibs} -o $out`,
53 CommandDeps: []string{"${jsonmodify}"},
54 Description: "Inject dependency into ${out}",
55 }, "provideNativeLibs", "requireNativeLibs")
56
Jiyong Park48ca7dc2018-10-10 14:01:00 +090057 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
58 // against the binary policy using sefcontext_compiler -p <policy>.
59
60 // TODO(b/114327326): automate the generation of file_contexts
61 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
62 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
63 `(${copy_commands}) && ` +
64 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090065 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090066 `--file_contexts ${file_contexts} ` +
67 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080068 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090069 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090070 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
71 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000072 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Jiyong Park48ca7dc2018-10-10 14:01:00 +090073 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090074 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080075
Alex Light5098a612018-11-29 17:12:15 -080076 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
77 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
78 `(${copy_commands}) && ` +
79 `APEXER_TOOL_PATH=${tool_path} ` +
80 `${apexer} --force --manifest ${manifest} ` +
81 `--payload_type zip ` +
82 `${image_dir} ${out} `,
83 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
84 Description: "ZipAPEX ${image_dir} => ${out}",
85 }, "tool_path", "image_dir", "copy_commands", "manifest")
86
Colin Crossa4925902018-11-16 11:36:28 -080087 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
88 blueprint.RuleParams{
89 Command: `${aapt2} convert --output-format proto $in -o $out`,
90 CommandDeps: []string{"${aapt2}"},
91 })
92
93 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090094 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000095 `apex_payload.img:apex/${abi}.img ` +
96 `apex_manifest.json:root/apex_manifest.json ` +
Shahar Amitai328b0772018-11-26 14:12:02 +000097 `AndroidManifest.xml:manifest/AndroidManifest.xml`,
Colin Crossa4925902018-11-16 11:36:28 -080098 CommandDeps: []string{"${zip2zip}"},
99 Description: "app bundle",
100 }, "abi")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900101)
102
Alex Light5098a612018-11-29 17:12:15 -0800103var imageApexSuffix = ".apex"
104var zipApexSuffix = ".zipapex"
105
106var imageApexType = "image"
107var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900108
109type dependencyTag struct {
110 blueprint.BaseDependencyTag
111 name string
112}
113
114var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900115 sharedLibTag = dependencyTag{name: "sharedLib"}
116 executableTag = dependencyTag{name: "executable"}
117 javaLibTag = dependencyTag{name: "javaLib"}
118 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100119 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900120 keyTag = dependencyTag{name: "key"}
121 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900122 usesTag = dependencyTag{name: "uses"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900123)
124
125func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700126 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900127 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900128 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100129 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
130 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
131 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
132 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000133 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100134 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
135 } else {
136 return pctx.HostBinToolPath(ctx, tool).String()
137 }
138 })
139 }
140 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900141 pctx.HostBinToolVariable("avbtool", "avbtool")
142 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
143 pctx.HostBinToolVariable("merge_zips", "merge_zips")
144 pctx.HostBinToolVariable("mke2fs", "mke2fs")
145 pctx.HostBinToolVariable("resize2fs", "resize2fs")
146 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
147 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800148 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900149 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900150 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900151
Alex Light0851b882019-02-07 13:20:53 -0800152 android.RegisterModuleType("apex", apexBundleFactory)
153 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900154 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700155 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900156
157 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
158 ctx.TopDown("apex_deps", apexDepsMutator)
Colin Cross643614d2019-06-19 22:51:38 -0700159 ctx.BottomUp("apex", apexMutator).Parallel()
Jooyung Han5c998b92019-06-27 11:30:33 +0900160 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900161 })
162}
163
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900164// Mark the direct and transitive dependencies of apex bundles so that they
165// can be built for the apex bundles.
166func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800167 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800168 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900169 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900170 depName := mctx.OtherModuleName(child)
171 // If the parent is apexBundle, this child is directly depended.
172 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800173 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800174 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
175 // non-installable apex's cannot be installed and so should not prevent libraries from being
176 // installed to the system.
177 android.UpdateApexDependency(apexBundleName, depName, directDep)
178 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900179
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900180 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900181 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900182 return true
183 } else {
184 return false
185 }
186 })
187 }
188}
189
190// Create apex variations if a module is included in APEX(s).
191func apexMutator(mctx android.BottomUpMutatorContext) {
192 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900193 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900194 } else if _, ok := mctx.Module().(*apexBundle); ok {
195 // apex bundle itself is mutated so that it and its modules have same
196 // apex variant.
197 apexBundleName := mctx.ModuleName()
198 mctx.CreateVariations(apexBundleName)
199 }
200}
Jooyung Han5c998b92019-06-27 11:30:33 +0900201func apexUsesMutator(mctx android.BottomUpMutatorContext) {
202 if ab, ok := mctx.Module().(*apexBundle); ok {
203 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
204 }
205}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900206
Alex Light9670d332019-01-29 18:07:33 -0800207type apexNativeDependencies struct {
208 // List of native libraries
209 Native_shared_libs []string
210 // List of native executables
211 Binaries []string
Roland Levillain630846d2019-06-26 12:48:34 +0100212 // List of native tests
213 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800214}
215type apexMultilibProperties struct {
216 // Native dependencies whose compile_multilib is "first"
217 First apexNativeDependencies
218
219 // Native dependencies whose compile_multilib is "both"
220 Both apexNativeDependencies
221
222 // Native dependencies whose compile_multilib is "prefer32"
223 Prefer32 apexNativeDependencies
224
225 // Native dependencies whose compile_multilib is "32"
226 Lib32 apexNativeDependencies
227
228 // Native dependencies whose compile_multilib is "64"
229 Lib64 apexNativeDependencies
230}
231
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900232type apexBundleProperties struct {
233 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000234 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800235 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900236
Jiyong Park40e26a22019-02-08 02:53:06 +0900237 // AndroidManifest.xml file used for the zip container of this APEX bundle.
238 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800239 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900240
Jiyong Park05e70dd2019-03-18 14:26:32 +0900241 // Canonical name of the APEX bundle in the manifest file.
242 // If unspecified, defaults to the value of name
243 Apex_name *string
244
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900245 // Determines the file contexts file for setting security context to each file in this APEX bundle.
246 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
247 // used.
248 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900249 File_contexts *string
250
251 // List of native shared libs that are embedded inside this APEX bundle
252 Native_shared_libs []string
253
Roland Levillain630846d2019-06-26 12:48:34 +0100254 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900255 Binaries []string
256
257 // List of java libraries that are embedded inside this APEX bundle
258 Java_libs []string
259
260 // List of prebuilt files that are embedded inside this APEX bundle
261 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900262
Roland Levillain630846d2019-06-26 12:48:34 +0100263 // List of tests that are embedded inside this APEX bundle
264 Tests []string
265
Jiyong Parkff1458f2018-10-12 21:49:38 +0900266 // Name of the apex_key module that provides the private key to sign APEX
267 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900268
Alex Light5098a612018-11-29 17:12:15 -0800269 // The type of APEX to build. Controls what the APEX payload is. Either
270 // 'image', 'zip' or 'both'. Default: 'image'.
271 Payload_type *string
272
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900273 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
274 // or an android_app_certificate module name in the form ":module".
275 Certificate *string
276
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900277 // Whether this APEX is installable to one of the partitions. Default: true.
278 Installable *bool
279
Jiyong Parkda6eb592018-12-19 17:12:36 +0900280 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
281 // Default is false.
282 Use_vendor *bool
283
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800284 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
285 Ignore_system_library_special_case *bool
286
Alex Light9670d332019-01-29 18:07:33 -0800287 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900288
Jiyong Parkf97782b2019-02-13 20:28:58 +0900289 // List of sanitizer names that this APEX is enabled for
290 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900291
292 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
293 Provide_cpp_shared_libs *bool
294
295 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
296 Uses []string
Alex Light9670d332019-01-29 18:07:33 -0800297}
298
299type apexTargetBundleProperties struct {
300 Target struct {
301 // Multilib properties only for android.
302 Android struct {
303 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900304 }
Alex Light9670d332019-01-29 18:07:33 -0800305 // Multilib properties only for host.
306 Host struct {
307 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900308 }
Alex Light9670d332019-01-29 18:07:33 -0800309 // Multilib properties only for host linux_bionic.
310 Linux_bionic struct {
311 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900312 }
Alex Light9670d332019-01-29 18:07:33 -0800313 // Multilib properties only for host linux_glibc.
314 Linux_glibc struct {
315 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900316 }
317 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900318}
319
Jiyong Park8fd61922018-11-08 02:50:25 +0900320type apexFileClass int
321
322const (
323 etc apexFileClass = iota
324 nativeSharedLib
325 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900326 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800327 pyBinary
328 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900329 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100330 nativeTest
Jiyong Park8fd61922018-11-08 02:50:25 +0900331)
332
Alex Light5098a612018-11-29 17:12:15 -0800333type apexPackaging int
334
335const (
336 imageApex apexPackaging = iota
337 zipApex
338 both
339)
340
341func (a apexPackaging) image() bool {
342 switch a {
343 case imageApex, both:
344 return true
345 }
346 return false
347}
348
349func (a apexPackaging) zip() bool {
350 switch a {
351 case zipApex, both:
352 return true
353 }
354 return false
355}
356
357func (a apexPackaging) suffix() string {
358 switch a {
359 case imageApex:
360 return imageApexSuffix
361 case zipApex:
362 return zipApexSuffix
363 case both:
364 panic(fmt.Errorf("must be either zip or image"))
365 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100366 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800367 }
368}
369
370func (a apexPackaging) name() string {
371 switch a {
372 case imageApex:
373 return imageApexType
374 case zipApex:
375 return zipApexType
376 case both:
377 panic(fmt.Errorf("must be either zip or image"))
378 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100379 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800380 }
381}
382
Jiyong Park8fd61922018-11-08 02:50:25 +0900383func (class apexFileClass) NameInMake() string {
384 switch class {
385 case etc:
386 return "ETC"
387 case nativeSharedLib:
388 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800389 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900390 return "EXECUTABLES"
391 case javaSharedLib:
392 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100393 case nativeTest:
394 return "NATIVE_TESTS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900395 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100396 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900397 }
398}
399
400type apexFile struct {
401 builtFile android.Path
402 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900403 installDir string
404 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900405 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800406 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900407}
408
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900409type apexBundle struct {
410 android.ModuleBase
411 android.DefaultableModuleBase
412
Alex Light9670d332019-01-29 18:07:33 -0800413 properties apexBundleProperties
414 targetProperties apexTargetBundleProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900415
Alex Light5098a612018-11-29 17:12:15 -0800416 apexTypes apexPackaging
417
Colin Crossa4925902018-11-16 11:36:28 -0800418 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800419 outputFiles map[apexPackaging]android.WritablePath
Colin Crossa4925902018-11-16 11:36:28 -0800420 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900421
Jiyong Park03b68dd2019-07-26 23:20:40 +0900422 prebuiltFileToDelete string
423
Jiyong Park42cca6c2019-04-01 11:15:50 +0900424 public_key_file android.Path
425 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900426
427 container_certificate_file android.Path
428 container_private_key_file android.Path
429
Jiyong Park8fd61922018-11-08 02:50:25 +0900430 // list of files to be included in this apex
431 filesInfo []apexFile
432
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900433 // list of module names that this APEX is depending on
434 externalDeps []string
435
Jiyong Park8fd61922018-11-08 02:50:25 +0900436 flattened bool
Alex Light0851b882019-02-07 13:20:53 -0800437
438 testApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900439
440 // intermediate path for apex_manifest.json
441 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900442}
443
Jiyong Park397e55e2018-10-24 21:09:55 +0900444func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100445 native_shared_libs []string, binaries []string, tests []string,
446 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900447 // Use *FarVariation* to be able to depend on modules having
448 // conflicting variations with this module. This is required since
449 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
450 // for native shared libs.
451 ctx.AddFarVariationDependencies([]blueprint.Variation{
452 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900453 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900454 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900455 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900456 }, sharedLibTag, native_shared_libs...)
457
458 ctx.AddFarVariationDependencies([]blueprint.Variation{
459 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900460 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900461 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100462
463 ctx.AddFarVariationDependencies([]blueprint.Variation{
464 {Mutator: "arch", Variation: arch},
465 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100466 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100467 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900468}
469
Alex Light9670d332019-01-29 18:07:33 -0800470func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
471 if ctx.Os().Class == android.Device {
472 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
473 } else {
474 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
475 if ctx.Os().Bionic() {
476 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
477 } else {
478 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
479 }
480 }
481}
482
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900483func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800484
Jiyong Park397e55e2018-10-24 21:09:55 +0900485 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900486 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800487
488 a.combineProperties(ctx)
489
Jiyong Park397e55e2018-10-24 21:09:55 +0900490 has32BitTarget := false
491 for _, target := range targets {
492 if target.Arch.ArchType.Multilib == "lib32" {
493 has32BitTarget = true
494 }
495 }
496 for i, target := range targets {
497 // When multilib.* is omitted for native_shared_libs, it implies
498 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900499 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900500 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900501 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900502 {Mutator: "link", Variation: "shared"},
503 }, sharedLibTag, a.properties.Native_shared_libs...)
504
Roland Levillain630846d2019-06-26 12:48:34 +0100505 // When multilib.* is omitted for tests, it implies
506 // multilib.both.
507 ctx.AddFarVariationDependencies([]blueprint.Variation{
508 {Mutator: "arch", Variation: target.String()},
509 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100510 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100511 }, testTag, a.properties.Tests...)
512
Jiyong Park397e55e2018-10-24 21:09:55 +0900513 // Add native modules targetting both ABIs
514 addDependenciesForNativeModules(ctx,
515 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100516 a.properties.Multilib.Both.Binaries,
517 a.properties.Multilib.Both.Tests,
518 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900519 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900520
Alex Light3d673592019-01-18 14:37:31 -0800521 isPrimaryAbi := i == 0
522 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900523 // When multilib.* is omitted for binaries, it implies
524 // multilib.first.
525 ctx.AddFarVariationDependencies([]blueprint.Variation{
526 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900527 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900528 }, executableTag, a.properties.Binaries...)
529
530 // Add native modules targetting the first ABI
531 addDependenciesForNativeModules(ctx,
532 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100533 a.properties.Multilib.First.Binaries,
534 a.properties.Multilib.First.Tests,
535 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900536 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800537
538 // When multilib.* is omitted for prebuilts, it implies multilib.first.
539 ctx.AddFarVariationDependencies([]blueprint.Variation{
540 {Mutator: "arch", Variation: target.String()},
541 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900542 }
543
544 switch target.Arch.ArchType.Multilib {
545 case "lib32":
546 // Add native modules targetting 32-bit ABI
547 addDependenciesForNativeModules(ctx,
548 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100549 a.properties.Multilib.Lib32.Binaries,
550 a.properties.Multilib.Lib32.Tests,
551 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900552 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900553
554 addDependenciesForNativeModules(ctx,
555 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100556 a.properties.Multilib.Prefer32.Binaries,
557 a.properties.Multilib.Prefer32.Tests,
558 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900559 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900560 case "lib64":
561 // Add native modules targetting 64-bit ABI
562 addDependenciesForNativeModules(ctx,
563 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100564 a.properties.Multilib.Lib64.Binaries,
565 a.properties.Multilib.Lib64.Tests,
566 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900567 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900568
569 if !has32BitTarget {
570 addDependenciesForNativeModules(ctx,
571 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100572 a.properties.Multilib.Prefer32.Binaries,
573 a.properties.Multilib.Prefer32.Tests,
574 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900575 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900576 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700577
578 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
579 for _, sanitizer := range ctx.Config().SanitizeDevice() {
580 if sanitizer == "hwaddress" {
581 addDependenciesForNativeModules(ctx,
582 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100583 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700584 break
585 }
586 }
587 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900588 }
589
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900590 }
591
Jiyong Parkff1458f2018-10-12 21:49:38 +0900592 ctx.AddFarVariationDependencies([]blueprint.Variation{
593 {Mutator: "arch", Variation: "android_common"},
594 }, javaLibTag, a.properties.Java_libs...)
595
Jiyong Park23c52b02019-02-02 13:13:47 +0900596 if String(a.properties.Key) == "" {
597 ctx.ModuleErrorf("key is missing")
598 return
599 }
600 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900601
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900602 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900603 if cert != "" {
604 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900605 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900606}
607
Colin Cross0ea8ba82019-06-06 14:33:29 -0700608func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900609 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
610 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000611 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900612 }
613 return String(a.properties.Certificate)
614}
615
Colin Cross41955e82019-05-29 14:40:35 -0700616func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
617 switch tag {
618 case "":
619 if file, ok := a.outputFiles[imageApex]; ok {
620 return android.Paths{file}, nil
621 } else {
622 return nil, nil
623 }
624 default:
625 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900626 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900627}
628
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900629func (a *apexBundle) installable() bool {
630 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
631}
632
Jiyong Park7c1dc612019-01-05 11:15:24 +0900633func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
634 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900635 return "vendor"
636 } else {
637 return "core"
638 }
639}
640
Jiyong Parkf97782b2019-02-13 20:28:58 +0900641func (a *apexBundle) EnableSanitizer(sanitizerName string) {
642 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
643 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
644 }
645}
646
Jiyong Park388ef3f2019-01-28 19:47:32 +0900647func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900648 if android.InList(sanitizerName, a.properties.SanitizerNames) {
649 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900650 }
651
652 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900653 globalSanitizerNames := []string{}
654 if a.Host() {
655 globalSanitizerNames = ctx.Config().SanitizeHost()
656 } else {
657 arches := ctx.Config().SanitizeDeviceArch()
658 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
659 globalSanitizerNames = ctx.Config().SanitizeDevice()
660 }
661 }
662 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900663}
664
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800665func getCopyManifestForNativeLibrary(cc *cc.Module, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900666 // Decide the APEX-local directory by the multilib of the library
667 // In the future, we may query this to the module.
668 switch cc.Arch().ArchType.Multilib {
669 case "lib32":
670 dirInApex = "lib"
671 case "lib64":
672 dirInApex = "lib64"
673 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900674 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200675 if !cc.Arch().Native {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900676 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200677 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
678 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900679 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800680 if handleSpecialLibs {
681 switch cc.Name() {
682 case "libc", "libm", "libdl":
683 // Special case for bionic libs. This is to prevent the bionic libs
684 // from being included in the search path /apex/com.android.apex/lib.
685 // This exclusion is required because bionic libs in the runtime APEX
686 // are available via the legacy paths /system/lib/libc.so, etc. By the
687 // init process, the bionic libs in the APEX are bind-mounted to the
688 // legacy paths and thus will be loaded into the default linker namespace.
689 // If the bionic libs are directly in /apex/com.android.apex/lib then
690 // the same libs will be again loaded to the runtime linker namespace,
691 // which will result double loading of bionic libs that isn't supported.
692 dirInApex = filepath.Join(dirInApex, "bionic")
693 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900694 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900695
696 fileToCopy = cc.OutputFile().Path()
697 return
698}
699
700func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900701 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200702 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900703 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200704 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
705 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900706 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900707 fileToCopy = cc.OutputFile().Path()
708 return
709}
710
Alex Light778127a2019-02-27 14:19:50 -0800711func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
712 dirInApex = "bin"
713 fileToCopy = py.HostToolPath().Path()
714 return
715}
716func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
717 dirInApex = "bin"
718 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
719 if err != nil {
720 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
721 return
722 }
723 fileToCopy = android.PathForOutput(ctx, s)
724 return
725}
726
Jiyong Park04480cf2019-02-06 00:16:29 +0900727func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
728 dirInApex = filepath.Join("bin", sh.SubDir())
729 fileToCopy = sh.OutputFile()
730 return
731}
732
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900733func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
734 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900735 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900736 return
737}
738
739func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
740 dirInApex = filepath.Join("etc", prebuilt.SubDir())
741 fileToCopy = prebuilt.OutputFile()
742 return
743}
744
745func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900746 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900747
Alex Light5098a612018-11-29 17:12:15 -0800748 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
749 a.apexTypes = imageApex
750 } else if *a.properties.Payload_type == "zip" {
751 a.apexTypes = zipApex
752 } else if *a.properties.Payload_type == "both" {
753 a.apexTypes = both
754 } else {
755 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
756 return
757 }
758
Roland Levillain630846d2019-06-26 12:48:34 +0100759 if len(a.properties.Tests) > 0 && !a.testApex {
760 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
761 return
762 }
763
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800764 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
765
Jooyung Hane1633032019-08-01 17:41:43 +0900766 // native lib dependencies
767 var provideNativeLibs []string
768 var requireNativeLibs []string
769
Jooyung Han5c998b92019-06-27 11:30:33 +0900770 // Check if "uses" requirements are met with dependent apexBundles
771 var providedNativeSharedLibs []string
772 useVendor := proptools.Bool(a.properties.Use_vendor)
773 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
774 if ctx.OtherModuleDependencyTag(m) != usesTag {
775 return
776 }
777 otherName := ctx.OtherModuleName(m)
778 other, ok := m.(*apexBundle)
779 if !ok {
780 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
781 return
782 }
783 if proptools.Bool(other.properties.Use_vendor) != useVendor {
784 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
785 return
786 }
787 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
788 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
789 return
790 }
791 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
792 })
793
Alex Light778127a2019-02-27 14:19:50 -0800794 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +0100795 depTag := ctx.OtherModuleDependencyTag(child)
796 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900797 if _, ok := parent.(*apexBundle); ok {
798 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900799 switch depTag {
800 case sharedLibTag:
801 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +0900802 if cc.HasStubsVariants() {
803 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
804 }
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800805 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900806 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900807 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900808 } else {
809 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900810 }
811 case executableTag:
812 if cc, ok := child.(*cc.Module); ok {
813 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900814 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900815 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900816 } else if sh, ok := child.(*android.ShBinary); ok {
817 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
818 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -0800819 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
820 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
821 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
822 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
823 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
824 // NB: Since go binaries are static we don't need the module for anything here, which is
825 // good since the go tool is a blueprint.Module not an android.Module like we would
826 // normally use.
827 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900828 } else {
Alex Light778127a2019-02-27 14:19:50 -0800829 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 +0900830 }
831 case javaLibTag:
832 if java, ok := child.(*java.Library); ok {
833 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java)
Jiyong Park8fd61922018-11-08 02:50:25 +0900834 if fileToCopy == nil {
835 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
836 } else {
Jiyong Park719b4462019-01-13 00:39:51 +0900837 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900838 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900839 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900840 } else {
841 ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900842 }
843 case prebuiltTag:
844 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
845 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900846 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900848 } else {
849 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
850 }
Roland Levillain630846d2019-06-26 12:48:34 +0100851 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +0100852 if ccTest, ok := child.(*cc.Module); ok {
853 if ccTest.IsTestPerSrcAllTestsVariation() {
854 // Multiple-output test module (where `test_per_src: true`).
855 //
856 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
857 // We do not add this variation to `filesInfo`, as it has no output;
858 // however, we do add the other variations of this module as indirect
859 // dependencies (see below).
860 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +0100861 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +0100862 // Single-output test module (where `test_per_src: false`).
863 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
864 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +0100865 }
Roland Levillain630846d2019-06-26 12:48:34 +0100866 return true
867 } else {
868 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
869 }
Jiyong Parkff1458f2018-10-12 21:49:38 +0900870 case keyTag:
871 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900872 a.private_key_file = key.private_key_file
873 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +0900874 return false
875 } else {
876 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900878 case certificateTag:
879 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900880 a.container_certificate_file = dep.Certificate.Pem
881 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900882 return false
883 } else {
884 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
885 }
Jiyong Park03b68dd2019-07-26 23:20:40 +0900886 case android.PrebuiltDepTag:
887 // If the prebuilt is force disabled, remember to delete the prebuilt file
888 // that might have been installed in the previous builds
889 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
890 a.prebuiltFileToDelete = prebuilt.InstallFilename()
891 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900892 }
893 } else {
894 // indirect dependencies
895 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +0100896 // We cannot use a switch statement on `depTag` here as the checked
897 // tags used below are private (e.g. `cc.sharedDepTag`).
898 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
899 if cc, ok := child.(*cc.Module); ok {
900 if android.InList(cc.Name(), providedNativeSharedLibs) {
901 // If we're using a shared library which is provided from other APEX,
902 // don't include it in this APEX
903 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900904 }
Roland Levillainf89cd092019-07-29 16:22:59 +0100905 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
906 // If the dependency is a stubs lib, don't include it in this APEX,
907 // but make sure that the lib is installed on the device.
908 // In case no APEX is having the lib, the lib is installed to the system
909 // partition.
910 //
911 // Always include if we are a host-apex however since those won't have any
912 // system libraries.
913 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
914 a.externalDeps = append(a.externalDeps, cc.Name())
915 }
Jooyung Hane1633032019-08-01 17:41:43 +0900916 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +0100917 // Don't track further
918 return false
919 }
920 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, handleSpecialLibs)
921 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
922 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900923 }
Roland Levillainf89cd092019-07-29 16:22:59 +0100924 } else if cc.IsTestPerSrcDepTag(depTag) {
925 if cc, ok := child.(*cc.Module); ok {
926 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
927 // Handle modules created as `test_per_src` variations of a single test module:
928 // use the name of the generated test binary (`fileToCopy`) instead of the name
929 // of the original test module (`depName`, shared by all `test_per_src`
930 // variations of that module).
931 moduleName := filepath.Base(fileToCopy.String())
932 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
933 return true
934 }
935 } else {
936 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900937 }
938 }
939 }
940 return false
941 })
942
Jiyong Park9335a262018-12-24 11:31:58 +0900943 a.flattened = ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900944 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +0900945 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
946 return
947 }
948
Jiyong Park8fd61922018-11-08 02:50:25 +0900949 // remove duplicates in filesInfo
950 removeDup := func(filesInfo []apexFile) []apexFile {
951 encountered := make(map[android.Path]bool)
952 result := []apexFile{}
953 for _, f := range filesInfo {
954 if !encountered[f.builtFile] {
955 encountered[f.builtFile] = true
956 result = append(result, f)
957 }
958 }
959 return result
960 }
961 filesInfo = removeDup(filesInfo)
962
963 // to have consistent build rules
964 sort.Slice(filesInfo, func(i, j int) bool {
965 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
966 })
967
968 // prepend the name of this APEX to the module names. These names will be the names of
969 // modules that will be defined if the APEX is flattened.
970 for i := range filesInfo {
971 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
972 }
973
Jiyong Park8fd61922018-11-08 02:50:25 +0900974 a.installDir = android.PathForModuleInstall(ctx, "apex")
975 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -0800976
Jooyung Hane1633032019-08-01 17:41:43 +0900977 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
978 // put dependency({provide|require}NativeLibs) in apex_manifest.json
979 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
980 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
981 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
982 ctx.Build(pctx, android.BuildParams{
983 Rule: injectApexDependency,
984 Input: manifestSrc,
985 Output: a.manifestOut,
986 Args: map[string]string{
987 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
988 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
989 },
990 })
991
Alex Light5098a612018-11-29 17:12:15 -0800992 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900993 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -0800994 }
995 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +0900996 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +0100997 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +0900998 // in other modules. It is in AndroidMk where the selection of flattened
999 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001000 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001001 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001002 }
1003}
1004
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001005func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001006 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001007 for _, f := range a.filesInfo {
1008 if f.module != nil {
1009 notice := f.module.NoticeFile()
1010 if notice.Valid() {
1011 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001012 }
1013 }
1014 }
1015 // append the notice file specified in the apex module itself
1016 if a.NoticeFile().Valid() {
1017 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001018 }
1019
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001020 if len(noticeFiles) == 0 {
1021 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001022 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001023
Jaewoong Jung98772792019-07-01 17:15:13 -07001024 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001025}
1026
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001027func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001028 cert := String(a.properties.Certificate)
1029 if cert != "" && android.SrcIsModule(cert) == "" {
1030 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001031 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1032 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001033 } else if cert == "" {
1034 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001035 a.container_certificate_file = pem
1036 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001037 }
1038
Alex Light5098a612018-11-29 17:12:15 -08001039 var abis []string
1040 for _, target := range ctx.MultiTargets() {
1041 if len(target.Arch.Abi) > 0 {
1042 abis = append(abis, target.Arch.Abi[0])
1043 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001044 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001045
Alex Light5098a612018-11-29 17:12:15 -08001046 abis = android.FirstUniqueStrings(abis)
1047
1048 suffix := apexType.suffix()
1049 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001050
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001051 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001052 for _, f := range a.filesInfo {
1053 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001055
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056 copyCommands := []string{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001057 for i, src := range filesToCopy {
1058 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Alex Light5098a612018-11-29 17:12:15 -08001059 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001060 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1061 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001062 for _, sym := range a.filesInfo[i].symlinks {
1063 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1064 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1065 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001066 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001067 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001068 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001069
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001070 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1071 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001072
Alex Light5098a612018-11-29 17:12:15 -08001073 if apexType.image() {
1074 // files and dirs that will be created in APEX
1075 var readOnlyPaths []string
1076 var executablePaths []string // this also includes dirs
1077 for _, f := range a.filesInfo {
1078 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001079 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001080 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001081 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001082 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001083 }
Alex Light5098a612018-11-29 17:12:15 -08001084 } else {
1085 readOnlyPaths = append(readOnlyPaths, pathInApex)
1086 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001087 dir := f.installDir
1088 for !android.InList(dir, executablePaths) && dir != "" {
1089 executablePaths = append(executablePaths, dir)
1090 dir, _ = filepath.Split(dir) // move up to the parent
1091 if len(dir) > 0 {
1092 // remove trailing slash
1093 dir = dir[:len(dir)-1]
1094 }
Alex Light5098a612018-11-29 17:12:15 -08001095 }
1096 }
1097 sort.Strings(readOnlyPaths)
1098 sort.Strings(executablePaths)
1099 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1100 ctx.Build(pctx, android.BuildParams{
1101 Rule: generateFsConfig,
1102 Output: cannedFsConfig,
1103 Description: "generate fs config",
1104 Args: map[string]string{
1105 "ro_paths": strings.Join(readOnlyPaths, " "),
1106 "exec_paths": strings.Join(executablePaths, " "),
1107 },
1108 })
1109
1110 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1111 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1112 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1113 if !fileContextsOptionalPath.Valid() {
1114 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1115 return
1116 }
1117 fileContexts := fileContextsOptionalPath.Path()
1118
Jiyong Park835d82b2018-12-27 16:04:18 +09001119 optFlags := []string{}
1120
Alex Light5098a612018-11-29 17:12:15 -08001121 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001122 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1123 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001124
Jiyong Park7f67f482019-01-05 12:57:48 +09001125 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1126 if overridden {
1127 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1128 }
1129
Jiyong Park40e26a22019-02-08 02:53:06 +09001130 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001131 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001132 implicitInputs = append(implicitInputs, androidManifestFile)
1133 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1134 }
1135
Jiyong Park71b519d2019-04-18 17:25:49 +09001136 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1137 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1138 ctx.Config().UnbundledBuild() &&
1139 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1140 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1141 apiFingerprint := java.ApiFingerprintPath(ctx)
1142 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1143 implicitInputs = append(implicitInputs, apiFingerprint)
1144 }
1145 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1146
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001147 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1148 if noticeFile.Valid() {
1149 // If there's a NOTICE file, embed it as an asset file in the APEX.
1150 implicitInputs = append(implicitInputs, noticeFile.Path())
1151 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1152 }
1153
Alex Light5098a612018-11-29 17:12:15 -08001154 ctx.Build(pctx, android.BuildParams{
1155 Rule: apexRule,
1156 Implicits: implicitInputs,
1157 Output: unsignedOutputFile,
1158 Description: "apex (" + apexType.name() + ")",
1159 Args: map[string]string{
1160 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1161 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1162 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001163 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001164 "file_contexts": fileContexts.String(),
1165 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001166 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001167 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001168 },
1169 })
1170
1171 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1172 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1173 a.bundleModuleFile = bundleModuleFile
1174
1175 ctx.Build(pctx, android.BuildParams{
1176 Rule: apexProtoConvertRule,
1177 Input: unsignedOutputFile,
1178 Output: apexProtoFile,
1179 Description: "apex proto convert",
1180 })
1181
1182 ctx.Build(pctx, android.BuildParams{
1183 Rule: apexBundleRule,
1184 Input: apexProtoFile,
1185 Output: a.bundleModuleFile,
1186 Description: "apex bundle module",
1187 Args: map[string]string{
1188 "abi": strings.Join(abis, "."),
1189 },
1190 })
1191 } else {
1192 ctx.Build(pctx, android.BuildParams{
1193 Rule: zipApexRule,
1194 Implicits: implicitInputs,
1195 Output: unsignedOutputFile,
1196 Description: "apex (" + apexType.name() + ")",
1197 Args: map[string]string{
1198 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1199 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1200 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001201 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001202 },
1203 })
Colin Crossa4925902018-11-16 11:36:28 -08001204 }
Colin Crossa4925902018-11-16 11:36:28 -08001205
Alex Light5098a612018-11-29 17:12:15 -08001206 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001207 ctx.Build(pctx, android.BuildParams{
1208 Rule: java.Signapk,
1209 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001210 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001211 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001212 Implicits: []android.Path{
1213 a.container_certificate_file,
1214 a.container_private_key_file,
1215 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001216 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001217 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001218 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001219 },
1220 })
Alex Light5098a612018-11-29 17:12:15 -08001221
1222 // Install to $OUT/soong/{target,host}/.../apex
Alex Light2a2561f2019-02-12 16:59:09 -08001223 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001224 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001225 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001226}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001227
Jiyong Park8fd61922018-11-08 02:50:25 +09001228func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001229 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001230 // 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 +09001231 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001232 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001233
Jiyong Park42cca6c2019-04-01 11:15:50 +09001234 // rename to apex_pubkey
1235 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1236 ctx.Build(pctx, android.BuildParams{
1237 Rule: android.Cp,
1238 Input: a.public_key_file,
1239 Output: copiedPubkey,
1240 })
1241 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1242
Jiyong Park23c52b02019-02-02 13:13:47 +09001243 if ctx.Config().FlattenApex() {
1244 for _, fi := range a.filesInfo {
1245 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001246 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1247 for _, sym := range fi.symlinks {
1248 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1249 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001250 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001251 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001252 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001253}
1254
1255func (a *apexBundle) AndroidMk() android.AndroidMkData {
Alex Light5098a612018-11-29 17:12:15 -08001256 writers := []android.AndroidMkData{}
1257 if a.apexTypes.image() {
1258 writers = append(writers, a.androidMkForType(imageApex))
1259 }
1260 if a.apexTypes.zip() {
1261 writers = append(writers, a.androidMkForType(zipApex))
1262 }
1263 return android.AndroidMkData{
1264 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1265 for _, data := range writers {
1266 data.Custom(w, name, prefix, moduleDir, data)
1267 }
1268 }}
1269}
1270
Alex Lightf1801bc2019-02-13 11:10:07 -08001271func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001272 moduleNames := []string{}
1273
1274 for _, fi := range a.filesInfo {
1275 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1276 continue
1277 }
1278 if !android.InList(fi.moduleName, moduleNames) {
1279 moduleNames = append(moduleNames, fi.moduleName)
1280 }
1281 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1282 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1283 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
Jiyong Park05e70dd2019-03-18 14:26:32 +09001284 // /apex/<name>/{lib|framework|...}
1285 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1286 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Alex Lightf1801bc2019-02-13 11:10:07 -08001287 if a.flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001288 // /system/apex/<name>/{lib|framework|...}
1289 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1290 a.installDir.RelPathString(), name, fi.installDir))
Jiyong Park05e70dd2019-03-18 14:26:32 +09001291 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
Alex Lightf4857cf2019-02-22 13:00:04 -08001292 if len(fi.symlinks) > 0 {
1293 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1294 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001295
1296 if fi.module != nil && fi.module.NoticeFile().Valid() {
1297 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1298 }
Jiyong Park94427262019-02-05 23:18:47 +09001299 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001300 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001301 }
1302 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1303 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1304 if fi.module != nil {
1305 archStr := fi.module.Target().Arch.ArchType.String()
1306 host := false
1307 switch fi.module.Target().Os.Class {
1308 case android.Host:
1309 if archStr != "common" {
1310 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1311 }
1312 host = true
1313 case android.HostCross:
1314 if archStr != "common" {
1315 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1316 }
1317 host = true
1318 case android.Device:
1319 if archStr != "common" {
1320 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1321 }
1322 }
1323 if host {
1324 makeOs := fi.module.Target().Os.String()
1325 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1326 makeOs = "linux"
1327 }
1328 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1329 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1330 }
1331 }
1332 if fi.class == javaSharedLib {
1333 javaModule := fi.module.(*java.Library)
1334 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1335 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1336 // we will have foo.jar.jar
1337 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1338 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1339 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1340 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1341 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1342 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
1343 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable {
1344 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001345 if cc, ok := fi.module.(*cc.Module); ok {
1346 if cc.UnstrippedOutputFile() != nil {
1347 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1348 }
1349 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Park94427262019-02-05 23:18:47 +09001350 }
1351 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1352 } else {
1353 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1354 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1355 }
1356 }
1357 return moduleNames
1358}
1359
Alex Light5098a612018-11-29 17:12:15 -08001360func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001361 return android.AndroidMkData{
1362 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1363 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001364 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001365 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001366 }
1367
Jiyong Park719b4462019-01-13 00:39:51 +09001368 if a.flattened && apexType.image() {
1369 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001370 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1371 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1372 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001373 if len(moduleNames) > 0 {
1374 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1375 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001376 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park719b4462019-01-13 00:39:51 +09001377 } else {
Alex Light5098a612018-11-29 17:12:15 -08001378 // zip-apex is the less common type so have the name refer to the image-apex
1379 // only and use {name}.zip if you want the zip-apex
1380 if apexType == zipApex && a.apexTypes == both {
1381 name = name + ".zip"
1382 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001383 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1384 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1385 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1386 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001387 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001388 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001389 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001390 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001391 if len(moduleNames) > 0 {
1392 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1393 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001394 if len(a.externalDeps) > 0 {
1395 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1396 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001397 if a.prebuiltFileToDelete != "" {
1398 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1399 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1400 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001401 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001402
Alex Light5098a612018-11-29 17:12:15 -08001403 if apexType == imageApex {
1404 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1405 }
Jiyong Park719b4462019-01-13 00:39:51 +09001406 }
1407 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001408}
1409
Alex Light0851b882019-02-07 13:20:53 -08001410func testApexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001411 return ApexBundleFactory(true /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001412}
1413
1414func apexBundleFactory() android.Module {
Roland Levillain630846d2019-06-26 12:48:34 +01001415 return ApexBundleFactory(false /*testApex*/)
Alex Light0851b882019-02-07 13:20:53 -08001416}
1417
1418func ApexBundleFactory(testApex bool) android.Module {
Alex Light5098a612018-11-29 17:12:15 -08001419 module := &apexBundle{
1420 outputFiles: map[apexPackaging]android.WritablePath{},
Alex Light0851b882019-02-07 13:20:53 -08001421 testApex: testApex,
Alex Light5098a612018-11-29 17:12:15 -08001422 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001423 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001424 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001425 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001426 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1427 })
Alex Light5098a612018-11-29 17:12:15 -08001428 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001429 android.InitDefaultableModule(module)
1430 return module
1431}
Jiyong Park30ca9372019-02-07 16:27:23 +09001432
1433//
1434// Defaults
1435//
1436type Defaults struct {
1437 android.ModuleBase
1438 android.DefaultsModuleBase
1439}
1440
Jiyong Park30ca9372019-02-07 16:27:23 +09001441func defaultsFactory() android.Module {
1442 return DefaultsFactory()
1443}
1444
1445func DefaultsFactory(props ...interface{}) android.Module {
1446 module := &Defaults{}
1447
1448 module.AddProperties(props...)
1449 module.AddProperties(
1450 &apexBundleProperties{},
1451 &apexTargetBundleProperties{},
1452 )
1453
1454 android.InitDefaultsModule(module)
1455 return module
1456}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001457
1458//
1459// Prebuilt APEX
1460//
1461type Prebuilt struct {
1462 android.ModuleBase
1463 prebuilt android.Prebuilt
1464
1465 properties PrebuiltProperties
1466
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001467 inputApex android.Path
1468 installDir android.OutputPath
1469 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001470 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001471}
1472
1473type PrebuiltProperties struct {
1474 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001475 Source string `blueprint:"mutated"`
1476 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001477
1478 Src *string
1479 Arch struct {
1480 Arm struct {
1481 Src *string
1482 }
1483 Arm64 struct {
1484 Src *string
1485 }
1486 X86 struct {
1487 Src *string
1488 }
1489 X86_64 struct {
1490 Src *string
1491 }
1492 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001493
1494 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001495 // Optional name for the installed apex. If unspecified, name of the
1496 // module is used as the file name
1497 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001498
1499 // Names of modules to be overridden. Listed modules can only be other binaries
1500 // (in Make or Soong).
1501 // This does not completely prevent installation of the overridden binaries, but if both
1502 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1503 // from PRODUCT_PACKAGES.
1504 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001505}
1506
1507func (p *Prebuilt) installable() bool {
1508 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001509}
1510
1511func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001512 // If the device is configured to use flattened APEX, force disable the prebuilt because
1513 // the prebuilt is a non-flattened one.
1514 forceDisable := ctx.Config().FlattenApex()
1515
1516 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1517 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001518 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001519
1520 // b/137216042 don't use prebuilts when address sanitizer is on
1521 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1522 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1523
1524 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001525 p.properties.ForceDisable = true
1526 return
1527 }
1528
Jiyong Parkc95714e2019-03-29 14:23:10 +09001529 // This is called before prebuilt_select and prebuilt_postdeps mutators
1530 // The mutators requires that src to be set correctly for each arch so that
1531 // arch variants are disabled when src is not provided for the arch.
1532 if len(ctx.MultiTargets()) != 1 {
1533 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1534 return
1535 }
1536 var src string
1537 switch ctx.MultiTargets()[0].Arch.ArchType {
1538 case android.Arm:
1539 src = String(p.properties.Arch.Arm.Src)
1540 case android.Arm64:
1541 src = String(p.properties.Arch.Arm64.Src)
1542 case android.X86:
1543 src = String(p.properties.Arch.X86.Src)
1544 case android.X86_64:
1545 src = String(p.properties.Arch.X86_64.Src)
1546 default:
1547 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1548 return
1549 }
1550 if src == "" {
1551 src = String(p.properties.Src)
1552 }
1553 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001554}
1555
Jiyong Park03b68dd2019-07-26 23:20:40 +09001556func (p *Prebuilt) isForceDisabled() bool {
1557 return p.properties.ForceDisable
1558}
1559
Colin Cross41955e82019-05-29 14:40:35 -07001560func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1561 switch tag {
1562 case "":
1563 return android.Paths{p.outputApex}, nil
1564 default:
1565 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1566 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001567}
1568
Jiyong Park4d277042019-04-23 18:00:10 +09001569func (p *Prebuilt) InstallFilename() string {
1570 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1571}
1572
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001573func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001574 if p.properties.ForceDisable {
1575 return
1576 }
1577
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001578 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001579 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001580 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001581 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001582 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1583 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1584 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001585 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1586 ctx.Build(pctx, android.BuildParams{
1587 Rule: android.Cp,
1588 Input: p.inputApex,
1589 Output: p.outputApex,
1590 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001591 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001592 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001593 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001594}
1595
1596func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1597 return &p.prebuilt
1598}
1599
1600func (p *Prebuilt) Name() string {
1601 return p.prebuilt.Name(p.ModuleBase.Name())
1602}
1603
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001604func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1605 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001606 Class: "ETC",
1607 OutputFile: android.OptionalPathForPath(p.inputApex),
1608 Include: "$(BUILD_PREBUILT)",
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001609 AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
1610 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1611 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1612 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1613 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001614 },
1615 }
1616}
1617
1618// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1619func PrebuiltFactory() android.Module {
1620 module := &Prebuilt{}
1621 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001622 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001623 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001624 return module
1625}