blob: 8891094a73ae030fc7c6a72f605b7023432de7b9 [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
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900152var (
153 whitelistNoApex = map[string][]string{
154 "apex_test_build_features": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900155 "com.android.media": []string{"libbinder"},
156 "com.android.media.swcodec": []string{"libbinder"},
157 "test_com.android.media.swcodec": []string{"libbinder"},
Jooyung Han344d5432019-08-23 11:17:39 +0900158 "com.android.vndk": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900159 }
160)
161
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900162func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700163 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900164 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900165 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100166 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
167 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
168 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
169 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000170 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100171 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
172 } else {
173 return pctx.HostBinToolPath(ctx, tool).String()
174 }
175 })
176 }
177 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900178 pctx.HostBinToolVariable("avbtool", "avbtool")
179 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
180 pctx.HostBinToolVariable("merge_zips", "merge_zips")
181 pctx.HostBinToolVariable("mke2fs", "mke2fs")
182 pctx.HostBinToolVariable("resize2fs", "resize2fs")
183 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
184 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800185 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900186 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900187 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900188
Jiyong Parkd1063c12019-07-17 20:08:41 +0900189 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800190 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900191 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900192 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700193 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900194
Jooyung Han344d5432019-08-23 11:17:39 +0900195 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
196 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
197 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
198 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900199 android.PostDepsMutators(RegisterPostDepsMutators)
200}
201
202func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
203 ctx.TopDown("apex_deps", apexDepsMutator)
204 ctx.BottomUp("apex", apexMutator).Parallel()
205 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
206 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900207}
208
Jooyung Han344d5432019-08-23 11:17:39 +0900209var (
210 vndkApexListKey = android.NewOnceKey("vndkApexList")
211 vndkApexListMutex sync.Mutex
212)
213
214func vndkApexList(config android.Config) map[string]*apexBundle {
215 return config.Once(vndkApexListKey, func() interface{} {
216 return map[string]*apexBundle{}
217 }).(map[string]*apexBundle)
218}
219
220// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
221func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
222 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
223 if ab.IsNativeBridgeSupported() {
224 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
225 }
226 vndkVersion := proptools.StringDefault(ab.vndkProperties.Vndk_version, mctx.DeviceConfig().PlatformVndkVersion())
227 vndkApexListMutex.Lock()
228 defer vndkApexListMutex.Unlock()
229 vndkApexList := vndkApexList(mctx.Config())
230 if other, ok := vndkApexList[vndkVersion]; ok {
231 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.Name())
232 }
233 vndkApexList[vndkVersion] = ab
234 }
235}
236
237// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
238// It filters only libs with matching targets.
239func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
240 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
241 vndkApexList := vndkApexList(mctx.Config())
242 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
243 targetArch := cc.Target().String()
244 for _, target := range ab.MultiTargets() {
245 if target.String() == targetArch {
246 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
247 break
248 }
249 }
250 }
251 }
252}
253
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900254// Mark the direct and transitive dependencies of apex bundles so that they
255// can be built for the apex bundles.
256func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800257 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800258 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900259 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900260 depName := mctx.OtherModuleName(child)
261 // If the parent is apexBundle, this child is directly depended.
262 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800263 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800264 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
265 // non-installable apex's cannot be installed and so should not prevent libraries from being
266 // installed to the system.
267 android.UpdateApexDependency(apexBundleName, depName, directDep)
268 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900269
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900270 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900271 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900272 return true
273 } else {
274 return false
275 }
276 })
277 }
278}
279
280// Create apex variations if a module is included in APEX(s).
281func apexMutator(mctx android.BottomUpMutatorContext) {
282 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900283 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900284 } else if _, ok := mctx.Module().(*apexBundle); ok {
285 // apex bundle itself is mutated so that it and its modules have same
286 // apex variant.
287 apexBundleName := mctx.ModuleName()
288 mctx.CreateVariations(apexBundleName)
289 }
290}
Sundong Ahne9b55722019-09-06 17:37:42 +0900291
292func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900293 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900294 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
295 modules := mctx.CreateLocalVariations("", "flattened")
296 modules[0].(*apexBundle).SetFlattened(false)
297 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900298 } else {
299 ab.SetFlattened(true)
300 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900301 }
302 }
303}
304
Jooyung Han5c998b92019-06-27 11:30:33 +0900305func apexUsesMutator(mctx android.BottomUpMutatorContext) {
306 if ab, ok := mctx.Module().(*apexBundle); ok {
307 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
308 }
309}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900310
Alex Light9670d332019-01-29 18:07:33 -0800311type apexNativeDependencies struct {
312 // List of native libraries
313 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900314
Alex Light9670d332019-01-29 18:07:33 -0800315 // List of native executables
316 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900317
Roland Levillain630846d2019-06-26 12:48:34 +0100318 // List of native tests
319 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800320}
Jooyung Han344d5432019-08-23 11:17:39 +0900321
Alex Light9670d332019-01-29 18:07:33 -0800322type apexMultilibProperties struct {
323 // Native dependencies whose compile_multilib is "first"
324 First apexNativeDependencies
325
326 // Native dependencies whose compile_multilib is "both"
327 Both apexNativeDependencies
328
329 // Native dependencies whose compile_multilib is "prefer32"
330 Prefer32 apexNativeDependencies
331
332 // Native dependencies whose compile_multilib is "32"
333 Lib32 apexNativeDependencies
334
335 // Native dependencies whose compile_multilib is "64"
336 Lib64 apexNativeDependencies
337}
338
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900339type apexBundleProperties struct {
340 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000341 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800342 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900343
Jiyong Park40e26a22019-02-08 02:53:06 +0900344 // AndroidManifest.xml file used for the zip container of this APEX bundle.
345 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800346 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900347
Roland Levillain411c5842019-09-19 16:37:20 +0100348 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
349 // device (/apex/<apex_name>).
350 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900351 Apex_name *string
352
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900353 // Determines the file contexts file for setting security context to each file in this APEX bundle.
354 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
355 // used.
356 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900357 File_contexts *string
358
359 // List of native shared libs that are embedded inside this APEX bundle
360 Native_shared_libs []string
361
Roland Levillain630846d2019-06-26 12:48:34 +0100362 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900363 Binaries []string
364
365 // List of java libraries that are embedded inside this APEX bundle
366 Java_libs []string
367
368 // List of prebuilt files that are embedded inside this APEX bundle
369 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900370
Roland Levillain630846d2019-06-26 12:48:34 +0100371 // List of tests that are embedded inside this APEX bundle
372 Tests []string
373
Jiyong Parkff1458f2018-10-12 21:49:38 +0900374 // Name of the apex_key module that provides the private key to sign APEX
375 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900376
Alex Light5098a612018-11-29 17:12:15 -0800377 // The type of APEX to build. Controls what the APEX payload is. Either
378 // 'image', 'zip' or 'both'. Default: 'image'.
379 Payload_type *string
380
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900381 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
382 // or an android_app_certificate module name in the form ":module".
383 Certificate *string
384
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900385 // Whether this APEX is installable to one of the partitions. Default: true.
386 Installable *bool
387
Jiyong Parkda6eb592018-12-19 17:12:36 +0900388 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
389 // Default is false.
390 Use_vendor *bool
391
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800392 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
393 Ignore_system_library_special_case *bool
394
Alex Light9670d332019-01-29 18:07:33 -0800395 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900396
Jiyong Parkf97782b2019-02-13 20:28:58 +0900397 // List of sanitizer names that this APEX is enabled for
398 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900399
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900400 PreventInstall bool `blueprint:"mutated"`
401
402 HideFromMake bool `blueprint:"mutated"`
403
Jooyung Han5c998b92019-06-27 11:30:33 +0900404 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
405 Provide_cpp_shared_libs *bool
406
407 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
408 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100409
410 // A txt file containing list of files that are whitelisted to be included in this APEX.
411 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900412
413 // List of APKs to package inside APEX
414 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900415
Sundong Ahne8fb7242019-09-17 13:50:45 +0900416 // To distinguish between flattened and non-flattened apex.
417 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900418 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900419
Sundong Ahne8fb7242019-09-17 13:50:45 +0900420 // if true, it means that TARGET_FLATTEN_APEX is true and
421 // TARGET_BUILD_APPS is false
422 FlattenedConfigValue bool `blueprint:"mutated"`
423
Jiyong Parkd1063c12019-07-17 20:08:41 +0900424 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
425 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
426 // is implied. This value affects all modules included in this APEX. In other words, they are
427 // also built with the SDKs specified here.
428 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800429}
430
431type apexTargetBundleProperties struct {
432 Target struct {
433 // Multilib properties only for android.
434 Android struct {
435 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900436 }
Jooyung Han344d5432019-08-23 11:17:39 +0900437
Alex Light9670d332019-01-29 18:07:33 -0800438 // Multilib properties only for host.
439 Host struct {
440 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900441 }
Jooyung Han344d5432019-08-23 11:17:39 +0900442
Alex Light9670d332019-01-29 18:07:33 -0800443 // Multilib properties only for host linux_bionic.
444 Linux_bionic struct {
445 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900446 }
Jooyung Han344d5432019-08-23 11:17:39 +0900447
Alex Light9670d332019-01-29 18:07:33 -0800448 // Multilib properties only for host linux_glibc.
449 Linux_glibc struct {
450 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900451 }
452 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900453}
454
Jooyung Han344d5432019-08-23 11:17:39 +0900455type apexVndkProperties struct {
456 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
457 Vndk_version *string
458}
459
Jiyong Park8fd61922018-11-08 02:50:25 +0900460type apexFileClass int
461
462const (
463 etc apexFileClass = iota
464 nativeSharedLib
465 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900466 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800467 pyBinary
468 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900469 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100470 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900471 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900472)
473
Alex Light5098a612018-11-29 17:12:15 -0800474type apexPackaging int
475
476const (
477 imageApex apexPackaging = iota
478 zipApex
479 both
480)
481
482func (a apexPackaging) image() bool {
483 switch a {
484 case imageApex, both:
485 return true
486 }
487 return false
488}
489
490func (a apexPackaging) zip() bool {
491 switch a {
492 case zipApex, both:
493 return true
494 }
495 return false
496}
497
498func (a apexPackaging) suffix() string {
499 switch a {
500 case imageApex:
501 return imageApexSuffix
502 case zipApex:
503 return zipApexSuffix
504 case both:
505 panic(fmt.Errorf("must be either zip or image"))
506 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100507 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800508 }
509}
510
511func (a apexPackaging) name() string {
512 switch a {
513 case imageApex:
514 return imageApexType
515 case zipApex:
516 return zipApexType
517 case both:
518 panic(fmt.Errorf("must be either zip or image"))
519 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100520 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800521 }
522}
523
Jiyong Park8fd61922018-11-08 02:50:25 +0900524func (class apexFileClass) NameInMake() string {
525 switch class {
526 case etc:
527 return "ETC"
528 case nativeSharedLib:
529 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800530 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900531 return "EXECUTABLES"
532 case javaSharedLib:
533 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100534 case nativeTest:
535 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900536 case app:
537 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900538 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100539 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900540 }
541}
542
543type apexFile struct {
544 builtFile android.Path
545 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900546 installDir string
547 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900548 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800549 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900550}
551
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900552type apexBundle struct {
553 android.ModuleBase
554 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900555 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900556
Alex Light9670d332019-01-29 18:07:33 -0800557 properties apexBundleProperties
558 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900559 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900560
Alex Light5098a612018-11-29 17:12:15 -0800561 apexTypes apexPackaging
562
Colin Crossa4925902018-11-16 11:36:28 -0800563 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800564 outputFiles map[apexPackaging]android.WritablePath
Roland Levillain935639d2019-08-13 14:55:28 +0100565 flattenedOutput android.OutputPath
Colin Crossa4925902018-11-16 11:36:28 -0800566 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900567
Jiyong Park03b68dd2019-07-26 23:20:40 +0900568 prebuiltFileToDelete string
569
Jiyong Park42cca6c2019-04-01 11:15:50 +0900570 public_key_file android.Path
571 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900572
573 container_certificate_file android.Path
574 container_private_key_file android.Path
575
Jiyong Park8fd61922018-11-08 02:50:25 +0900576 // list of files to be included in this apex
577 filesInfo []apexFile
578
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900579 // list of module names that this APEX is depending on
580 externalDeps []string
581
Alex Light0851b882019-02-07 13:20:53 -0800582 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900583 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900584
585 // intermediate path for apex_manifest.json
586 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900587}
588
Jiyong Park397e55e2018-10-24 21:09:55 +0900589func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100590 native_shared_libs []string, binaries []string, tests []string,
591 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900592 // Use *FarVariation* to be able to depend on modules having
593 // conflicting variations with this module. This is required since
594 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
595 // for native shared libs.
596 ctx.AddFarVariationDependencies([]blueprint.Variation{
597 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900598 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900599 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900600 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900601 }, sharedLibTag, native_shared_libs...)
602
603 ctx.AddFarVariationDependencies([]blueprint.Variation{
604 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900605 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900606 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100607
608 ctx.AddFarVariationDependencies([]blueprint.Variation{
609 {Mutator: "arch", Variation: arch},
610 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100611 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100612 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900613}
614
Alex Light9670d332019-01-29 18:07:33 -0800615func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
616 if ctx.Os().Class == android.Device {
617 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
618 } else {
619 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
620 if ctx.Os().Bionic() {
621 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
622 } else {
623 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
624 }
625 }
626}
627
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900628func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800629
Jiyong Park397e55e2018-10-24 21:09:55 +0900630 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900631 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800632
633 a.combineProperties(ctx)
634
Jiyong Park397e55e2018-10-24 21:09:55 +0900635 has32BitTarget := false
636 for _, target := range targets {
637 if target.Arch.ArchType.Multilib == "lib32" {
638 has32BitTarget = true
639 }
640 }
641 for i, target := range targets {
642 // When multilib.* is omitted for native_shared_libs, it implies
643 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900644 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900645 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900646 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900647 {Mutator: "link", Variation: "shared"},
648 }, sharedLibTag, a.properties.Native_shared_libs...)
649
Roland Levillain630846d2019-06-26 12:48:34 +0100650 // When multilib.* is omitted for tests, it implies
651 // multilib.both.
652 ctx.AddFarVariationDependencies([]blueprint.Variation{
653 {Mutator: "arch", Variation: target.String()},
654 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100655 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100656 }, testTag, a.properties.Tests...)
657
Jiyong Park397e55e2018-10-24 21:09:55 +0900658 // Add native modules targetting both ABIs
659 addDependenciesForNativeModules(ctx,
660 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100661 a.properties.Multilib.Both.Binaries,
662 a.properties.Multilib.Both.Tests,
663 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900664 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900665
Alex Light3d673592019-01-18 14:37:31 -0800666 isPrimaryAbi := i == 0
667 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900668 // When multilib.* is omitted for binaries, it implies
669 // multilib.first.
670 ctx.AddFarVariationDependencies([]blueprint.Variation{
671 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900672 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900673 }, executableTag, a.properties.Binaries...)
674
675 // Add native modules targetting the first ABI
676 addDependenciesForNativeModules(ctx,
677 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100678 a.properties.Multilib.First.Binaries,
679 a.properties.Multilib.First.Tests,
680 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900681 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800682
683 // When multilib.* is omitted for prebuilts, it implies multilib.first.
684 ctx.AddFarVariationDependencies([]blueprint.Variation{
685 {Mutator: "arch", Variation: target.String()},
686 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900687 }
688
689 switch target.Arch.ArchType.Multilib {
690 case "lib32":
691 // Add native modules targetting 32-bit ABI
692 addDependenciesForNativeModules(ctx,
693 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100694 a.properties.Multilib.Lib32.Binaries,
695 a.properties.Multilib.Lib32.Tests,
696 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900697 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900698
699 addDependenciesForNativeModules(ctx,
700 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100701 a.properties.Multilib.Prefer32.Binaries,
702 a.properties.Multilib.Prefer32.Tests,
703 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900704 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900705 case "lib64":
706 // Add native modules targetting 64-bit ABI
707 addDependenciesForNativeModules(ctx,
708 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100709 a.properties.Multilib.Lib64.Binaries,
710 a.properties.Multilib.Lib64.Tests,
711 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900712 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900713
714 if !has32BitTarget {
715 addDependenciesForNativeModules(ctx,
716 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100717 a.properties.Multilib.Prefer32.Binaries,
718 a.properties.Multilib.Prefer32.Tests,
719 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900720 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900721 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700722
723 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
724 for _, sanitizer := range ctx.Config().SanitizeDevice() {
725 if sanitizer == "hwaddress" {
726 addDependenciesForNativeModules(ctx,
727 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100728 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700729 break
730 }
731 }
732 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900733 }
734
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900735 }
736
Jiyong Parkff1458f2018-10-12 21:49:38 +0900737 ctx.AddFarVariationDependencies([]blueprint.Variation{
738 {Mutator: "arch", Variation: "android_common"},
739 }, javaLibTag, a.properties.Java_libs...)
740
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900741 ctx.AddFarVariationDependencies([]blueprint.Variation{
742 {Mutator: "arch", Variation: "android_common"},
743 }, androidAppTag, a.properties.Apps...)
744
Jiyong Park23c52b02019-02-02 13:13:47 +0900745 if String(a.properties.Key) == "" {
746 ctx.ModuleErrorf("key is missing")
747 return
748 }
749 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900750
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900751 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900752 if cert != "" {
753 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900754 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900755
756 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
757 if len(a.properties.Uses_sdks) > 0 {
758 sdkRefs := []android.SdkRef{}
759 for _, str := range a.properties.Uses_sdks {
760 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
761 sdkRefs = append(sdkRefs, parsed)
762 }
763 a.BuildWithSdks(sdkRefs)
764 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900765}
766
Colin Cross0ea8ba82019-06-06 14:33:29 -0700767func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900768 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
769 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000770 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900771 }
772 return String(a.properties.Certificate)
773}
774
Colin Cross41955e82019-05-29 14:40:35 -0700775func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
776 switch tag {
777 case "":
778 if file, ok := a.outputFiles[imageApex]; ok {
779 return android.Paths{file}, nil
780 } else {
781 return nil, nil
782 }
Roland Levillain935639d2019-08-13 14:55:28 +0100783 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900784 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100785 flattenedApexPath := a.flattenedOutput
786 return android.Paths{flattenedApexPath}, nil
787 } else {
788 return nil, nil
789 }
Colin Cross41955e82019-05-29 14:40:35 -0700790 default:
791 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900792 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900793}
794
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900795func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900796 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900797}
798
Jiyong Park7c1dc612019-01-05 11:15:24 +0900799func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
800 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900801 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900802 } else {
803 return "core"
804 }
805}
806
Jiyong Parkf97782b2019-02-13 20:28:58 +0900807func (a *apexBundle) EnableSanitizer(sanitizerName string) {
808 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
809 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
810 }
811}
812
Jiyong Park388ef3f2019-01-28 19:47:32 +0900813func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900814 if android.InList(sanitizerName, a.properties.SanitizerNames) {
815 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900816 }
817
818 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900819 globalSanitizerNames := []string{}
820 if a.Host() {
821 globalSanitizerNames = ctx.Config().SanitizeHost()
822 } else {
823 arches := ctx.Config().SanitizeDeviceArch()
824 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
825 globalSanitizerNames = ctx.Config().SanitizeDevice()
826 }
827 }
828 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900829}
830
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900831func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
832 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
833}
834
835func (a *apexBundle) PreventInstall() {
836 a.properties.PreventInstall = true
837}
838
839func (a *apexBundle) HideFromMake() {
840 a.properties.HideFromMake = true
841}
842
Sundong Ahne9b55722019-09-06 17:37:42 +0900843func (a *apexBundle) SetFlattened(flattened bool) {
844 a.properties.Flattened = flattened
845}
846
Sundong Ahne8fb7242019-09-17 13:50:45 +0900847func (a *apexBundle) SetFlattenedConfigValue() {
848 a.properties.FlattenedConfigValue = true
849}
850
851// isFlattenedVariant returns true when the current module is the flattened
852// variant of an apex that has both a flattened and an unflattened variant.
853// It returns false when the current module is flattened but there is no
854// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
855// true. It can be used to avoid collisions between the install paths of the
856// flattened and unflattened variants.
857func (a *apexBundle) isFlattenedVariant() bool {
858 return a.properties.Flattened && !a.properties.FlattenedConfigValue
859}
860
Martin Stjernholm279de572019-09-10 23:18:20 +0100861func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862 // Decide the APEX-local directory by the multilib of the library
863 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100864 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900865 case "lib32":
866 dirInApex = "lib"
867 case "lib64":
868 dirInApex = "lib64"
869 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100870 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
871 if !ccMod.Arch().Native {
872 dirInApex = filepath.Join(dirInApex, ccMod.Arch().ArchType.String())
873 } else if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
874 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900875 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100876 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
877 // Special case for Bionic libs and other libs installed with them. This is
878 // to prevent those libs from being included in the search path
879 // /apex/com.android.runtime/${LIB}. This exclusion is required because
880 // those libs in the Runtime APEX are available via the legacy paths in
881 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
882 // to the legacy paths and thus will be loaded into the default linker
883 // namespace (aka "platform" namespace). If the libs are directly in
884 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
885 // into the runtime linker namespace, which will result in double loading of
886 // them, which isn't supported.
887 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900888 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900889
Martin Stjernholm279de572019-09-10 23:18:20 +0100890 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900891 return
892}
893
894func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900895 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200896 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900897 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200898 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
899 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900900 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900901 fileToCopy = cc.OutputFile().Path()
902 return
903}
904
Alex Light778127a2019-02-27 14:19:50 -0800905func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
906 dirInApex = "bin"
907 fileToCopy = py.HostToolPath().Path()
908 return
909}
910func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
911 dirInApex = "bin"
912 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
913 if err != nil {
914 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
915 return
916 }
917 fileToCopy = android.PathForOutput(ctx, s)
918 return
919}
920
Jiyong Park04480cf2019-02-06 00:16:29 +0900921func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
922 dirInApex = filepath.Join("bin", sh.SubDir())
923 fileToCopy = sh.OutputFile()
924 return
925}
926
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900927func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
928 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900929 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900930 return
931}
932
Jiyong Park9e6c2422019-08-09 20:39:45 +0900933func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
934 dirInApex = "javalib"
935 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
936 implJars := java.ImplementationJars()
937 if len(implJars) != 1 {
938 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
939 strings.Join(implJars.Strings(), ", ")))
940 }
941 fileToCopy = implJars[0]
942 return
943}
944
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900945func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
946 dirInApex = filepath.Join("etc", prebuilt.SubDir())
947 fileToCopy = prebuilt.OutputFile()
948 return
949}
950
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900951func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
952 dirInApex = filepath.Join("app", pkgName)
953 fileToCopy = app.OutputFile()
954 return
955}
956
Roland Levillain935639d2019-08-13 14:55:28 +0100957// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
958type flattenedApexContext struct {
959 android.ModuleContext
960}
961
962func (c *flattenedApexContext) InstallBypassMake() bool {
963 return true
964}
965
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900966func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900967 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900968
Alex Light5098a612018-11-29 17:12:15 -0800969 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
970 a.apexTypes = imageApex
971 } else if *a.properties.Payload_type == "zip" {
972 a.apexTypes = zipApex
973 } else if *a.properties.Payload_type == "both" {
974 a.apexTypes = both
975 } else {
976 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
977 return
978 }
979
Roland Levillain630846d2019-06-26 12:48:34 +0100980 if len(a.properties.Tests) > 0 && !a.testApex {
981 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
982 return
983 }
984
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800985 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
986
Jooyung Hane1633032019-08-01 17:41:43 +0900987 // native lib dependencies
988 var provideNativeLibs []string
989 var requireNativeLibs []string
990
Jooyung Han5c998b92019-06-27 11:30:33 +0900991 // Check if "uses" requirements are met with dependent apexBundles
992 var providedNativeSharedLibs []string
993 useVendor := proptools.Bool(a.properties.Use_vendor)
994 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
995 if ctx.OtherModuleDependencyTag(m) != usesTag {
996 return
997 }
998 otherName := ctx.OtherModuleName(m)
999 other, ok := m.(*apexBundle)
1000 if !ok {
1001 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1002 return
1003 }
1004 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1005 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1006 return
1007 }
1008 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1009 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1010 return
1011 }
1012 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1013 })
1014
Alex Light778127a2019-02-27 14:19:50 -08001015 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001016 depTag := ctx.OtherModuleDependencyTag(child)
1017 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001018 if _, ok := parent.(*apexBundle); ok {
1019 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001020 switch depTag {
1021 case sharedLibTag:
1022 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001023 if cc.HasStubsVariants() {
1024 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1025 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001026 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001027 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001028 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001029 } else {
1030 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031 }
1032 case executableTag:
1033 if cc, ok := child.(*cc.Module); ok {
1034 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001035 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001036 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001037 } else if sh, ok := child.(*android.ShBinary); ok {
1038 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
1039 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -08001040 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1041 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1042 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1043 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1044 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1045 // NB: Since go binaries are static we don't need the module for anything here, which is
1046 // good since the go tool is a blueprint.Module not an android.Module like we would
1047 // normally use.
1048 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001049 } else {
Alex Light778127a2019-02-27 14:19:50 -08001050 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 +09001051 }
1052 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001053 if javaLib, ok := child.(*java.Library); ok {
1054 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001055 if fileToCopy == nil {
1056 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1057 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001058 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1059 }
1060 return true
1061 } else if javaLib, ok := child.(*java.Import); ok {
1062 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1063 if fileToCopy == nil {
1064 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1065 } else {
1066 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001067 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001069 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001070 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001071 }
1072 case prebuiltTag:
1073 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1074 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001075 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001076 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001077 } else {
1078 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1079 }
Roland Levillain630846d2019-06-26 12:48:34 +01001080 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001081 if ccTest, ok := child.(*cc.Module); ok {
1082 if ccTest.IsTestPerSrcAllTestsVariation() {
1083 // Multiple-output test module (where `test_per_src: true`).
1084 //
1085 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1086 // We do not add this variation to `filesInfo`, as it has no output;
1087 // however, we do add the other variations of this module as indirect
1088 // dependencies (see below).
1089 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001090 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001091 // Single-output test module (where `test_per_src: false`).
1092 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1093 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001094 }
Roland Levillain630846d2019-06-26 12:48:34 +01001095 return true
1096 } else {
1097 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1098 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001099 case keyTag:
1100 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001101 a.private_key_file = key.private_key_file
1102 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001103 return false
1104 } else {
1105 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001106 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001107 case certificateTag:
1108 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001109 a.container_certificate_file = dep.Certificate.Pem
1110 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001111 return false
1112 } else {
1113 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1114 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001115 case android.PrebuiltDepTag:
1116 // If the prebuilt is force disabled, remember to delete the prebuilt file
1117 // that might have been installed in the previous builds
1118 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1119 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1120 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001121 case androidAppTag:
1122 if ap, ok := child.(*java.AndroidApp); ok {
1123 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1124 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1125 return true
1126 } else {
1127 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1128 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001129 }
1130 } else {
1131 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001132 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001133 // We cannot use a switch statement on `depTag` here as the checked
1134 // tags used below are private (e.g. `cc.sharedDepTag`).
1135 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1136 if cc, ok := child.(*cc.Module); ok {
1137 if android.InList(cc.Name(), providedNativeSharedLibs) {
1138 // If we're using a shared library which is provided from other APEX,
1139 // don't include it in this APEX
1140 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001141 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001142 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1143 // If the dependency is a stubs lib, don't include it in this APEX,
1144 // but make sure that the lib is installed on the device.
1145 // In case no APEX is having the lib, the lib is installed to the system
1146 // partition.
1147 //
1148 // Always include if we are a host-apex however since those won't have any
1149 // system libraries.
1150 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1151 a.externalDeps = append(a.externalDeps, cc.Name())
1152 }
Jooyung Hane1633032019-08-01 17:41:43 +09001153 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001154 // Don't track further
1155 return false
1156 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001157 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001158 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1159 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001160 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001161 } else if cc.IsTestPerSrcDepTag(depTag) {
1162 if cc, ok := child.(*cc.Module); ok {
1163 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1164 // Handle modules created as `test_per_src` variations of a single test module:
1165 // use the name of the generated test binary (`fileToCopy`) instead of the name
1166 // of the original test module (`depName`, shared by all `test_per_src`
1167 // variations of that module).
1168 moduleName := filepath.Base(fileToCopy.String())
1169 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1170 return true
1171 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001172 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001173 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jooyung Hancc372c52019-09-25 15:18:44 +09001174 } else if depTag == android.DefaultsDepTag {
1175 return false
Sundong Ahn2db7f462019-08-27 18:53:12 +09001176 } else if am.NoApex() && !android.InList(depName, whitelistNoApex[ctx.ModuleName()]) {
1177 ctx.ModuleErrorf("tries to include no_apex module %s", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001178 }
1179 }
1180 }
1181 return false
1182 })
1183
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001184 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001185 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1186 return
1187 }
1188
Jiyong Park8fd61922018-11-08 02:50:25 +09001189 // remove duplicates in filesInfo
1190 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001191 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001192 result := []apexFile{}
1193 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001194 dest := filepath.Join(f.installDir, f.builtFile.Base())
1195 if !encountered[dest] {
1196 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001197 result = append(result, f)
1198 }
1199 }
1200 return result
1201 }
1202 filesInfo = removeDup(filesInfo)
1203
1204 // to have consistent build rules
1205 sort.Slice(filesInfo, func(i, j int) bool {
1206 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1207 })
1208
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09001209 // check no_apex modules
1210 whitelist := whitelistNoApex[ctx.ModuleName()]
1211 for i := range filesInfo {
1212 if am, ok := filesInfo[i].module.(android.ApexModule); ok {
1213 if am.NoApex() && !android.InList(filesInfo[i].moduleName, whitelist) {
1214 ctx.ModuleErrorf("tries to include no_apex module %s", filesInfo[i].moduleName)
1215 }
1216 }
1217 }
1218
Jiyong Park8fd61922018-11-08 02:50:25 +09001219 // prepend the name of this APEX to the module names. These names will be the names of
1220 // modules that will be defined if the APEX is flattened.
1221 for i := range filesInfo {
1222 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
1223 }
1224
Jiyong Park8fd61922018-11-08 02:50:25 +09001225 a.installDir = android.PathForModuleInstall(ctx, "apex")
1226 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001227
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001228 // prepare apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001229 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
Jooyung Hane1633032019-08-01 17:41:43 +09001230 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001231
1232 // put dependency({provide|require}NativeLibs) in apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001233 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1234 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001235
1236 // apex name can be overridden
1237 optCommands := []string{}
1238 if a.properties.Apex_name != nil {
1239 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
1240 }
1241
Jooyung Hane1633032019-08-01 17:41:43 +09001242 ctx.Build(pctx, android.BuildParams{
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001243 Rule: apexManifestRule,
Jooyung Hane1633032019-08-01 17:41:43 +09001244 Input: manifestSrc,
1245 Output: a.manifestOut,
1246 Args: map[string]string{
1247 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1248 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001249 "opt": strings.Join(optCommands, " "),
Jooyung Hane1633032019-08-01 17:41:43 +09001250 },
1251 })
1252
Roland Levillain935639d2019-08-13 14:55:28 +01001253 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1254 // reply true to `InstallBypassMake()` (thus making the call
1255 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1256 // instead of `android.PathForOutput`) to return the correct path to the flattened
1257 // APEX (as its contents is installed by Make, not Soong).
1258 factx := flattenedApexContext{ctx}
1259 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
1260
Alex Light5098a612018-11-29 17:12:15 -08001261 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001262 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001263 }
1264 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001265 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001266 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001267 // in other modules. It is in AndroidMk where the selection of flattened
1268 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001269 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001270 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001271 }
1272}
1273
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001274func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001275 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001276 for _, f := range a.filesInfo {
1277 if f.module != nil {
1278 notice := f.module.NoticeFile()
1279 if notice.Valid() {
1280 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001281 }
1282 }
1283 }
1284 // append the notice file specified in the apex module itself
1285 if a.NoticeFile().Valid() {
1286 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001287 }
1288
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001289 if len(noticeFiles) == 0 {
1290 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001291 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001292
Jaewoong Jung98772792019-07-01 17:15:13 -07001293 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001294}
1295
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001296func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001297 cert := String(a.properties.Certificate)
1298 if cert != "" && android.SrcIsModule(cert) == "" {
1299 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001300 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1301 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001302 } else if cert == "" {
1303 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001304 a.container_certificate_file = pem
1305 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001306 }
1307
Alex Light5098a612018-11-29 17:12:15 -08001308 var abis []string
1309 for _, target := range ctx.MultiTargets() {
1310 if len(target.Arch.Abi) > 0 {
1311 abis = append(abis, target.Arch.Abi[0])
1312 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001313 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001314
Alex Light5098a612018-11-29 17:12:15 -08001315 abis = android.FirstUniqueStrings(abis)
1316
1317 suffix := apexType.suffix()
1318 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001319
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001320 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001321 for _, f := range a.filesInfo {
1322 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001323 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001324
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001325 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001326 emitCommands := []string{}
1327 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1328 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001329 for i, src := range filesToCopy {
1330 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001331 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001332 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001333 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1334 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001335 for _, sym := range a.filesInfo[i].symlinks {
1336 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1337 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1338 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001339 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001340 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001341 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001342
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001343 if a.properties.Whitelisted_files != nil {
1344 ctx.Build(pctx, android.BuildParams{
1345 Rule: emitApexContentRule,
1346 Implicits: implicitInputs,
1347 Output: imageContentFile,
1348 Description: "emit apex image content",
1349 Args: map[string]string{
1350 "emit_commands": strings.Join(emitCommands, " && "),
1351 },
1352 })
1353 implicitInputs = append(implicitInputs, imageContentFile)
1354 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1355
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001356 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001357 ctx.Build(pctx, android.BuildParams{
1358 Rule: diffApexContentRule,
1359 Implicits: implicitInputs,
1360 Output: phonyOutput,
1361 Description: "diff apex image content",
1362 Args: map[string]string{
1363 "whitelisted_files_file": whitelistedFilesFile.String(),
1364 "image_content_file": imageContentFile.String(),
1365 "apex_module_name": ctx.ModuleName(),
1366 },
1367 })
1368
1369 implicitInputs = append(implicitInputs, phonyOutput)
1370 }
1371
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001372 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1373 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001374
Alex Light5098a612018-11-29 17:12:15 -08001375 if apexType.image() {
1376 // files and dirs that will be created in APEX
1377 var readOnlyPaths []string
1378 var executablePaths []string // this also includes dirs
1379 for _, f := range a.filesInfo {
1380 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001381 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001382 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001383 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001384 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001385 }
Alex Light5098a612018-11-29 17:12:15 -08001386 } else {
1387 readOnlyPaths = append(readOnlyPaths, pathInApex)
1388 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001389 dir := f.installDir
1390 for !android.InList(dir, executablePaths) && dir != "" {
1391 executablePaths = append(executablePaths, dir)
1392 dir, _ = filepath.Split(dir) // move up to the parent
1393 if len(dir) > 0 {
1394 // remove trailing slash
1395 dir = dir[:len(dir)-1]
1396 }
Alex Light5098a612018-11-29 17:12:15 -08001397 }
1398 }
1399 sort.Strings(readOnlyPaths)
1400 sort.Strings(executablePaths)
1401 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1402 ctx.Build(pctx, android.BuildParams{
1403 Rule: generateFsConfig,
1404 Output: cannedFsConfig,
1405 Description: "generate fs config",
1406 Args: map[string]string{
1407 "ro_paths": strings.Join(readOnlyPaths, " "),
1408 "exec_paths": strings.Join(executablePaths, " "),
1409 },
1410 })
1411
1412 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1413 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1414 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1415 if !fileContextsOptionalPath.Valid() {
1416 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1417 return
1418 }
1419 fileContexts := fileContextsOptionalPath.Path()
1420
Jiyong Park835d82b2018-12-27 16:04:18 +09001421 optFlags := []string{}
1422
Alex Light5098a612018-11-29 17:12:15 -08001423 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001424 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1425 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001426
Jiyong Park7f67f482019-01-05 12:57:48 +09001427 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1428 if overridden {
1429 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1430 }
1431
Jiyong Park40e26a22019-02-08 02:53:06 +09001432 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001433 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001434 implicitInputs = append(implicitInputs, androidManifestFile)
1435 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1436 }
1437
Jiyong Park71b519d2019-04-18 17:25:49 +09001438 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1439 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1440 ctx.Config().UnbundledBuild() &&
1441 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1442 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1443 apiFingerprint := java.ApiFingerprintPath(ctx)
1444 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1445 implicitInputs = append(implicitInputs, apiFingerprint)
1446 }
1447 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1448
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001449 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1450 if noticeFile.Valid() {
1451 // If there's a NOTICE file, embed it as an asset file in the APEX.
1452 implicitInputs = append(implicitInputs, noticeFile.Path())
1453 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1454 }
1455
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001456 if !ctx.Config().UnbundledBuild() && a.installable() {
1457 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1458 // don't need hashtree for activation. Therefore, by removing hashtree from
1459 // apex bundle (filesystem image in it, to be specific), we can save storage.
1460 optFlags = append(optFlags, "--no_hashtree")
1461 }
1462
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001463 if a.properties.Apex_name != nil {
1464 // If apex_name is set, apexer can skip checking if key name matches with apex name.
1465 // Note that apex_manifest is also mended.
1466 optFlags = append(optFlags, "--do_not_check_keyname")
1467 }
1468
Alex Light5098a612018-11-29 17:12:15 -08001469 ctx.Build(pctx, android.BuildParams{
1470 Rule: apexRule,
1471 Implicits: implicitInputs,
1472 Output: unsignedOutputFile,
1473 Description: "apex (" + apexType.name() + ")",
1474 Args: map[string]string{
1475 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1476 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1477 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001478 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001479 "file_contexts": fileContexts.String(),
1480 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001481 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001482 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001483 },
1484 })
1485
1486 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1487 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1488 a.bundleModuleFile = bundleModuleFile
1489
1490 ctx.Build(pctx, android.BuildParams{
1491 Rule: apexProtoConvertRule,
1492 Input: unsignedOutputFile,
1493 Output: apexProtoFile,
1494 Description: "apex proto convert",
1495 })
1496
1497 ctx.Build(pctx, android.BuildParams{
1498 Rule: apexBundleRule,
1499 Input: apexProtoFile,
1500 Output: a.bundleModuleFile,
1501 Description: "apex bundle module",
1502 Args: map[string]string{
1503 "abi": strings.Join(abis, "."),
1504 },
1505 })
1506 } else {
1507 ctx.Build(pctx, android.BuildParams{
1508 Rule: zipApexRule,
1509 Implicits: implicitInputs,
1510 Output: unsignedOutputFile,
1511 Description: "apex (" + apexType.name() + ")",
1512 Args: map[string]string{
1513 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1514 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1515 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001516 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001517 },
1518 })
Colin Crossa4925902018-11-16 11:36:28 -08001519 }
Colin Crossa4925902018-11-16 11:36:28 -08001520
Alex Light5098a612018-11-29 17:12:15 -08001521 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001522 ctx.Build(pctx, android.BuildParams{
1523 Rule: java.Signapk,
1524 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001525 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001526 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001527 Implicits: []android.Path{
1528 a.container_certificate_file,
1529 a.container_private_key_file,
1530 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001531 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001532 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001533 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001534 },
1535 })
Alex Light5098a612018-11-29 17:12:15 -08001536
1537 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001538 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001539 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001540 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001541}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001542
Jiyong Park8fd61922018-11-08 02:50:25 +09001543func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001544 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001545 // 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 +09001546 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001547 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001548
Jiyong Park42cca6c2019-04-01 11:15:50 +09001549 // rename to apex_pubkey
1550 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1551 ctx.Build(pctx, android.BuildParams{
1552 Rule: android.Cp,
1553 Input: a.public_key_file,
1554 Output: copiedPubkey,
1555 })
1556 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1557
Jiyong Park23c52b02019-02-02 13:13:47 +09001558 if ctx.Config().FlattenApex() {
1559 for _, fi := range a.filesInfo {
1560 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001561 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1562 for _, sym := range fi.symlinks {
1563 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1564 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001565 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001566 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001567 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001568}
1569
1570func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001571 if a.properties.HideFromMake {
1572 return android.AndroidMkData{
1573 Disabled: true,
1574 }
1575 }
Alex Light5098a612018-11-29 17:12:15 -08001576 writers := []android.AndroidMkData{}
1577 if a.apexTypes.image() {
1578 writers = append(writers, a.androidMkForType(imageApex))
1579 }
1580 if a.apexTypes.zip() {
1581 writers = append(writers, a.androidMkForType(zipApex))
1582 }
1583 return android.AndroidMkData{
1584 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1585 for _, data := range writers {
1586 data.Custom(w, name, prefix, moduleDir, data)
1587 }
1588 }}
1589}
1590
Alex Lightf1801bc2019-02-13 11:10:07 -08001591func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001592 moduleNames := []string{}
1593
1594 for _, fi := range a.filesInfo {
1595 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1596 continue
1597 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001598 if a.properties.Flattened && !apexType.image() {
1599 continue
Jiyong Park94427262019-02-05 23:18:47 +09001600 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001601
1602 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001603 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001604 suffix = ".flattened"
1605 }
1606
1607 if !android.InList(fi.moduleName, moduleNames) {
1608 moduleNames = append(moduleNames, fi.moduleName+suffix)
1609 }
1610
Jiyong Park94427262019-02-05 23:18:47 +09001611 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1612 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001613 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001614 // /apex/<apex_name>/{lib|framework|...}
Jiyong Park05e70dd2019-03-18 14:26:32 +09001615 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1616 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001617 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001618 // /system/apex/<name>/{lib|framework|...}
1619 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1620 a.installDir.RelPathString(), name, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001621 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001622 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1623 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001624 if len(fi.symlinks) > 0 {
1625 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1626 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001627
1628 if fi.module != nil && fi.module.NoticeFile().Valid() {
1629 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1630 }
Jiyong Park94427262019-02-05 23:18:47 +09001631 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001632 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001633 }
1634 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1635 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1636 if fi.module != nil {
1637 archStr := fi.module.Target().Arch.ArchType.String()
1638 host := false
1639 switch fi.module.Target().Os.Class {
1640 case android.Host:
1641 if archStr != "common" {
1642 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1643 }
1644 host = true
1645 case android.HostCross:
1646 if archStr != "common" {
1647 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1648 }
1649 host = true
1650 case android.Device:
1651 if archStr != "common" {
1652 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1653 }
1654 }
1655 if host {
1656 makeOs := fi.module.Target().Os.String()
1657 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1658 makeOs = "linux"
1659 }
1660 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1661 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1662 }
1663 }
1664 if fi.class == javaSharedLib {
1665 javaModule := fi.module.(*java.Library)
1666 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1667 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1668 // we will have foo.jar.jar
1669 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1670 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1671 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1672 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1673 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1674 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001675 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001676 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001677 if cc, ok := fi.module.(*cc.Module); ok {
1678 if cc.UnstrippedOutputFile() != nil {
1679 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1680 }
1681 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001682 if cc.CoverageOutputFile().Valid() {
1683 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1684 }
Jiyong Park94427262019-02-05 23:18:47 +09001685 }
1686 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1687 } else {
1688 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1689 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1690 }
1691 }
1692 return moduleNames
1693}
1694
Alex Light5098a612018-11-29 17:12:15 -08001695func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001696 return android.AndroidMkData{
1697 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1698 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001699 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001700 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001701 }
1702
Sundong Ahne8fb7242019-09-17 13:50:45 +09001703 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001704 name = name + ".flattened"
1705 }
1706
1707 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001708 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001709 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1710 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1711 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001712 if len(moduleNames) > 0 {
1713 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1714 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001715 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001716 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1717
Sundong Ahne8fb7242019-09-17 13:50:45 +09001718 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001719 // zip-apex is the less common type so have the name refer to the image-apex
1720 // only and use {name}.zip if you want the zip-apex
1721 if apexType == zipApex && a.apexTypes == both {
1722 name = name + ".zip"
1723 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001724 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1725 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1726 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1727 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001728 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001729 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001730 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001731 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001732 if len(moduleNames) > 0 {
1733 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1734 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001735 if len(a.externalDeps) > 0 {
1736 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1737 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001738 if a.prebuiltFileToDelete != "" {
1739 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1740 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1741 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001742 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001743
Alex Light5098a612018-11-29 17:12:15 -08001744 if apexType == imageApex {
1745 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1746 }
Jiyong Park719b4462019-01-13 00:39:51 +09001747 }
1748 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001749}
1750
Jooyung Han344d5432019-08-23 11:17:39 +09001751func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001752 module := &apexBundle{
1753 outputFiles: map[apexPackaging]android.WritablePath{},
1754 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001755 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001756 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001757 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001758 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1759 })
Alex Light5098a612018-11-29 17:12:15 -08001760 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001761 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001762 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001763 return module
1764}
Jiyong Park30ca9372019-02-07 16:27:23 +09001765
Jooyung Han344d5432019-08-23 11:17:39 +09001766func ApexBundleFactory(testApex bool) android.Module {
1767 bundle := newApexBundle()
1768 bundle.testApex = testApex
1769 return bundle
1770}
1771
1772func testApexBundleFactory() android.Module {
1773 bundle := newApexBundle()
1774 bundle.testApex = true
1775 return bundle
1776}
1777
Jiyong Parkd1063c12019-07-17 20:08:41 +09001778func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001779 return newApexBundle()
1780}
1781
1782// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1783// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1784// If not specified, then the "current" versions are gathered.
1785func vndkApexBundleFactory() android.Module {
1786 bundle := newApexBundle()
1787 bundle.vndkApex = true
1788 bundle.AddProperties(&bundle.vndkProperties)
1789 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1790 ctx.AppendProperties(&struct {
1791 Compile_multilib *string
1792 }{
1793 proptools.StringPtr("both"),
1794 })
1795 })
1796 return bundle
1797}
1798
Jiyong Park30ca9372019-02-07 16:27:23 +09001799//
1800// Defaults
1801//
1802type Defaults struct {
1803 android.ModuleBase
1804 android.DefaultsModuleBase
1805}
1806
Jiyong Park30ca9372019-02-07 16:27:23 +09001807func defaultsFactory() android.Module {
1808 return DefaultsFactory()
1809}
1810
1811func DefaultsFactory(props ...interface{}) android.Module {
1812 module := &Defaults{}
1813
1814 module.AddProperties(props...)
1815 module.AddProperties(
1816 &apexBundleProperties{},
1817 &apexTargetBundleProperties{},
1818 )
1819
1820 android.InitDefaultsModule(module)
1821 return module
1822}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001823
1824//
1825// Prebuilt APEX
1826//
1827type Prebuilt struct {
1828 android.ModuleBase
1829 prebuilt android.Prebuilt
1830
1831 properties PrebuiltProperties
1832
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001833 inputApex android.Path
1834 installDir android.OutputPath
1835 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001836 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001837}
1838
1839type PrebuiltProperties struct {
1840 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001841 Source string `blueprint:"mutated"`
1842 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001843
1844 Src *string
1845 Arch struct {
1846 Arm struct {
1847 Src *string
1848 }
1849 Arm64 struct {
1850 Src *string
1851 }
1852 X86 struct {
1853 Src *string
1854 }
1855 X86_64 struct {
1856 Src *string
1857 }
1858 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001859
1860 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001861 // Optional name for the installed apex. If unspecified, name of the
1862 // module is used as the file name
1863 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001864
1865 // Names of modules to be overridden. Listed modules can only be other binaries
1866 // (in Make or Soong).
1867 // This does not completely prevent installation of the overridden binaries, but if both
1868 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1869 // from PRODUCT_PACKAGES.
1870 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001871}
1872
1873func (p *Prebuilt) installable() bool {
1874 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001875}
1876
1877func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001878 // If the device is configured to use flattened APEX, force disable the prebuilt because
1879 // the prebuilt is a non-flattened one.
1880 forceDisable := ctx.Config().FlattenApex()
1881
1882 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1883 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001884 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001885
Kun Niu10c9f832019-07-29 16:28:57 -07001886 // Force disable the prebuilts when coverage is enabled.
1887 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1888 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1889
Jiyong Park50b81e52019-07-11 11:24:41 +09001890 // b/137216042 don't use prebuilts when address sanitizer is on
1891 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1892 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1893
1894 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001895 p.properties.ForceDisable = true
1896 return
1897 }
1898
Jiyong Parkc95714e2019-03-29 14:23:10 +09001899 // This is called before prebuilt_select and prebuilt_postdeps mutators
1900 // The mutators requires that src to be set correctly for each arch so that
1901 // arch variants are disabled when src is not provided for the arch.
1902 if len(ctx.MultiTargets()) != 1 {
1903 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1904 return
1905 }
1906 var src string
1907 switch ctx.MultiTargets()[0].Arch.ArchType {
1908 case android.Arm:
1909 src = String(p.properties.Arch.Arm.Src)
1910 case android.Arm64:
1911 src = String(p.properties.Arch.Arm64.Src)
1912 case android.X86:
1913 src = String(p.properties.Arch.X86.Src)
1914 case android.X86_64:
1915 src = String(p.properties.Arch.X86_64.Src)
1916 default:
1917 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1918 return
1919 }
1920 if src == "" {
1921 src = String(p.properties.Src)
1922 }
1923 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001924}
1925
Jiyong Park03b68dd2019-07-26 23:20:40 +09001926func (p *Prebuilt) isForceDisabled() bool {
1927 return p.properties.ForceDisable
1928}
1929
Colin Cross41955e82019-05-29 14:40:35 -07001930func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1931 switch tag {
1932 case "":
1933 return android.Paths{p.outputApex}, nil
1934 default:
1935 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1936 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001937}
1938
Jiyong Park4d277042019-04-23 18:00:10 +09001939func (p *Prebuilt) InstallFilename() string {
1940 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1941}
1942
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001943func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001944 if p.properties.ForceDisable {
1945 return
1946 }
1947
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001948 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001949 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001950 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001951 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001952 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1953 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1954 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001955 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1956 ctx.Build(pctx, android.BuildParams{
1957 Rule: android.Cp,
1958 Input: p.inputApex,
1959 Output: p.outputApex,
1960 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001961 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001962 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001963 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001964}
1965
1966func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1967 return &p.prebuilt
1968}
1969
1970func (p *Prebuilt) Name() string {
1971 return p.prebuilt.Name(p.ModuleBase.Name())
1972}
1973
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001974func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1975 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001976 Class: "ETC",
1977 OutputFile: android.OptionalPathForPath(p.inputApex),
1978 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001979 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1980 func(entries *android.AndroidMkEntries) {
1981 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1982 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1983 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1984 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
1985 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001986 },
1987 }
1988}
1989
1990// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1991func PrebuiltFactory() android.Module {
1992 module := &Prebuilt{}
1993 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001994 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001995 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001996 return module
1997}