blob: 8b2dcbeff61f0dcb49335683f34185ffc51952b9 [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"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
36var (
37 pctx = android.NewPackageContext("android/apex")
38
39 // Create a canned fs config file where all files and directories are
40 // by default set to (uid/gid/mode) = (1000/1000/0644)
41 // TODO(b/113082813) make this configurable using config.fs syntax
42 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000043 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000044 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090045 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090046 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090047 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090048 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090049
Jooyung Hand15aa1f2019-09-27 00:38:03 +090050 apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
Jooyung Hane1633032019-08-01 17:41:43 +090051 Command: `rm -f $out && ${jsonmodify} $in ` +
52 `-a provideNativeLibs ${provideNativeLibs} ` +
Jooyung Hand15aa1f2019-09-27 00:38:03 +090053 `-a requireNativeLibs ${requireNativeLibs} ` +
54 `${opt} ` +
55 `-o $out`,
Jooyung Hane1633032019-08-01 17:41:43 +090056 CommandDeps: []string{"${jsonmodify}"},
Jooyung Hand15aa1f2019-09-27 00:38:03 +090057 Description: "prepare ${out}",
58 }, "provideNativeLibs", "requireNativeLibs", "opt")
Jooyung Hane1633032019-08-01 17:41:43 +090059
Jiyong Park48ca7dc2018-10-10 14:01:00 +090060 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
61 // against the binary policy using sefcontext_compiler -p <policy>.
62
63 // TODO(b/114327326): automate the generation of file_contexts
64 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
65 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010066 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090068 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069 `--file_contexts ${file_contexts} ` +
70 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080071 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090072 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090073 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
74 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000075 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010076 Rspfile: "${out}.copy_commands",
77 RspfileContent: "${copy_commands}",
78 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090079 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080080
Alex Light5098a612018-11-29 17:12:15 -080081 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
82 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010083 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080084 `APEXER_TOOL_PATH=${tool_path} ` +
85 `${apexer} --force --manifest ${manifest} ` +
86 `--payload_type zip ` +
87 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010088 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
89 Rspfile: "${out}.copy_commands",
90 RspfileContent: "${copy_commands}",
91 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080092 }, "tool_path", "image_dir", "copy_commands", "manifest")
93
Colin Crossa4925902018-11-16 11:36:28 -080094 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
95 blueprint.RuleParams{
96 Command: `${aapt2} convert --output-format proto $in -o $out`,
97 CommandDeps: []string{"${aapt2}"},
98 })
99
100 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +0900101 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +0000102 `apex_payload.img:apex/${abi}.img ` +
103 `apex_manifest.json:root/apex_manifest.json ` +
Jaewoong Jungb00c1fb2019-09-04 13:26:18 -0700104 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
105 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
Colin Crossa4925902018-11-16 11:36:28 -0800106 CommandDeps: []string{"${zip2zip}"},
107 Description: "app bundle",
108 }, "abi")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100109
110 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
111 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
112 Rspfile: "${out}.emit_commands",
113 RspfileContent: "${emit_commands}",
114 Description: "Emit APEX image content",
115 }, "emit_commands")
116
117 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
118 Command: `diff --unchanged-group-format='' \` +
119 `--changed-group-format='%<' \` +
120 `${image_content_file} ${whitelisted_files_file} || (` +
121 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
122 ` "To fix the build run following command:" && ` +
123 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
124 `exit 1)`,
125 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
126 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900127)
128
Alex Light5098a612018-11-29 17:12:15 -0800129var imageApexSuffix = ".apex"
130var zipApexSuffix = ".zipapex"
131
132var imageApexType = "image"
133var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900134
135type dependencyTag struct {
136 blueprint.BaseDependencyTag
137 name string
138}
139
140var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900141 sharedLibTag = dependencyTag{name: "sharedLib"}
142 executableTag = dependencyTag{name: "executable"}
143 javaLibTag = dependencyTag{name: "javaLib"}
144 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100145 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900146 keyTag = dependencyTag{name: "key"}
147 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900148 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900149 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900150)
151
152func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700153 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900154 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900155 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100156 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
157 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
158 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
159 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000160 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100161 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
162 } else {
163 return pctx.HostBinToolPath(ctx, tool).String()
164 }
165 })
166 }
167 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900168 pctx.HostBinToolVariable("avbtool", "avbtool")
169 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
170 pctx.HostBinToolVariable("merge_zips", "merge_zips")
171 pctx.HostBinToolVariable("mke2fs", "mke2fs")
172 pctx.HostBinToolVariable("resize2fs", "resize2fs")
173 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
174 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800175 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900176 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900177 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900178
Jiyong Parkd1063c12019-07-17 20:08:41 +0900179 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800180 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900181 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900182 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700183 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900184
Jooyung Han344d5432019-08-23 11:17:39 +0900185 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
186 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
187 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
188 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900189 android.PostDepsMutators(RegisterPostDepsMutators)
190}
191
192func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
193 ctx.TopDown("apex_deps", apexDepsMutator)
194 ctx.BottomUp("apex", apexMutator).Parallel()
195 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
196 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900197}
198
Jooyung Han344d5432019-08-23 11:17:39 +0900199var (
200 vndkApexListKey = android.NewOnceKey("vndkApexList")
201 vndkApexListMutex sync.Mutex
202)
203
204func vndkApexList(config android.Config) map[string]*apexBundle {
205 return config.Once(vndkApexListKey, func() interface{} {
206 return map[string]*apexBundle{}
207 }).(map[string]*apexBundle)
208}
209
210// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
211func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
212 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
213 if ab.IsNativeBridgeSupported() {
214 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
215 }
Jooyung Han90eee022019-10-01 20:02:42 +0900216
217 vndkVersion := proptools.String(ab.vndkProperties.Vndk_version)
218
Jooyung Han344d5432019-08-23 11:17:39 +0900219 vndkApexListMutex.Lock()
220 defer vndkApexListMutex.Unlock()
221 vndkApexList := vndkApexList(mctx.Config())
222 if other, ok := vndkApexList[vndkVersion]; ok {
Jooyung Han90eee022019-10-01 20:02:42 +0900223 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.BaseModuleName())
Jooyung Han344d5432019-08-23 11:17:39 +0900224 }
225 vndkApexList[vndkVersion] = ab
226 }
227}
228
229// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
230// It filters only libs with matching targets.
231func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
232 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
233 vndkApexList := vndkApexList(mctx.Config())
234 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
235 targetArch := cc.Target().String()
236 for _, target := range ab.MultiTargets() {
237 if target.String() == targetArch {
238 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
239 break
240 }
241 }
242 }
243 }
244}
245
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900246// Mark the direct and transitive dependencies of apex bundles so that they
247// can be built for the apex bundles.
248func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800249 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800250 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900251 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900252 depName := mctx.OtherModuleName(child)
253 // If the parent is apexBundle, this child is directly depended.
254 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800255 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800256 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
257 // non-installable apex's cannot be installed and so should not prevent libraries from being
258 // installed to the system.
259 android.UpdateApexDependency(apexBundleName, depName, directDep)
260 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900261
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900262 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900263 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900264 return true
265 } else {
266 return false
267 }
268 })
269 }
270}
271
272// Create apex variations if a module is included in APEX(s).
273func apexMutator(mctx android.BottomUpMutatorContext) {
274 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900275 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900276 } else if _, ok := mctx.Module().(*apexBundle); ok {
277 // apex bundle itself is mutated so that it and its modules have same
278 // apex variant.
279 apexBundleName := mctx.ModuleName()
280 mctx.CreateVariations(apexBundleName)
281 }
282}
Sundong Ahne9b55722019-09-06 17:37:42 +0900283
284func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900285 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900286 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
287 modules := mctx.CreateLocalVariations("", "flattened")
288 modules[0].(*apexBundle).SetFlattened(false)
289 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900290 } else {
291 ab.SetFlattened(true)
292 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900293 }
294 }
295}
296
Jooyung Han5c998b92019-06-27 11:30:33 +0900297func apexUsesMutator(mctx android.BottomUpMutatorContext) {
298 if ab, ok := mctx.Module().(*apexBundle); ok {
299 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
300 }
301}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900302
Alex Light9670d332019-01-29 18:07:33 -0800303type apexNativeDependencies struct {
304 // List of native libraries
305 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900306
Alex Light9670d332019-01-29 18:07:33 -0800307 // List of native executables
308 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900309
Roland Levillain630846d2019-06-26 12:48:34 +0100310 // List of native tests
311 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800312}
Jooyung Han344d5432019-08-23 11:17:39 +0900313
Alex Light9670d332019-01-29 18:07:33 -0800314type apexMultilibProperties struct {
315 // Native dependencies whose compile_multilib is "first"
316 First apexNativeDependencies
317
318 // Native dependencies whose compile_multilib is "both"
319 Both apexNativeDependencies
320
321 // Native dependencies whose compile_multilib is "prefer32"
322 Prefer32 apexNativeDependencies
323
324 // Native dependencies whose compile_multilib is "32"
325 Lib32 apexNativeDependencies
326
327 // Native dependencies whose compile_multilib is "64"
328 Lib64 apexNativeDependencies
329}
330
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900331type apexBundleProperties struct {
332 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000333 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800334 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900335
Jiyong Park40e26a22019-02-08 02:53:06 +0900336 // AndroidManifest.xml file used for the zip container of this APEX bundle.
337 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800338 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900339
Roland Levillain411c5842019-09-19 16:37:20 +0100340 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
341 // device (/apex/<apex_name>).
342 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900343 Apex_name *string
344
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900345 // Determines the file contexts file for setting security context to each file in this APEX bundle.
346 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
347 // used.
348 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900349 File_contexts *string
350
351 // List of native shared libs that are embedded inside this APEX bundle
352 Native_shared_libs []string
353
Roland Levillain630846d2019-06-26 12:48:34 +0100354 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900355 Binaries []string
356
357 // List of java libraries that are embedded inside this APEX bundle
358 Java_libs []string
359
360 // List of prebuilt files that are embedded inside this APEX bundle
361 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900362
Roland Levillain630846d2019-06-26 12:48:34 +0100363 // List of tests that are embedded inside this APEX bundle
364 Tests []string
365
Jiyong Parkff1458f2018-10-12 21:49:38 +0900366 // Name of the apex_key module that provides the private key to sign APEX
367 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900368
Alex Light5098a612018-11-29 17:12:15 -0800369 // The type of APEX to build. Controls what the APEX payload is. Either
370 // 'image', 'zip' or 'both'. Default: 'image'.
371 Payload_type *string
372
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900373 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
374 // or an android_app_certificate module name in the form ":module".
375 Certificate *string
376
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900377 // Whether this APEX is installable to one of the partitions. Default: true.
378 Installable *bool
379
Jiyong Parkda6eb592018-12-19 17:12:36 +0900380 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
381 // Default is false.
382 Use_vendor *bool
383
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800384 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
385 Ignore_system_library_special_case *bool
386
Alex Light9670d332019-01-29 18:07:33 -0800387 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900388
Jiyong Parkf97782b2019-02-13 20:28:58 +0900389 // List of sanitizer names that this APEX is enabled for
390 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900391
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900392 PreventInstall bool `blueprint:"mutated"`
393
394 HideFromMake bool `blueprint:"mutated"`
395
Jooyung Han5c998b92019-06-27 11:30:33 +0900396 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
397 Provide_cpp_shared_libs *bool
398
399 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
400 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100401
402 // A txt file containing list of files that are whitelisted to be included in this APEX.
403 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900404
405 // List of APKs to package inside APEX
406 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900407
Sundong Ahne8fb7242019-09-17 13:50:45 +0900408 // To distinguish between flattened and non-flattened apex.
409 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900410 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900411
Sundong Ahne8fb7242019-09-17 13:50:45 +0900412 // if true, it means that TARGET_FLATTEN_APEX is true and
413 // TARGET_BUILD_APPS is false
414 FlattenedConfigValue bool `blueprint:"mutated"`
415
Jiyong Parkd1063c12019-07-17 20:08:41 +0900416 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
417 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
418 // is implied. This value affects all modules included in this APEX. In other words, they are
419 // also built with the SDKs specified here.
420 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800421}
422
423type apexTargetBundleProperties struct {
424 Target struct {
425 // Multilib properties only for android.
426 Android struct {
427 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900428 }
Jooyung Han344d5432019-08-23 11:17:39 +0900429
Alex Light9670d332019-01-29 18:07:33 -0800430 // Multilib properties only for host.
431 Host struct {
432 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900433 }
Jooyung Han344d5432019-08-23 11:17:39 +0900434
Alex Light9670d332019-01-29 18:07:33 -0800435 // Multilib properties only for host linux_bionic.
436 Linux_bionic struct {
437 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900438 }
Jooyung Han344d5432019-08-23 11:17:39 +0900439
Alex Light9670d332019-01-29 18:07:33 -0800440 // Multilib properties only for host linux_glibc.
441 Linux_glibc struct {
442 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900443 }
444 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900445}
446
Jooyung Han344d5432019-08-23 11:17:39 +0900447type apexVndkProperties struct {
448 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
449 Vndk_version *string
450}
451
Jiyong Park8fd61922018-11-08 02:50:25 +0900452type apexFileClass int
453
454const (
455 etc apexFileClass = iota
456 nativeSharedLib
457 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900458 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800459 pyBinary
460 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900461 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100462 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900463 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900464)
465
Alex Light5098a612018-11-29 17:12:15 -0800466type apexPackaging int
467
468const (
469 imageApex apexPackaging = iota
470 zipApex
471 both
472)
473
474func (a apexPackaging) image() bool {
475 switch a {
476 case imageApex, both:
477 return true
478 }
479 return false
480}
481
482func (a apexPackaging) zip() bool {
483 switch a {
484 case zipApex, both:
485 return true
486 }
487 return false
488}
489
490func (a apexPackaging) suffix() string {
491 switch a {
492 case imageApex:
493 return imageApexSuffix
494 case zipApex:
495 return zipApexSuffix
496 case both:
497 panic(fmt.Errorf("must be either zip or image"))
498 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100499 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800500 }
501}
502
503func (a apexPackaging) name() string {
504 switch a {
505 case imageApex:
506 return imageApexType
507 case zipApex:
508 return zipApexType
509 case both:
510 panic(fmt.Errorf("must be either zip or image"))
511 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100512 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800513 }
514}
515
Jiyong Park8fd61922018-11-08 02:50:25 +0900516func (class apexFileClass) NameInMake() string {
517 switch class {
518 case etc:
519 return "ETC"
520 case nativeSharedLib:
521 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800522 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900523 return "EXECUTABLES"
524 case javaSharedLib:
525 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100526 case nativeTest:
527 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900528 case app:
529 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900530 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100531 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900532 }
533}
534
535type apexFile struct {
536 builtFile android.Path
537 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900538 installDir string
539 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900540 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800541 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900542}
543
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900544type apexBundle struct {
545 android.ModuleBase
546 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900547 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900548
Alex Light9670d332019-01-29 18:07:33 -0800549 properties apexBundleProperties
550 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900551 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900552
Alex Light5098a612018-11-29 17:12:15 -0800553 apexTypes apexPackaging
554
Colin Crossa4925902018-11-16 11:36:28 -0800555 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800556 outputFiles map[apexPackaging]android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700557 flattenedOutput android.InstallPath
558 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900559
Jiyong Park03b68dd2019-07-26 23:20:40 +0900560 prebuiltFileToDelete string
561
Jiyong Park42cca6c2019-04-01 11:15:50 +0900562 public_key_file android.Path
563 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900564
565 container_certificate_file android.Path
566 container_private_key_file android.Path
567
Jiyong Park8fd61922018-11-08 02:50:25 +0900568 // list of files to be included in this apex
569 filesInfo []apexFile
570
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900571 // list of module names that this APEX is depending on
572 externalDeps []string
573
Alex Light0851b882019-02-07 13:20:53 -0800574 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900575 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900576
577 // intermediate path for apex_manifest.json
578 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900579}
580
Jiyong Park397e55e2018-10-24 21:09:55 +0900581func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100582 native_shared_libs []string, binaries []string, tests []string,
583 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900584 // Use *FarVariation* to be able to depend on modules having
585 // conflicting variations with this module. This is required since
586 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
587 // for native shared libs.
588 ctx.AddFarVariationDependencies([]blueprint.Variation{
589 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900590 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900591 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900592 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900593 }, sharedLibTag, native_shared_libs...)
594
595 ctx.AddFarVariationDependencies([]blueprint.Variation{
596 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900597 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900598 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100599
600 ctx.AddFarVariationDependencies([]blueprint.Variation{
601 {Mutator: "arch", Variation: arch},
602 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100603 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100604 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900605}
606
Alex Light9670d332019-01-29 18:07:33 -0800607func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
608 if ctx.Os().Class == android.Device {
609 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
610 } else {
611 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
612 if ctx.Os().Bionic() {
613 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
614 } else {
615 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
616 }
617 }
618}
619
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900620func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800621
Jiyong Park397e55e2018-10-24 21:09:55 +0900622 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900623 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800624
625 a.combineProperties(ctx)
626
Jiyong Park397e55e2018-10-24 21:09:55 +0900627 has32BitTarget := false
628 for _, target := range targets {
629 if target.Arch.ArchType.Multilib == "lib32" {
630 has32BitTarget = true
631 }
632 }
633 for i, target := range targets {
634 // When multilib.* is omitted for native_shared_libs, it implies
635 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900636 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900637 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900638 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900639 {Mutator: "link", Variation: "shared"},
640 }, sharedLibTag, a.properties.Native_shared_libs...)
641
Roland Levillain630846d2019-06-26 12:48:34 +0100642 // When multilib.* is omitted for tests, it implies
643 // multilib.both.
644 ctx.AddFarVariationDependencies([]blueprint.Variation{
645 {Mutator: "arch", Variation: target.String()},
646 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100647 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100648 }, testTag, a.properties.Tests...)
649
Jiyong Park397e55e2018-10-24 21:09:55 +0900650 // Add native modules targetting both ABIs
651 addDependenciesForNativeModules(ctx,
652 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100653 a.properties.Multilib.Both.Binaries,
654 a.properties.Multilib.Both.Tests,
655 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900656 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900657
Alex Light3d673592019-01-18 14:37:31 -0800658 isPrimaryAbi := i == 0
659 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900660 // When multilib.* is omitted for binaries, it implies
661 // multilib.first.
662 ctx.AddFarVariationDependencies([]blueprint.Variation{
663 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900664 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900665 }, executableTag, a.properties.Binaries...)
666
667 // Add native modules targetting the first ABI
668 addDependenciesForNativeModules(ctx,
669 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100670 a.properties.Multilib.First.Binaries,
671 a.properties.Multilib.First.Tests,
672 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900673 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800674
675 // When multilib.* is omitted for prebuilts, it implies multilib.first.
676 ctx.AddFarVariationDependencies([]blueprint.Variation{
677 {Mutator: "arch", Variation: target.String()},
678 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900679 }
680
681 switch target.Arch.ArchType.Multilib {
682 case "lib32":
683 // Add native modules targetting 32-bit ABI
684 addDependenciesForNativeModules(ctx,
685 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100686 a.properties.Multilib.Lib32.Binaries,
687 a.properties.Multilib.Lib32.Tests,
688 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900689 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900690
691 addDependenciesForNativeModules(ctx,
692 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100693 a.properties.Multilib.Prefer32.Binaries,
694 a.properties.Multilib.Prefer32.Tests,
695 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900696 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900697 case "lib64":
698 // Add native modules targetting 64-bit ABI
699 addDependenciesForNativeModules(ctx,
700 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100701 a.properties.Multilib.Lib64.Binaries,
702 a.properties.Multilib.Lib64.Tests,
703 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900704 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900705
706 if !has32BitTarget {
707 addDependenciesForNativeModules(ctx,
708 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100709 a.properties.Multilib.Prefer32.Binaries,
710 a.properties.Multilib.Prefer32.Tests,
711 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900712 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900713 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700714
715 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
716 for _, sanitizer := range ctx.Config().SanitizeDevice() {
717 if sanitizer == "hwaddress" {
718 addDependenciesForNativeModules(ctx,
719 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100720 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700721 break
722 }
723 }
724 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900725 }
726
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900727 }
728
Jiyong Parkff1458f2018-10-12 21:49:38 +0900729 ctx.AddFarVariationDependencies([]blueprint.Variation{
730 {Mutator: "arch", Variation: "android_common"},
731 }, javaLibTag, a.properties.Java_libs...)
732
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900733 ctx.AddFarVariationDependencies([]blueprint.Variation{
734 {Mutator: "arch", Variation: "android_common"},
735 }, androidAppTag, a.properties.Apps...)
736
Jiyong Park23c52b02019-02-02 13:13:47 +0900737 if String(a.properties.Key) == "" {
738 ctx.ModuleErrorf("key is missing")
739 return
740 }
741 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900742
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900743 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900744 if cert != "" {
745 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900746 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900747
748 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
749 if len(a.properties.Uses_sdks) > 0 {
750 sdkRefs := []android.SdkRef{}
751 for _, str := range a.properties.Uses_sdks {
752 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
753 sdkRefs = append(sdkRefs, parsed)
754 }
755 a.BuildWithSdks(sdkRefs)
756 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900757}
758
Colin Cross0ea8ba82019-06-06 14:33:29 -0700759func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900760 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
761 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000762 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900763 }
764 return String(a.properties.Certificate)
765}
766
Colin Cross41955e82019-05-29 14:40:35 -0700767func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
768 switch tag {
769 case "":
770 if file, ok := a.outputFiles[imageApex]; ok {
771 return android.Paths{file}, nil
772 } else {
773 return nil, nil
774 }
Roland Levillain935639d2019-08-13 14:55:28 +0100775 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900776 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100777 flattenedApexPath := a.flattenedOutput
778 return android.Paths{flattenedApexPath}, nil
779 } else {
780 return nil, nil
781 }
Colin Cross41955e82019-05-29 14:40:35 -0700782 default:
783 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900784 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900785}
786
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900787func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900788 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900789}
790
Jiyong Park7c1dc612019-01-05 11:15:24 +0900791func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
792 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900793 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900794 } else {
795 return "core"
796 }
797}
798
Jiyong Parkf97782b2019-02-13 20:28:58 +0900799func (a *apexBundle) EnableSanitizer(sanitizerName string) {
800 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
801 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
802 }
803}
804
Jiyong Park388ef3f2019-01-28 19:47:32 +0900805func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900806 if android.InList(sanitizerName, a.properties.SanitizerNames) {
807 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900808 }
809
810 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900811 globalSanitizerNames := []string{}
812 if a.Host() {
813 globalSanitizerNames = ctx.Config().SanitizeHost()
814 } else {
815 arches := ctx.Config().SanitizeDeviceArch()
816 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
817 globalSanitizerNames = ctx.Config().SanitizeDevice()
818 }
819 }
820 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900821}
822
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900823func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
824 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
825}
826
827func (a *apexBundle) PreventInstall() {
828 a.properties.PreventInstall = true
829}
830
831func (a *apexBundle) HideFromMake() {
832 a.properties.HideFromMake = true
833}
834
Sundong Ahne9b55722019-09-06 17:37:42 +0900835func (a *apexBundle) SetFlattened(flattened bool) {
836 a.properties.Flattened = flattened
837}
838
Sundong Ahne8fb7242019-09-17 13:50:45 +0900839func (a *apexBundle) SetFlattenedConfigValue() {
840 a.properties.FlattenedConfigValue = true
841}
842
843// isFlattenedVariant returns true when the current module is the flattened
844// variant of an apex that has both a flattened and an unflattened variant.
845// It returns false when the current module is flattened but there is no
846// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
847// true. It can be used to avoid collisions between the install paths of the
848// flattened and unflattened variants.
849func (a *apexBundle) isFlattenedVariant() bool {
850 return a.properties.Flattened && !a.properties.FlattenedConfigValue
851}
852
Martin Stjernholm279de572019-09-10 23:18:20 +0100853func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900854 // Decide the APEX-local directory by the multilib of the library
855 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100856 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900857 case "lib32":
858 dirInApex = "lib"
859 case "lib64":
860 dirInApex = "lib64"
861 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100862 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700863 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100864 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900865 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100866 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
867 // Special case for Bionic libs and other libs installed with them. This is
868 // to prevent those libs from being included in the search path
869 // /apex/com.android.runtime/${LIB}. This exclusion is required because
870 // those libs in the Runtime APEX are available via the legacy paths in
871 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
872 // to the legacy paths and thus will be loaded into the default linker
873 // namespace (aka "platform" namespace). If the libs are directly in
874 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
875 // into the runtime linker namespace, which will result in double loading of
876 // them, which isn't supported.
877 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900878 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900879
Martin Stjernholm279de572019-09-10 23:18:20 +0100880 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900881 return
882}
883
884func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900885 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700886 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200887 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900888 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900889 fileToCopy = cc.OutputFile().Path()
890 return
891}
892
Alex Light778127a2019-02-27 14:19:50 -0800893func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
894 dirInApex = "bin"
895 fileToCopy = py.HostToolPath().Path()
896 return
897}
898func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
899 dirInApex = "bin"
900 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
901 if err != nil {
902 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
903 return
904 }
905 fileToCopy = android.PathForOutput(ctx, s)
906 return
907}
908
Jiyong Park04480cf2019-02-06 00:16:29 +0900909func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
910 dirInApex = filepath.Join("bin", sh.SubDir())
911 fileToCopy = sh.OutputFile()
912 return
913}
914
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900915func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
916 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900917 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900918 return
919}
920
Jiyong Park9e6c2422019-08-09 20:39:45 +0900921func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
922 dirInApex = "javalib"
923 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
924 implJars := java.ImplementationJars()
925 if len(implJars) != 1 {
926 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
927 strings.Join(implJars.Strings(), ", ")))
928 }
929 fileToCopy = implJars[0]
930 return
931}
932
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900933func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
934 dirInApex = filepath.Join("etc", prebuilt.SubDir())
935 fileToCopy = prebuilt.OutputFile()
936 return
937}
938
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900939func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
940 dirInApex = filepath.Join("app", pkgName)
941 fileToCopy = app.OutputFile()
942 return
943}
944
Roland Levillain935639d2019-08-13 14:55:28 +0100945// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
946type flattenedApexContext struct {
947 android.ModuleContext
948}
949
950func (c *flattenedApexContext) InstallBypassMake() bool {
951 return true
952}
953
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900954func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900955 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900956
Alex Light5098a612018-11-29 17:12:15 -0800957 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
958 a.apexTypes = imageApex
959 } else if *a.properties.Payload_type == "zip" {
960 a.apexTypes = zipApex
961 } else if *a.properties.Payload_type == "both" {
962 a.apexTypes = both
963 } else {
964 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
965 return
966 }
967
Roland Levillain630846d2019-06-26 12:48:34 +0100968 if len(a.properties.Tests) > 0 && !a.testApex {
969 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
970 return
971 }
972
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800973 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
974
Jooyung Hane1633032019-08-01 17:41:43 +0900975 // native lib dependencies
976 var provideNativeLibs []string
977 var requireNativeLibs []string
978
Jooyung Han5c998b92019-06-27 11:30:33 +0900979 // Check if "uses" requirements are met with dependent apexBundles
980 var providedNativeSharedLibs []string
981 useVendor := proptools.Bool(a.properties.Use_vendor)
982 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
983 if ctx.OtherModuleDependencyTag(m) != usesTag {
984 return
985 }
986 otherName := ctx.OtherModuleName(m)
987 other, ok := m.(*apexBundle)
988 if !ok {
989 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
990 return
991 }
992 if proptools.Bool(other.properties.Use_vendor) != useVendor {
993 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
994 return
995 }
996 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
997 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
998 return
999 }
1000 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1001 })
1002
Alex Light778127a2019-02-27 14:19:50 -08001003 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001004 depTag := ctx.OtherModuleDependencyTag(child)
1005 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001006 if _, ok := parent.(*apexBundle); ok {
1007 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001008 switch depTag {
1009 case sharedLibTag:
1010 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001011 if cc.HasStubsVariants() {
1012 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1013 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001014 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001015 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001017 } else {
1018 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001019 }
1020 case executableTag:
1021 if cc, ok := child.(*cc.Module); ok {
1022 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001023 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001024 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001025 } else if sh, ok := child.(*android.ShBinary); ok {
1026 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -07001027 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
Alex Light778127a2019-02-27 14:19:50 -08001028 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1029 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1030 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1031 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1032 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1033 // NB: Since go binaries are static we don't need the module for anything here, which is
1034 // good since the go tool is a blueprint.Module not an android.Module like we would
1035 // normally use.
1036 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001037 } else {
Alex Light778127a2019-02-27 14:19:50 -08001038 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 +09001039 }
1040 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001041 if javaLib, ok := child.(*java.Library); ok {
1042 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001043 if fileToCopy == nil {
1044 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1045 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001046 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1047 }
1048 return true
1049 } else if javaLib, ok := child.(*java.Import); ok {
1050 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1051 if fileToCopy == nil {
1052 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1053 } else {
1054 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001055 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001057 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001058 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001059 }
1060 case prebuiltTag:
1061 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1062 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001063 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001064 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001065 } else {
1066 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1067 }
Roland Levillain630846d2019-06-26 12:48:34 +01001068 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001069 if ccTest, ok := child.(*cc.Module); ok {
1070 if ccTest.IsTestPerSrcAllTestsVariation() {
1071 // Multiple-output test module (where `test_per_src: true`).
1072 //
1073 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1074 // We do not add this variation to `filesInfo`, as it has no output;
1075 // however, we do add the other variations of this module as indirect
1076 // dependencies (see below).
1077 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001078 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001079 // Single-output test module (where `test_per_src: false`).
1080 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1081 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001082 }
Roland Levillain630846d2019-06-26 12:48:34 +01001083 return true
1084 } else {
1085 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1086 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001087 case keyTag:
1088 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001089 a.private_key_file = key.private_key_file
1090 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001091 return false
1092 } else {
1093 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001094 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001095 case certificateTag:
1096 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001097 a.container_certificate_file = dep.Certificate.Pem
1098 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001099 return false
1100 } else {
1101 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1102 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001103 case android.PrebuiltDepTag:
1104 // If the prebuilt is force disabled, remember to delete the prebuilt file
1105 // that might have been installed in the previous builds
1106 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1107 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1108 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001109 case androidAppTag:
1110 if ap, ok := child.(*java.AndroidApp); ok {
1111 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1112 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1113 return true
1114 } else {
1115 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1116 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001117 }
1118 } else {
1119 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001120 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001121 // We cannot use a switch statement on `depTag` here as the checked
1122 // tags used below are private (e.g. `cc.sharedDepTag`).
1123 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1124 if cc, ok := child.(*cc.Module); ok {
1125 if android.InList(cc.Name(), providedNativeSharedLibs) {
1126 // If we're using a shared library which is provided from other APEX,
1127 // don't include it in this APEX
1128 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001129 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001130 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1131 // If the dependency is a stubs lib, don't include it in this APEX,
1132 // but make sure that the lib is installed on the device.
1133 // In case no APEX is having the lib, the lib is installed to the system
1134 // partition.
1135 //
1136 // Always include if we are a host-apex however since those won't have any
1137 // system libraries.
1138 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1139 a.externalDeps = append(a.externalDeps, cc.Name())
1140 }
Jooyung Hane1633032019-08-01 17:41:43 +09001141 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001142 // Don't track further
1143 return false
1144 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001145 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001146 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1147 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001148 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001149 } else if cc.IsTestPerSrcDepTag(depTag) {
1150 if cc, ok := child.(*cc.Module); ok {
1151 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1152 // Handle modules created as `test_per_src` variations of a single test module:
1153 // use the name of the generated test binary (`fileToCopy`) instead of the name
1154 // of the original test module (`depName`, shared by all `test_per_src`
1155 // variations of that module).
1156 moduleName := filepath.Base(fileToCopy.String())
1157 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1158 return true
1159 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001160 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001161 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001162 }
1163 }
1164 }
1165 return false
1166 })
1167
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001168 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001169 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1170 return
1171 }
1172
Jiyong Park8fd61922018-11-08 02:50:25 +09001173 // remove duplicates in filesInfo
1174 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001175 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001176 result := []apexFile{}
1177 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001178 dest := filepath.Join(f.installDir, f.builtFile.Base())
1179 if !encountered[dest] {
1180 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001181 result = append(result, f)
1182 }
1183 }
1184 return result
1185 }
1186 filesInfo = removeDup(filesInfo)
1187
1188 // to have consistent build rules
1189 sort.Slice(filesInfo, func(i, j int) bool {
1190 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1191 })
1192
Jiyong Park127b40b2019-09-30 16:04:35 +09001193 // check apex_available requirements
Jiyong Park583a2262019-10-08 20:55:38 +09001194 if !ctx.Host() {
1195 for _, fi := range filesInfo {
1196 if am, ok := fi.module.(android.ApexModule); ok {
1197 if !am.AvailableFor(ctx.ModuleName()) {
1198 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
1199 return
1200 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001201 }
1202 }
1203 }
1204
Jiyong Park8fd61922018-11-08 02:50:25 +09001205 // prepend the name of this APEX to the module names. These names will be the names of
1206 // modules that will be defined if the APEX is flattened.
1207 for i := range filesInfo {
1208 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
1209 }
1210
Jiyong Park8fd61922018-11-08 02:50:25 +09001211 a.installDir = android.PathForModuleInstall(ctx, "apex")
1212 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001213
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001214 // prepare apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001215 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
Jooyung Hane1633032019-08-01 17:41:43 +09001216 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001217
1218 // put dependency({provide|require}NativeLibs) in apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001219 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1220 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001221
1222 // apex name can be overridden
1223 optCommands := []string{}
1224 if a.properties.Apex_name != nil {
1225 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
1226 }
1227
Jooyung Hane1633032019-08-01 17:41:43 +09001228 ctx.Build(pctx, android.BuildParams{
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001229 Rule: apexManifestRule,
Jooyung Hane1633032019-08-01 17:41:43 +09001230 Input: manifestSrc,
1231 Output: a.manifestOut,
1232 Args: map[string]string{
1233 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1234 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001235 "opt": strings.Join(optCommands, " "),
Jooyung Hane1633032019-08-01 17:41:43 +09001236 },
1237 })
1238
Roland Levillain935639d2019-08-13 14:55:28 +01001239 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1240 // reply true to `InstallBypassMake()` (thus making the call
1241 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1242 // instead of `android.PathForOutput`) to return the correct path to the flattened
1243 // APEX (as its contents is installed by Make, not Soong).
1244 factx := flattenedApexContext{ctx}
1245 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
1246
Alex Light5098a612018-11-29 17:12:15 -08001247 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001248 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001249 }
1250 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001251 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001252 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001253 // in other modules. It is in AndroidMk where the selection of flattened
1254 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001255 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001256 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001257 }
1258}
1259
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001260func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001261 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001262 for _, f := range a.filesInfo {
1263 if f.module != nil {
1264 notice := f.module.NoticeFile()
1265 if notice.Valid() {
1266 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001267 }
1268 }
1269 }
1270 // append the notice file specified in the apex module itself
1271 if a.NoticeFile().Valid() {
1272 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001273 }
1274
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001275 if len(noticeFiles) == 0 {
1276 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001277 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001278
Jaewoong Jung98772792019-07-01 17:15:13 -07001279 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001280}
1281
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001282func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001283 cert := String(a.properties.Certificate)
1284 if cert != "" && android.SrcIsModule(cert) == "" {
1285 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001286 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1287 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001288 } else if cert == "" {
1289 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001290 a.container_certificate_file = pem
1291 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001292 }
1293
Alex Light5098a612018-11-29 17:12:15 -08001294 var abis []string
1295 for _, target := range ctx.MultiTargets() {
1296 if len(target.Arch.Abi) > 0 {
1297 abis = append(abis, target.Arch.Abi[0])
1298 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001299 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001300
Alex Light5098a612018-11-29 17:12:15 -08001301 abis = android.FirstUniqueStrings(abis)
1302
1303 suffix := apexType.suffix()
1304 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001305
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001306 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001307 for _, f := range a.filesInfo {
1308 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001309 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001310
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001311 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001312 emitCommands := []string{}
1313 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1314 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001315 for i, src := range filesToCopy {
1316 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001317 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001318 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001319 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1320 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001321 for _, sym := range a.filesInfo[i].symlinks {
1322 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1323 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1324 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001325 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001326 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001327 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001328
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001329 if a.properties.Whitelisted_files != nil {
1330 ctx.Build(pctx, android.BuildParams{
1331 Rule: emitApexContentRule,
1332 Implicits: implicitInputs,
1333 Output: imageContentFile,
1334 Description: "emit apex image content",
1335 Args: map[string]string{
1336 "emit_commands": strings.Join(emitCommands, " && "),
1337 },
1338 })
1339 implicitInputs = append(implicitInputs, imageContentFile)
1340 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1341
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001342 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001343 ctx.Build(pctx, android.BuildParams{
1344 Rule: diffApexContentRule,
1345 Implicits: implicitInputs,
1346 Output: phonyOutput,
1347 Description: "diff apex image content",
1348 Args: map[string]string{
1349 "whitelisted_files_file": whitelistedFilesFile.String(),
1350 "image_content_file": imageContentFile.String(),
1351 "apex_module_name": ctx.ModuleName(),
1352 },
1353 })
1354
1355 implicitInputs = append(implicitInputs, phonyOutput)
1356 }
1357
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001358 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1359 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001360
Alex Light5098a612018-11-29 17:12:15 -08001361 if apexType.image() {
1362 // files and dirs that will be created in APEX
1363 var readOnlyPaths []string
1364 var executablePaths []string // this also includes dirs
1365 for _, f := range a.filesInfo {
1366 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001367 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001368 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001369 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001370 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001371 }
Alex Light5098a612018-11-29 17:12:15 -08001372 } else {
1373 readOnlyPaths = append(readOnlyPaths, pathInApex)
1374 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001375 dir := f.installDir
1376 for !android.InList(dir, executablePaths) && dir != "" {
1377 executablePaths = append(executablePaths, dir)
1378 dir, _ = filepath.Split(dir) // move up to the parent
1379 if len(dir) > 0 {
1380 // remove trailing slash
1381 dir = dir[:len(dir)-1]
1382 }
Alex Light5098a612018-11-29 17:12:15 -08001383 }
1384 }
1385 sort.Strings(readOnlyPaths)
1386 sort.Strings(executablePaths)
1387 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1388 ctx.Build(pctx, android.BuildParams{
1389 Rule: generateFsConfig,
1390 Output: cannedFsConfig,
1391 Description: "generate fs config",
1392 Args: map[string]string{
1393 "ro_paths": strings.Join(readOnlyPaths, " "),
1394 "exec_paths": strings.Join(executablePaths, " "),
1395 },
1396 })
1397
1398 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1399 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1400 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1401 if !fileContextsOptionalPath.Valid() {
1402 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1403 return
1404 }
1405 fileContexts := fileContextsOptionalPath.Path()
1406
Jiyong Park835d82b2018-12-27 16:04:18 +09001407 optFlags := []string{}
1408
Alex Light5098a612018-11-29 17:12:15 -08001409 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001410 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1411 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001412
Jiyong Park7f67f482019-01-05 12:57:48 +09001413 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1414 if overridden {
1415 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1416 }
1417
Jiyong Park40e26a22019-02-08 02:53:06 +09001418 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001419 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001420 implicitInputs = append(implicitInputs, androidManifestFile)
1421 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1422 }
1423
Jiyong Park71b519d2019-04-18 17:25:49 +09001424 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1425 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1426 ctx.Config().UnbundledBuild() &&
1427 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1428 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1429 apiFingerprint := java.ApiFingerprintPath(ctx)
1430 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1431 implicitInputs = append(implicitInputs, apiFingerprint)
1432 }
1433 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1434
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001435 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1436 if noticeFile.Valid() {
1437 // If there's a NOTICE file, embed it as an asset file in the APEX.
1438 implicitInputs = append(implicitInputs, noticeFile.Path())
1439 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1440 }
1441
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001442 if !ctx.Config().UnbundledBuild() && a.installable() {
1443 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1444 // don't need hashtree for activation. Therefore, by removing hashtree from
1445 // apex bundle (filesystem image in it, to be specific), we can save storage.
1446 optFlags = append(optFlags, "--no_hashtree")
1447 }
1448
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001449 if a.properties.Apex_name != nil {
1450 // If apex_name is set, apexer can skip checking if key name matches with apex name.
1451 // Note that apex_manifest is also mended.
1452 optFlags = append(optFlags, "--do_not_check_keyname")
1453 }
1454
Alex Light5098a612018-11-29 17:12:15 -08001455 ctx.Build(pctx, android.BuildParams{
1456 Rule: apexRule,
1457 Implicits: implicitInputs,
1458 Output: unsignedOutputFile,
1459 Description: "apex (" + apexType.name() + ")",
1460 Args: map[string]string{
1461 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1462 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1463 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001464 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001465 "file_contexts": fileContexts.String(),
1466 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001467 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001468 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001469 },
1470 })
1471
1472 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1473 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1474 a.bundleModuleFile = bundleModuleFile
1475
1476 ctx.Build(pctx, android.BuildParams{
1477 Rule: apexProtoConvertRule,
1478 Input: unsignedOutputFile,
1479 Output: apexProtoFile,
1480 Description: "apex proto convert",
1481 })
1482
1483 ctx.Build(pctx, android.BuildParams{
1484 Rule: apexBundleRule,
1485 Input: apexProtoFile,
1486 Output: a.bundleModuleFile,
1487 Description: "apex bundle module",
1488 Args: map[string]string{
1489 "abi": strings.Join(abis, "."),
1490 },
1491 })
1492 } else {
1493 ctx.Build(pctx, android.BuildParams{
1494 Rule: zipApexRule,
1495 Implicits: implicitInputs,
1496 Output: unsignedOutputFile,
1497 Description: "apex (" + apexType.name() + ")",
1498 Args: map[string]string{
1499 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1500 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1501 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001502 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001503 },
1504 })
Colin Crossa4925902018-11-16 11:36:28 -08001505 }
Colin Crossa4925902018-11-16 11:36:28 -08001506
Alex Light5098a612018-11-29 17:12:15 -08001507 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001508 ctx.Build(pctx, android.BuildParams{
1509 Rule: java.Signapk,
1510 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001511 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001512 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001513 Implicits: []android.Path{
1514 a.container_certificate_file,
1515 a.container_private_key_file,
1516 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001517 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001518 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001519 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001520 },
1521 })
Alex Light5098a612018-11-29 17:12:15 -08001522
1523 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001524 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001525 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001526 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001527}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001528
Jiyong Park8fd61922018-11-08 02:50:25 +09001529func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001530 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001531 // 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 +09001532 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001533 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001534
Jiyong Park42cca6c2019-04-01 11:15:50 +09001535 // rename to apex_pubkey
1536 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1537 ctx.Build(pctx, android.BuildParams{
1538 Rule: android.Cp,
1539 Input: a.public_key_file,
1540 Output: copiedPubkey,
1541 })
1542 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1543
Jiyong Park23c52b02019-02-02 13:13:47 +09001544 if ctx.Config().FlattenApex() {
1545 for _, fi := range a.filesInfo {
1546 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001547 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1548 for _, sym := range fi.symlinks {
1549 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1550 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001551 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001552 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001553 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001554}
1555
1556func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001557 if a.properties.HideFromMake {
1558 return android.AndroidMkData{
1559 Disabled: true,
1560 }
1561 }
Alex Light5098a612018-11-29 17:12:15 -08001562 writers := []android.AndroidMkData{}
1563 if a.apexTypes.image() {
1564 writers = append(writers, a.androidMkForType(imageApex))
1565 }
1566 if a.apexTypes.zip() {
1567 writers = append(writers, a.androidMkForType(zipApex))
1568 }
1569 return android.AndroidMkData{
1570 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1571 for _, data := range writers {
1572 data.Custom(w, name, prefix, moduleDir, data)
1573 }
1574 }}
1575}
1576
Alex Lightf1801bc2019-02-13 11:10:07 -08001577func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001578 moduleNames := []string{}
1579
1580 for _, fi := range a.filesInfo {
1581 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1582 continue
1583 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001584 if a.properties.Flattened && !apexType.image() {
1585 continue
Jiyong Park94427262019-02-05 23:18:47 +09001586 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001587
1588 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001589 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001590 suffix = ".flattened"
1591 }
1592
1593 if !android.InList(fi.moduleName, moduleNames) {
1594 moduleNames = append(moduleNames, fi.moduleName+suffix)
1595 }
1596
Jiyong Park94427262019-02-05 23:18:47 +09001597 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1598 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001599 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001600 // /apex/<apex_name>/{lib|framework|...}
Jiyong Park05e70dd2019-03-18 14:26:32 +09001601 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1602 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001603 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001604 // /system/apex/<name>/{lib|framework|...}
Colin Crossff6c33d2019-10-02 16:01:35 -07001605 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
1606 name, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001607 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001608 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1609 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001610 if len(fi.symlinks) > 0 {
1611 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1612 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001613
1614 if fi.module != nil && fi.module.NoticeFile().Valid() {
1615 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1616 }
Jiyong Park94427262019-02-05 23:18:47 +09001617 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001618 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001619 }
1620 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1621 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1622 if fi.module != nil {
1623 archStr := fi.module.Target().Arch.ArchType.String()
1624 host := false
1625 switch fi.module.Target().Os.Class {
1626 case android.Host:
1627 if archStr != "common" {
1628 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1629 }
1630 host = true
1631 case android.HostCross:
1632 if archStr != "common" {
1633 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1634 }
1635 host = true
1636 case android.Device:
1637 if archStr != "common" {
1638 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1639 }
1640 }
1641 if host {
1642 makeOs := fi.module.Target().Os.String()
1643 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1644 makeOs = "linux"
1645 }
1646 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1647 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1648 }
1649 }
1650 if fi.class == javaSharedLib {
1651 javaModule := fi.module.(*java.Library)
1652 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1653 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1654 // we will have foo.jar.jar
1655 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1656 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1657 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1658 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1659 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1660 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001661 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001662 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001663 if cc, ok := fi.module.(*cc.Module); ok {
1664 if cc.UnstrippedOutputFile() != nil {
1665 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1666 }
1667 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001668 if cc.CoverageOutputFile().Valid() {
1669 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1670 }
Jiyong Park94427262019-02-05 23:18:47 +09001671 }
1672 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1673 } else {
1674 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1675 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1676 }
1677 }
1678 return moduleNames
1679}
1680
Alex Light5098a612018-11-29 17:12:15 -08001681func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001682 return android.AndroidMkData{
1683 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1684 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001685 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001686 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001687 }
1688
Sundong Ahne8fb7242019-09-17 13:50:45 +09001689 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001690 name = name + ".flattened"
1691 }
1692
1693 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001694 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001695 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1696 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1697 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001698 if len(moduleNames) > 0 {
1699 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1700 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001701 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001702 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1703
Sundong Ahne8fb7242019-09-17 13:50:45 +09001704 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001705 // zip-apex is the less common type so have the name refer to the image-apex
1706 // only and use {name}.zip if you want the zip-apex
1707 if apexType == zipApex && a.apexTypes == both {
1708 name = name + ".zip"
1709 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001710 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1711 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1712 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1713 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001714 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Colin Crossff6c33d2019-10-02 16:01:35 -07001715 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
Colin Cross189ff982019-01-02 22:32:27 -08001716 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001717 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001718 if len(moduleNames) > 0 {
1719 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1720 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001721 if len(a.externalDeps) > 0 {
1722 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1723 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001724 if a.prebuiltFileToDelete != "" {
1725 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
Colin Crossff6c33d2019-10-02 16:01:35 -07001726 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
Jiyong Park03b68dd2019-07-26 23:20:40 +09001727 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001728 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001729
Alex Light5098a612018-11-29 17:12:15 -08001730 if apexType == imageApex {
1731 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1732 }
Jiyong Park719b4462019-01-13 00:39:51 +09001733 }
1734 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001735}
1736
Jooyung Han344d5432019-08-23 11:17:39 +09001737func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001738 module := &apexBundle{
1739 outputFiles: map[apexPackaging]android.WritablePath{},
1740 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001741 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001742 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001743 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001744 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1745 })
Alex Light5098a612018-11-29 17:12:15 -08001746 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001747 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001748 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001749 return module
1750}
Jiyong Park30ca9372019-02-07 16:27:23 +09001751
Jooyung Han344d5432019-08-23 11:17:39 +09001752func ApexBundleFactory(testApex bool) android.Module {
1753 bundle := newApexBundle()
1754 bundle.testApex = testApex
1755 return bundle
1756}
1757
1758func testApexBundleFactory() android.Module {
1759 bundle := newApexBundle()
1760 bundle.testApex = true
1761 return bundle
1762}
1763
Jiyong Parkd1063c12019-07-17 20:08:41 +09001764func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001765 return newApexBundle()
1766}
1767
1768// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1769// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1770// If not specified, then the "current" versions are gathered.
1771func vndkApexBundleFactory() android.Module {
1772 bundle := newApexBundle()
1773 bundle.vndkApex = true
1774 bundle.AddProperties(&bundle.vndkProperties)
1775 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1776 ctx.AppendProperties(&struct {
1777 Compile_multilib *string
1778 }{
1779 proptools.StringPtr("both"),
1780 })
Jooyung Han90eee022019-10-01 20:02:42 +09001781
1782 vndkVersion := proptools.StringDefault(bundle.vndkProperties.Vndk_version, "current")
1783 if vndkVersion == "current" {
1784 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1785 bundle.vndkProperties.Vndk_version = proptools.StringPtr(vndkVersion)
1786 }
1787
1788 // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
1789 bundle.properties.Apex_name = proptools.StringPtr("com.android.vndk.v" + vndkVersion)
Jooyung Han344d5432019-08-23 11:17:39 +09001790 })
1791 return bundle
1792}
1793
Jiyong Park30ca9372019-02-07 16:27:23 +09001794//
1795// Defaults
1796//
1797type Defaults struct {
1798 android.ModuleBase
1799 android.DefaultsModuleBase
1800}
1801
Jiyong Park30ca9372019-02-07 16:27:23 +09001802func defaultsFactory() android.Module {
1803 return DefaultsFactory()
1804}
1805
1806func DefaultsFactory(props ...interface{}) android.Module {
1807 module := &Defaults{}
1808
1809 module.AddProperties(props...)
1810 module.AddProperties(
1811 &apexBundleProperties{},
1812 &apexTargetBundleProperties{},
1813 )
1814
1815 android.InitDefaultsModule(module)
1816 return module
1817}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001818
1819//
1820// Prebuilt APEX
1821//
1822type Prebuilt struct {
1823 android.ModuleBase
1824 prebuilt android.Prebuilt
1825
1826 properties PrebuiltProperties
1827
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001828 inputApex android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001829 installDir android.InstallPath
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001830 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001831 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001832}
1833
1834type PrebuiltProperties struct {
1835 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001836 Source string `blueprint:"mutated"`
1837 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001838
1839 Src *string
1840 Arch struct {
1841 Arm struct {
1842 Src *string
1843 }
1844 Arm64 struct {
1845 Src *string
1846 }
1847 X86 struct {
1848 Src *string
1849 }
1850 X86_64 struct {
1851 Src *string
1852 }
1853 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001854
1855 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001856 // Optional name for the installed apex. If unspecified, name of the
1857 // module is used as the file name
1858 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001859
1860 // Names of modules to be overridden. Listed modules can only be other binaries
1861 // (in Make or Soong).
1862 // This does not completely prevent installation of the overridden binaries, but if both
1863 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1864 // from PRODUCT_PACKAGES.
1865 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001866}
1867
1868func (p *Prebuilt) installable() bool {
1869 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001870}
1871
1872func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001873 // If the device is configured to use flattened APEX, force disable the prebuilt because
1874 // the prebuilt is a non-flattened one.
1875 forceDisable := ctx.Config().FlattenApex()
1876
1877 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1878 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001879 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001880
Kun Niu10c9f832019-07-29 16:28:57 -07001881 // Force disable the prebuilts when coverage is enabled.
1882 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1883 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1884
Jiyong Park50b81e52019-07-11 11:24:41 +09001885 // b/137216042 don't use prebuilts when address sanitizer is on
1886 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1887 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1888
1889 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001890 p.properties.ForceDisable = true
1891 return
1892 }
1893
Jiyong Parkc95714e2019-03-29 14:23:10 +09001894 // This is called before prebuilt_select and prebuilt_postdeps mutators
1895 // The mutators requires that src to be set correctly for each arch so that
1896 // arch variants are disabled when src is not provided for the arch.
1897 if len(ctx.MultiTargets()) != 1 {
1898 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1899 return
1900 }
1901 var src string
1902 switch ctx.MultiTargets()[0].Arch.ArchType {
1903 case android.Arm:
1904 src = String(p.properties.Arch.Arm.Src)
1905 case android.Arm64:
1906 src = String(p.properties.Arch.Arm64.Src)
1907 case android.X86:
1908 src = String(p.properties.Arch.X86.Src)
1909 case android.X86_64:
1910 src = String(p.properties.Arch.X86_64.Src)
1911 default:
1912 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1913 return
1914 }
1915 if src == "" {
1916 src = String(p.properties.Src)
1917 }
1918 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001919}
1920
Jiyong Park03b68dd2019-07-26 23:20:40 +09001921func (p *Prebuilt) isForceDisabled() bool {
1922 return p.properties.ForceDisable
1923}
1924
Colin Cross41955e82019-05-29 14:40:35 -07001925func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1926 switch tag {
1927 case "":
1928 return android.Paths{p.outputApex}, nil
1929 default:
1930 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1931 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001932}
1933
Jiyong Park4d277042019-04-23 18:00:10 +09001934func (p *Prebuilt) InstallFilename() string {
1935 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1936}
1937
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001938func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001939 if p.properties.ForceDisable {
1940 return
1941 }
1942
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001943 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001944 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001945 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001946 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001947 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1948 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1949 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001950 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1951 ctx.Build(pctx, android.BuildParams{
1952 Rule: android.Cp,
1953 Input: p.inputApex,
1954 Output: p.outputApex,
1955 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001956 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001957 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001958 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001959}
1960
1961func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1962 return &p.prebuilt
1963}
1964
1965func (p *Prebuilt) Name() string {
1966 return p.prebuilt.Name(p.ModuleBase.Name())
1967}
1968
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001969func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1970 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001971 Class: "ETC",
1972 OutputFile: android.OptionalPathForPath(p.inputApex),
1973 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001974 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1975 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -07001976 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001977 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1978 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1979 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
1980 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001981 },
1982 }
1983}
1984
1985// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1986func PrebuiltFactory() android.Module {
1987 module := &Prebuilt{}
1988 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001989 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001990 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001991 return module
1992}