blob: 6024deb9756759b8d128f75811088e83ff9a176c [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 Hane1633032019-08-01 17:41:43 +090050 injectApexDependency = pctx.StaticRule("injectApexDependency", blueprint.RuleParams{
51 Command: `rm -f $out && ${jsonmodify} $in ` +
52 `-a provideNativeLibs ${provideNativeLibs} ` +
53 `-a requireNativeLibs ${requireNativeLibs} -o $out`,
54 CommandDeps: []string{"${jsonmodify}"},
55 Description: "Inject dependency into ${out}",
56 }, "provideNativeLibs", "requireNativeLibs")
57
Jiyong Park48ca7dc2018-10-10 14:01:00 +090058 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
59 // against the binary policy using sefcontext_compiler -p <policy>.
60
61 // TODO(b/114327326): automate the generation of file_contexts
62 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
63 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010064 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090065 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090066 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067 `--file_contexts ${file_contexts} ` +
68 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080069 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090070 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090071 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
72 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000073 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010074 Rspfile: "${out}.copy_commands",
75 RspfileContent: "${copy_commands}",
76 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090077 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080078
Alex Light5098a612018-11-29 17:12:15 -080079 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
80 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010081 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080082 `APEXER_TOOL_PATH=${tool_path} ` +
83 `${apexer} --force --manifest ${manifest} ` +
84 `--payload_type zip ` +
85 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010086 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
87 Rspfile: "${out}.copy_commands",
88 RspfileContent: "${copy_commands}",
89 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080090 }, "tool_path", "image_dir", "copy_commands", "manifest")
91
Colin Crossa4925902018-11-16 11:36:28 -080092 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
93 blueprint.RuleParams{
94 Command: `${aapt2} convert --output-format proto $in -o $out`,
95 CommandDeps: []string{"${aapt2}"},
96 })
97
98 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090099 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +0000100 `apex_payload.img:apex/${abi}.img ` +
101 `apex_manifest.json:root/apex_manifest.json ` +
Jaewoong Jungb00c1fb2019-09-04 13:26:18 -0700102 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
103 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
Colin Crossa4925902018-11-16 11:36:28 -0800104 CommandDeps: []string{"${zip2zip}"},
105 Description: "app bundle",
106 }, "abi")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100107
108 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
109 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
110 Rspfile: "${out}.emit_commands",
111 RspfileContent: "${emit_commands}",
112 Description: "Emit APEX image content",
113 }, "emit_commands")
114
115 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
116 Command: `diff --unchanged-group-format='' \` +
117 `--changed-group-format='%<' \` +
118 `${image_content_file} ${whitelisted_files_file} || (` +
119 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
120 ` "To fix the build run following command:" && ` +
121 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
122 `exit 1)`,
123 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
124 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900125)
126
Alex Light5098a612018-11-29 17:12:15 -0800127var imageApexSuffix = ".apex"
128var zipApexSuffix = ".zipapex"
129
130var imageApexType = "image"
131var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900132
133type dependencyTag struct {
134 blueprint.BaseDependencyTag
135 name string
136}
137
138var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900139 sharedLibTag = dependencyTag{name: "sharedLib"}
140 executableTag = dependencyTag{name: "executable"}
141 javaLibTag = dependencyTag{name: "javaLib"}
142 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100143 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900144 keyTag = dependencyTag{name: "key"}
145 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900146 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900147 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900148)
149
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900150var (
151 whitelistNoApex = map[string][]string{
152 "apex_test_build_features": []string{"libbinder"},
153 "com.android.neuralnetworks": []string{"libbinder"},
154 "com.android.media": []string{"libbinder"},
155 "com.android.media.swcodec": []string{"libbinder"},
156 "test_com.android.media.swcodec": []string{"libbinder"},
Jooyung Han344d5432019-08-23 11:17:39 +0900157 "com.android.vndk": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900158 }
159)
160
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900161func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700162 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900163 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900164 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100165 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
166 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
167 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
168 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000169 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100170 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
171 } else {
172 return pctx.HostBinToolPath(ctx, tool).String()
173 }
174 })
175 }
176 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900177 pctx.HostBinToolVariable("avbtool", "avbtool")
178 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
179 pctx.HostBinToolVariable("merge_zips", "merge_zips")
180 pctx.HostBinToolVariable("mke2fs", "mke2fs")
181 pctx.HostBinToolVariable("resize2fs", "resize2fs")
182 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
183 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800184 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900185 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900186 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900187
Jiyong Parkd1063c12019-07-17 20:08:41 +0900188 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800189 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900190 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900191 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700192 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900193
Jooyung Han344d5432019-08-23 11:17:39 +0900194 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
195 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
196 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
197 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900198 android.PostDepsMutators(RegisterPostDepsMutators)
199}
200
201func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
202 ctx.TopDown("apex_deps", apexDepsMutator)
203 ctx.BottomUp("apex", apexMutator).Parallel()
204 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
205 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900206}
207
Jooyung Han344d5432019-08-23 11:17:39 +0900208var (
209 vndkApexListKey = android.NewOnceKey("vndkApexList")
210 vndkApexListMutex sync.Mutex
211)
212
213func vndkApexList(config android.Config) map[string]*apexBundle {
214 return config.Once(vndkApexListKey, func() interface{} {
215 return map[string]*apexBundle{}
216 }).(map[string]*apexBundle)
217}
218
219// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
220func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
221 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
222 if ab.IsNativeBridgeSupported() {
223 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
224 }
225 vndkVersion := proptools.StringDefault(ab.vndkProperties.Vndk_version, mctx.DeviceConfig().PlatformVndkVersion())
226 vndkApexListMutex.Lock()
227 defer vndkApexListMutex.Unlock()
228 vndkApexList := vndkApexList(mctx.Config())
229 if other, ok := vndkApexList[vndkVersion]; ok {
230 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.Name())
231 }
232 vndkApexList[vndkVersion] = ab
233 }
234}
235
236// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
237// It filters only libs with matching targets.
238func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
239 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
240 vndkApexList := vndkApexList(mctx.Config())
241 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
242 targetArch := cc.Target().String()
243 for _, target := range ab.MultiTargets() {
244 if target.String() == targetArch {
245 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
246 break
247 }
248 }
249 }
250 }
251}
252
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900253// Mark the direct and transitive dependencies of apex bundles so that they
254// can be built for the apex bundles.
255func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800256 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800257 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900258 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900259 depName := mctx.OtherModuleName(child)
260 // If the parent is apexBundle, this child is directly depended.
261 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800262 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800263 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
264 // non-installable apex's cannot be installed and so should not prevent libraries from being
265 // installed to the system.
266 android.UpdateApexDependency(apexBundleName, depName, directDep)
267 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900268
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900269 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900270 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900271 return true
272 } else {
273 return false
274 }
275 })
276 }
277}
278
279// Create apex variations if a module is included in APEX(s).
280func apexMutator(mctx android.BottomUpMutatorContext) {
281 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900282 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900283 } else if _, ok := mctx.Module().(*apexBundle); ok {
284 // apex bundle itself is mutated so that it and its modules have same
285 // apex variant.
286 apexBundleName := mctx.ModuleName()
287 mctx.CreateVariations(apexBundleName)
288 }
289}
Sundong Ahne9b55722019-09-06 17:37:42 +0900290
291func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900292 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900293 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
294 modules := mctx.CreateLocalVariations("", "flattened")
295 modules[0].(*apexBundle).SetFlattened(false)
296 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900297 } else {
298 ab.SetFlattened(true)
299 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900300 }
301 }
302}
303
Jooyung Han5c998b92019-06-27 11:30:33 +0900304func apexUsesMutator(mctx android.BottomUpMutatorContext) {
305 if ab, ok := mctx.Module().(*apexBundle); ok {
306 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
307 }
308}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900309
Alex Light9670d332019-01-29 18:07:33 -0800310type apexNativeDependencies struct {
311 // List of native libraries
312 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900313
Alex Light9670d332019-01-29 18:07:33 -0800314 // List of native executables
315 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900316
Roland Levillain630846d2019-06-26 12:48:34 +0100317 // List of native tests
318 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800319}
Jooyung Han344d5432019-08-23 11:17:39 +0900320
Alex Light9670d332019-01-29 18:07:33 -0800321type apexMultilibProperties struct {
322 // Native dependencies whose compile_multilib is "first"
323 First apexNativeDependencies
324
325 // Native dependencies whose compile_multilib is "both"
326 Both apexNativeDependencies
327
328 // Native dependencies whose compile_multilib is "prefer32"
329 Prefer32 apexNativeDependencies
330
331 // Native dependencies whose compile_multilib is "32"
332 Lib32 apexNativeDependencies
333
334 // Native dependencies whose compile_multilib is "64"
335 Lib64 apexNativeDependencies
336}
337
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900338type apexBundleProperties struct {
339 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000340 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800341 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900342
Jiyong Park40e26a22019-02-08 02:53:06 +0900343 // AndroidManifest.xml file used for the zip container of this APEX bundle.
344 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800345 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900346
Roland Levillain411c5842019-09-19 16:37:20 +0100347 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
348 // device (/apex/<apex_name>).
349 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900350 Apex_name *string
351
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900352 // Determines the file contexts file for setting security context to each file in this APEX bundle.
353 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
354 // used.
355 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900356 File_contexts *string
357
358 // List of native shared libs that are embedded inside this APEX bundle
359 Native_shared_libs []string
360
Roland Levillain630846d2019-06-26 12:48:34 +0100361 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900362 Binaries []string
363
364 // List of java libraries that are embedded inside this APEX bundle
365 Java_libs []string
366
367 // List of prebuilt files that are embedded inside this APEX bundle
368 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900369
Roland Levillain630846d2019-06-26 12:48:34 +0100370 // List of tests that are embedded inside this APEX bundle
371 Tests []string
372
Jiyong Parkff1458f2018-10-12 21:49:38 +0900373 // Name of the apex_key module that provides the private key to sign APEX
374 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900375
Alex Light5098a612018-11-29 17:12:15 -0800376 // The type of APEX to build. Controls what the APEX payload is. Either
377 // 'image', 'zip' or 'both'. Default: 'image'.
378 Payload_type *string
379
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900380 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
381 // or an android_app_certificate module name in the form ":module".
382 Certificate *string
383
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900384 // Whether this APEX is installable to one of the partitions. Default: true.
385 Installable *bool
386
Jiyong Parkda6eb592018-12-19 17:12:36 +0900387 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
388 // Default is false.
389 Use_vendor *bool
390
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800391 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
392 Ignore_system_library_special_case *bool
393
Alex Light9670d332019-01-29 18:07:33 -0800394 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900395
Jiyong Parkf97782b2019-02-13 20:28:58 +0900396 // List of sanitizer names that this APEX is enabled for
397 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900398
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900399 PreventInstall bool `blueprint:"mutated"`
400
401 HideFromMake bool `blueprint:"mutated"`
402
Jooyung Han5c998b92019-06-27 11:30:33 +0900403 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
404 Provide_cpp_shared_libs *bool
405
406 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
407 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100408
409 // A txt file containing list of files that are whitelisted to be included in this APEX.
410 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900411
412 // List of APKs to package inside APEX
413 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900414
Sundong Ahne8fb7242019-09-17 13:50:45 +0900415 // To distinguish between flattened and non-flattened apex.
416 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900417 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900418
Sundong Ahne8fb7242019-09-17 13:50:45 +0900419 // if true, it means that TARGET_FLATTEN_APEX is true and
420 // TARGET_BUILD_APPS is false
421 FlattenedConfigValue bool `blueprint:"mutated"`
422
Jiyong Parkd1063c12019-07-17 20:08:41 +0900423 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
424 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
425 // is implied. This value affects all modules included in this APEX. In other words, they are
426 // also built with the SDKs specified here.
427 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800428}
429
430type apexTargetBundleProperties struct {
431 Target struct {
432 // Multilib properties only for android.
433 Android struct {
434 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900435 }
Jooyung Han344d5432019-08-23 11:17:39 +0900436
Alex Light9670d332019-01-29 18:07:33 -0800437 // Multilib properties only for host.
438 Host struct {
439 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900440 }
Jooyung Han344d5432019-08-23 11:17:39 +0900441
Alex Light9670d332019-01-29 18:07:33 -0800442 // Multilib properties only for host linux_bionic.
443 Linux_bionic struct {
444 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900445 }
Jooyung Han344d5432019-08-23 11:17:39 +0900446
Alex Light9670d332019-01-29 18:07:33 -0800447 // Multilib properties only for host linux_glibc.
448 Linux_glibc struct {
449 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900450 }
451 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900452}
453
Jooyung Han344d5432019-08-23 11:17:39 +0900454type apexVndkProperties struct {
455 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
456 Vndk_version *string
457}
458
Jiyong Park8fd61922018-11-08 02:50:25 +0900459type apexFileClass int
460
461const (
462 etc apexFileClass = iota
463 nativeSharedLib
464 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900465 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800466 pyBinary
467 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900468 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100469 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900470 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900471)
472
Alex Light5098a612018-11-29 17:12:15 -0800473type apexPackaging int
474
475const (
476 imageApex apexPackaging = iota
477 zipApex
478 both
479)
480
481func (a apexPackaging) image() bool {
482 switch a {
483 case imageApex, both:
484 return true
485 }
486 return false
487}
488
489func (a apexPackaging) zip() bool {
490 switch a {
491 case zipApex, both:
492 return true
493 }
494 return false
495}
496
497func (a apexPackaging) suffix() string {
498 switch a {
499 case imageApex:
500 return imageApexSuffix
501 case zipApex:
502 return zipApexSuffix
503 case both:
504 panic(fmt.Errorf("must be either zip or image"))
505 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100506 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800507 }
508}
509
510func (a apexPackaging) name() string {
511 switch a {
512 case imageApex:
513 return imageApexType
514 case zipApex:
515 return zipApexType
516 case both:
517 panic(fmt.Errorf("must be either zip or image"))
518 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100519 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800520 }
521}
522
Jiyong Park8fd61922018-11-08 02:50:25 +0900523func (class apexFileClass) NameInMake() string {
524 switch class {
525 case etc:
526 return "ETC"
527 case nativeSharedLib:
528 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800529 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900530 return "EXECUTABLES"
531 case javaSharedLib:
532 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100533 case nativeTest:
534 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900535 case app:
536 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900537 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100538 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900539 }
540}
541
542type apexFile struct {
543 builtFile android.Path
544 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900545 installDir string
546 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900547 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800548 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900549}
550
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900551type apexBundle struct {
552 android.ModuleBase
553 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900554 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900555
Alex Light9670d332019-01-29 18:07:33 -0800556 properties apexBundleProperties
557 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900558 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900559
Alex Light5098a612018-11-29 17:12:15 -0800560 apexTypes apexPackaging
561
Colin Crossa4925902018-11-16 11:36:28 -0800562 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800563 outputFiles map[apexPackaging]android.WritablePath
Roland Levillain935639d2019-08-13 14:55:28 +0100564 flattenedOutput android.OutputPath
Colin Crossa4925902018-11-16 11:36:28 -0800565 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900566
Jiyong Park03b68dd2019-07-26 23:20:40 +0900567 prebuiltFileToDelete string
568
Jiyong Park42cca6c2019-04-01 11:15:50 +0900569 public_key_file android.Path
570 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900571
572 container_certificate_file android.Path
573 container_private_key_file android.Path
574
Jiyong Park8fd61922018-11-08 02:50:25 +0900575 // list of files to be included in this apex
576 filesInfo []apexFile
577
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900578 // list of module names that this APEX is depending on
579 externalDeps []string
580
Alex Light0851b882019-02-07 13:20:53 -0800581 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900582 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900583
584 // intermediate path for apex_manifest.json
585 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900586}
587
Jiyong Park397e55e2018-10-24 21:09:55 +0900588func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100589 native_shared_libs []string, binaries []string, tests []string,
590 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900591 // Use *FarVariation* to be able to depend on modules having
592 // conflicting variations with this module. This is required since
593 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
594 // for native shared libs.
595 ctx.AddFarVariationDependencies([]blueprint.Variation{
596 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900597 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900598 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900599 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900600 }, sharedLibTag, native_shared_libs...)
601
602 ctx.AddFarVariationDependencies([]blueprint.Variation{
603 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900604 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900605 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100606
607 ctx.AddFarVariationDependencies([]blueprint.Variation{
608 {Mutator: "arch", Variation: arch},
609 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100610 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100611 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900612}
613
Alex Light9670d332019-01-29 18:07:33 -0800614func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
615 if ctx.Os().Class == android.Device {
616 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
617 } else {
618 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
619 if ctx.Os().Bionic() {
620 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
621 } else {
622 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
623 }
624 }
625}
626
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900627func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800628
Jiyong Park397e55e2018-10-24 21:09:55 +0900629 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900630 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800631
632 a.combineProperties(ctx)
633
Jiyong Park397e55e2018-10-24 21:09:55 +0900634 has32BitTarget := false
635 for _, target := range targets {
636 if target.Arch.ArchType.Multilib == "lib32" {
637 has32BitTarget = true
638 }
639 }
640 for i, target := range targets {
641 // When multilib.* is omitted for native_shared_libs, it implies
642 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900643 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900644 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900645 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900646 {Mutator: "link", Variation: "shared"},
647 }, sharedLibTag, a.properties.Native_shared_libs...)
648
Roland Levillain630846d2019-06-26 12:48:34 +0100649 // When multilib.* is omitted for tests, it implies
650 // multilib.both.
651 ctx.AddFarVariationDependencies([]blueprint.Variation{
652 {Mutator: "arch", Variation: target.String()},
653 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100654 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100655 }, testTag, a.properties.Tests...)
656
Jiyong Park397e55e2018-10-24 21:09:55 +0900657 // Add native modules targetting both ABIs
658 addDependenciesForNativeModules(ctx,
659 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100660 a.properties.Multilib.Both.Binaries,
661 a.properties.Multilib.Both.Tests,
662 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900663 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900664
Alex Light3d673592019-01-18 14:37:31 -0800665 isPrimaryAbi := i == 0
666 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900667 // When multilib.* is omitted for binaries, it implies
668 // multilib.first.
669 ctx.AddFarVariationDependencies([]blueprint.Variation{
670 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900671 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900672 }, executableTag, a.properties.Binaries...)
673
674 // Add native modules targetting the first ABI
675 addDependenciesForNativeModules(ctx,
676 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100677 a.properties.Multilib.First.Binaries,
678 a.properties.Multilib.First.Tests,
679 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900680 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800681
682 // When multilib.* is omitted for prebuilts, it implies multilib.first.
683 ctx.AddFarVariationDependencies([]blueprint.Variation{
684 {Mutator: "arch", Variation: target.String()},
685 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900686 }
687
688 switch target.Arch.ArchType.Multilib {
689 case "lib32":
690 // Add native modules targetting 32-bit ABI
691 addDependenciesForNativeModules(ctx,
692 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100693 a.properties.Multilib.Lib32.Binaries,
694 a.properties.Multilib.Lib32.Tests,
695 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900696 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900697
698 addDependenciesForNativeModules(ctx,
699 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100700 a.properties.Multilib.Prefer32.Binaries,
701 a.properties.Multilib.Prefer32.Tests,
702 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900703 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900704 case "lib64":
705 // Add native modules targetting 64-bit ABI
706 addDependenciesForNativeModules(ctx,
707 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100708 a.properties.Multilib.Lib64.Binaries,
709 a.properties.Multilib.Lib64.Tests,
710 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900711 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900712
713 if !has32BitTarget {
714 addDependenciesForNativeModules(ctx,
715 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100716 a.properties.Multilib.Prefer32.Binaries,
717 a.properties.Multilib.Prefer32.Tests,
718 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900719 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900720 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700721
722 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
723 for _, sanitizer := range ctx.Config().SanitizeDevice() {
724 if sanitizer == "hwaddress" {
725 addDependenciesForNativeModules(ctx,
726 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100727 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700728 break
729 }
730 }
731 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900732 }
733
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900734 }
735
Jiyong Parkff1458f2018-10-12 21:49:38 +0900736 ctx.AddFarVariationDependencies([]blueprint.Variation{
737 {Mutator: "arch", Variation: "android_common"},
738 }, javaLibTag, a.properties.Java_libs...)
739
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900740 ctx.AddFarVariationDependencies([]blueprint.Variation{
741 {Mutator: "arch", Variation: "android_common"},
742 }, androidAppTag, a.properties.Apps...)
743
Jiyong Park23c52b02019-02-02 13:13:47 +0900744 if String(a.properties.Key) == "" {
745 ctx.ModuleErrorf("key is missing")
746 return
747 }
748 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900749
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900750 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900751 if cert != "" {
752 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900753 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900754
755 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
756 if len(a.properties.Uses_sdks) > 0 {
757 sdkRefs := []android.SdkRef{}
758 for _, str := range a.properties.Uses_sdks {
759 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
760 sdkRefs = append(sdkRefs, parsed)
761 }
762 a.BuildWithSdks(sdkRefs)
763 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900764}
765
Colin Cross0ea8ba82019-06-06 14:33:29 -0700766func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900767 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
768 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000769 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900770 }
771 return String(a.properties.Certificate)
772}
773
Colin Cross41955e82019-05-29 14:40:35 -0700774func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
775 switch tag {
776 case "":
777 if file, ok := a.outputFiles[imageApex]; ok {
778 return android.Paths{file}, nil
779 } else {
780 return nil, nil
781 }
Roland Levillain935639d2019-08-13 14:55:28 +0100782 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900783 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100784 flattenedApexPath := a.flattenedOutput
785 return android.Paths{flattenedApexPath}, nil
786 } else {
787 return nil, nil
788 }
Colin Cross41955e82019-05-29 14:40:35 -0700789 default:
790 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900791 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900792}
793
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900794func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900795 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900796}
797
Jiyong Park7c1dc612019-01-05 11:15:24 +0900798func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
799 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900800 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900801 } else {
802 return "core"
803 }
804}
805
Jiyong Parkf97782b2019-02-13 20:28:58 +0900806func (a *apexBundle) EnableSanitizer(sanitizerName string) {
807 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
808 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
809 }
810}
811
Jiyong Park388ef3f2019-01-28 19:47:32 +0900812func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900813 if android.InList(sanitizerName, a.properties.SanitizerNames) {
814 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900815 }
816
817 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900818 globalSanitizerNames := []string{}
819 if a.Host() {
820 globalSanitizerNames = ctx.Config().SanitizeHost()
821 } else {
822 arches := ctx.Config().SanitizeDeviceArch()
823 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
824 globalSanitizerNames = ctx.Config().SanitizeDevice()
825 }
826 }
827 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900828}
829
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900830func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
831 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
832}
833
834func (a *apexBundle) PreventInstall() {
835 a.properties.PreventInstall = true
836}
837
838func (a *apexBundle) HideFromMake() {
839 a.properties.HideFromMake = true
840}
841
Sundong Ahne9b55722019-09-06 17:37:42 +0900842func (a *apexBundle) SetFlattened(flattened bool) {
843 a.properties.Flattened = flattened
844}
845
Sundong Ahne8fb7242019-09-17 13:50:45 +0900846func (a *apexBundle) SetFlattenedConfigValue() {
847 a.properties.FlattenedConfigValue = true
848}
849
850// isFlattenedVariant returns true when the current module is the flattened
851// variant of an apex that has both a flattened and an unflattened variant.
852// It returns false when the current module is flattened but there is no
853// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
854// true. It can be used to avoid collisions between the install paths of the
855// flattened and unflattened variants.
856func (a *apexBundle) isFlattenedVariant() bool {
857 return a.properties.Flattened && !a.properties.FlattenedConfigValue
858}
859
Martin Stjernholm279de572019-09-10 23:18:20 +0100860func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861 // Decide the APEX-local directory by the multilib of the library
862 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100863 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900864 case "lib32":
865 dirInApex = "lib"
866 case "lib64":
867 dirInApex = "lib64"
868 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100869 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
870 if !ccMod.Arch().Native {
871 dirInApex = filepath.Join(dirInApex, ccMod.Arch().ArchType.String())
872 } else if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
873 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900874 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100875 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
876 // Special case for Bionic libs and other libs installed with them. This is
877 // to prevent those libs from being included in the search path
878 // /apex/com.android.runtime/${LIB}. This exclusion is required because
879 // those libs in the Runtime APEX are available via the legacy paths in
880 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
881 // to the legacy paths and thus will be loaded into the default linker
882 // namespace (aka "platform" namespace). If the libs are directly in
883 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
884 // into the runtime linker namespace, which will result in double loading of
885 // them, which isn't supported.
886 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900887 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900888
Martin Stjernholm279de572019-09-10 23:18:20 +0100889 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900890 return
891}
892
893func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900894 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200895 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900896 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200897 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
898 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900899 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900900 fileToCopy = cc.OutputFile().Path()
901 return
902}
903
Alex Light778127a2019-02-27 14:19:50 -0800904func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
905 dirInApex = "bin"
906 fileToCopy = py.HostToolPath().Path()
907 return
908}
909func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
910 dirInApex = "bin"
911 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
912 if err != nil {
913 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
914 return
915 }
916 fileToCopy = android.PathForOutput(ctx, s)
917 return
918}
919
Jiyong Park04480cf2019-02-06 00:16:29 +0900920func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
921 dirInApex = filepath.Join("bin", sh.SubDir())
922 fileToCopy = sh.OutputFile()
923 return
924}
925
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900926func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
927 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900928 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900929 return
930}
931
Jiyong Park9e6c2422019-08-09 20:39:45 +0900932func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
933 dirInApex = "javalib"
934 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
935 implJars := java.ImplementationJars()
936 if len(implJars) != 1 {
937 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
938 strings.Join(implJars.Strings(), ", ")))
939 }
940 fileToCopy = implJars[0]
941 return
942}
943
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900944func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
945 dirInApex = filepath.Join("etc", prebuilt.SubDir())
946 fileToCopy = prebuilt.OutputFile()
947 return
948}
949
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900950func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
951 dirInApex = filepath.Join("app", pkgName)
952 fileToCopy = app.OutputFile()
953 return
954}
955
Roland Levillain935639d2019-08-13 14:55:28 +0100956// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
957type flattenedApexContext struct {
958 android.ModuleContext
959}
960
961func (c *flattenedApexContext) InstallBypassMake() bool {
962 return true
963}
964
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900966 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900967
Alex Light5098a612018-11-29 17:12:15 -0800968 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
969 a.apexTypes = imageApex
970 } else if *a.properties.Payload_type == "zip" {
971 a.apexTypes = zipApex
972 } else if *a.properties.Payload_type == "both" {
973 a.apexTypes = both
974 } else {
975 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
976 return
977 }
978
Roland Levillain630846d2019-06-26 12:48:34 +0100979 if len(a.properties.Tests) > 0 && !a.testApex {
980 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
981 return
982 }
983
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800984 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
985
Jooyung Hane1633032019-08-01 17:41:43 +0900986 // native lib dependencies
987 var provideNativeLibs []string
988 var requireNativeLibs []string
989
Jooyung Han5c998b92019-06-27 11:30:33 +0900990 // Check if "uses" requirements are met with dependent apexBundles
991 var providedNativeSharedLibs []string
992 useVendor := proptools.Bool(a.properties.Use_vendor)
993 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
994 if ctx.OtherModuleDependencyTag(m) != usesTag {
995 return
996 }
997 otherName := ctx.OtherModuleName(m)
998 other, ok := m.(*apexBundle)
999 if !ok {
1000 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1001 return
1002 }
1003 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1004 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1005 return
1006 }
1007 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1008 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1009 return
1010 }
1011 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1012 })
1013
Alex Light778127a2019-02-27 14:19:50 -08001014 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001015 depTag := ctx.OtherModuleDependencyTag(child)
1016 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017 if _, ok := parent.(*apexBundle); ok {
1018 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001019 switch depTag {
1020 case sharedLibTag:
1021 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001022 if cc.HasStubsVariants() {
1023 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1024 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001025 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001026 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001027 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001028 } else {
1029 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001030 }
1031 case executableTag:
1032 if cc, ok := child.(*cc.Module); ok {
1033 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001034 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001035 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001036 } else if sh, ok := child.(*android.ShBinary); ok {
1037 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
1038 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -08001039 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1040 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1041 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1042 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1043 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1044 // NB: Since go binaries are static we don't need the module for anything here, which is
1045 // good since the go tool is a blueprint.Module not an android.Module like we would
1046 // normally use.
1047 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001048 } else {
Alex Light778127a2019-02-27 14:19:50 -08001049 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 +09001050 }
1051 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001052 if javaLib, ok := child.(*java.Library); ok {
1053 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001054 if fileToCopy == nil {
1055 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1056 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001057 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1058 }
1059 return true
1060 } else if javaLib, ok := child.(*java.Import); ok {
1061 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1062 if fileToCopy == nil {
1063 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1064 } else {
1065 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001066 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001067 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001068 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001069 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001070 }
1071 case prebuiltTag:
1072 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1073 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001074 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001075 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001076 } else {
1077 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1078 }
Roland Levillain630846d2019-06-26 12:48:34 +01001079 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001080 if ccTest, ok := child.(*cc.Module); ok {
1081 if ccTest.IsTestPerSrcAllTestsVariation() {
1082 // Multiple-output test module (where `test_per_src: true`).
1083 //
1084 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1085 // We do not add this variation to `filesInfo`, as it has no output;
1086 // however, we do add the other variations of this module as indirect
1087 // dependencies (see below).
1088 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001089 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001090 // Single-output test module (where `test_per_src: false`).
1091 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1092 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001093 }
Roland Levillain630846d2019-06-26 12:48:34 +01001094 return true
1095 } else {
1096 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1097 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001098 case keyTag:
1099 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001100 a.private_key_file = key.private_key_file
1101 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001102 return false
1103 } else {
1104 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001105 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001106 case certificateTag:
1107 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001108 a.container_certificate_file = dep.Certificate.Pem
1109 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001110 return false
1111 } else {
1112 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1113 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001114 case android.PrebuiltDepTag:
1115 // If the prebuilt is force disabled, remember to delete the prebuilt file
1116 // that might have been installed in the previous builds
1117 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1118 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1119 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001120 case androidAppTag:
1121 if ap, ok := child.(*java.AndroidApp); ok {
1122 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1123 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1124 return true
1125 } else {
1126 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1127 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001128 }
1129 } else {
1130 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001131 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001132 // We cannot use a switch statement on `depTag` here as the checked
1133 // tags used below are private (e.g. `cc.sharedDepTag`).
1134 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1135 if cc, ok := child.(*cc.Module); ok {
1136 if android.InList(cc.Name(), providedNativeSharedLibs) {
1137 // If we're using a shared library which is provided from other APEX,
1138 // don't include it in this APEX
1139 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001140 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001141 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1142 // If the dependency is a stubs lib, don't include it in this APEX,
1143 // but make sure that the lib is installed on the device.
1144 // In case no APEX is having the lib, the lib is installed to the system
1145 // partition.
1146 //
1147 // Always include if we are a host-apex however since those won't have any
1148 // system libraries.
1149 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1150 a.externalDeps = append(a.externalDeps, cc.Name())
1151 }
Jooyung Hane1633032019-08-01 17:41:43 +09001152 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001153 // Don't track further
1154 return false
1155 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001156 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001157 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1158 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001159 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001160 } else if cc.IsTestPerSrcDepTag(depTag) {
1161 if cc, ok := child.(*cc.Module); ok {
1162 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1163 // Handle modules created as `test_per_src` variations of a single test module:
1164 // use the name of the generated test binary (`fileToCopy`) instead of the name
1165 // of the original test module (`depName`, shared by all `test_per_src`
1166 // variations of that module).
1167 moduleName := filepath.Base(fileToCopy.String())
1168 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1169 return true
1170 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001171 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001172 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Sundong Ahn2db7f462019-08-27 18:53:12 +09001173 } else if am.NoApex() && !android.InList(depName, whitelistNoApex[ctx.ModuleName()]) {
1174 ctx.ModuleErrorf("tries to include no_apex module %s", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001175 }
1176 }
1177 }
1178 return false
1179 })
1180
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001181 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001182 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1183 return
1184 }
1185
Jiyong Park8fd61922018-11-08 02:50:25 +09001186 // remove duplicates in filesInfo
1187 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001188 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001189 result := []apexFile{}
1190 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001191 dest := filepath.Join(f.installDir, f.builtFile.Base())
1192 if !encountered[dest] {
1193 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001194 result = append(result, f)
1195 }
1196 }
1197 return result
1198 }
1199 filesInfo = removeDup(filesInfo)
1200
1201 // to have consistent build rules
1202 sort.Slice(filesInfo, func(i, j int) bool {
1203 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1204 })
1205
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09001206 // check no_apex modules
1207 whitelist := whitelistNoApex[ctx.ModuleName()]
1208 for i := range filesInfo {
1209 if am, ok := filesInfo[i].module.(android.ApexModule); ok {
1210 if am.NoApex() && !android.InList(filesInfo[i].moduleName, whitelist) {
1211 ctx.ModuleErrorf("tries to include no_apex module %s", filesInfo[i].moduleName)
1212 }
1213 }
1214 }
1215
Jiyong Park8fd61922018-11-08 02:50:25 +09001216 // prepend the name of this APEX to the module names. These names will be the names of
1217 // modules that will be defined if the APEX is flattened.
1218 for i := range filesInfo {
1219 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
1220 }
1221
Jiyong Park8fd61922018-11-08 02:50:25 +09001222 a.installDir = android.PathForModuleInstall(ctx, "apex")
1223 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001224
Jooyung Hane1633032019-08-01 17:41:43 +09001225 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
1226 // put dependency({provide|require}NativeLibs) in apex_manifest.json
1227 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
1228 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1229 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
1230 ctx.Build(pctx, android.BuildParams{
1231 Rule: injectApexDependency,
1232 Input: manifestSrc,
1233 Output: a.manifestOut,
1234 Args: map[string]string{
1235 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1236 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
1237 },
1238 })
1239
Roland Levillain935639d2019-08-13 14:55:28 +01001240 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1241 // reply true to `InstallBypassMake()` (thus making the call
1242 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1243 // instead of `android.PathForOutput`) to return the correct path to the flattened
1244 // APEX (as its contents is installed by Make, not Soong).
1245 factx := flattenedApexContext{ctx}
1246 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
1247
Alex Light5098a612018-11-29 17:12:15 -08001248 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001249 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001250 }
1251 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001252 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001253 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001254 // in other modules. It is in AndroidMk where the selection of flattened
1255 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001256 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001257 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001258 }
1259}
1260
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001261func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001262 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001263 for _, f := range a.filesInfo {
1264 if f.module != nil {
1265 notice := f.module.NoticeFile()
1266 if notice.Valid() {
1267 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001268 }
1269 }
1270 }
1271 // append the notice file specified in the apex module itself
1272 if a.NoticeFile().Valid() {
1273 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001274 }
1275
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001276 if len(noticeFiles) == 0 {
1277 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001278 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001279
Jaewoong Jung98772792019-07-01 17:15:13 -07001280 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001281}
1282
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001283func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001284 cert := String(a.properties.Certificate)
1285 if cert != "" && android.SrcIsModule(cert) == "" {
1286 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001287 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1288 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001289 } else if cert == "" {
1290 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001291 a.container_certificate_file = pem
1292 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001293 }
1294
Alex Light5098a612018-11-29 17:12:15 -08001295 var abis []string
1296 for _, target := range ctx.MultiTargets() {
1297 if len(target.Arch.Abi) > 0 {
1298 abis = append(abis, target.Arch.Abi[0])
1299 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001300 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001301
Alex Light5098a612018-11-29 17:12:15 -08001302 abis = android.FirstUniqueStrings(abis)
1303
1304 suffix := apexType.suffix()
1305 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001306
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001307 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001308 for _, f := range a.filesInfo {
1309 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001310 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001311
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001312 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001313 emitCommands := []string{}
1314 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1315 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001316 for i, src := range filesToCopy {
1317 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001318 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001319 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001320 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1321 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001322 for _, sym := range a.filesInfo[i].symlinks {
1323 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1324 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1325 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001326 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001327 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001328 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001329
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001330 if a.properties.Whitelisted_files != nil {
1331 ctx.Build(pctx, android.BuildParams{
1332 Rule: emitApexContentRule,
1333 Implicits: implicitInputs,
1334 Output: imageContentFile,
1335 Description: "emit apex image content",
1336 Args: map[string]string{
1337 "emit_commands": strings.Join(emitCommands, " && "),
1338 },
1339 })
1340 implicitInputs = append(implicitInputs, imageContentFile)
1341 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1342
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001343 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001344 ctx.Build(pctx, android.BuildParams{
1345 Rule: diffApexContentRule,
1346 Implicits: implicitInputs,
1347 Output: phonyOutput,
1348 Description: "diff apex image content",
1349 Args: map[string]string{
1350 "whitelisted_files_file": whitelistedFilesFile.String(),
1351 "image_content_file": imageContentFile.String(),
1352 "apex_module_name": ctx.ModuleName(),
1353 },
1354 })
1355
1356 implicitInputs = append(implicitInputs, phonyOutput)
1357 }
1358
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001359 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1360 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001361
Alex Light5098a612018-11-29 17:12:15 -08001362 if apexType.image() {
1363 // files and dirs that will be created in APEX
1364 var readOnlyPaths []string
1365 var executablePaths []string // this also includes dirs
1366 for _, f := range a.filesInfo {
1367 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001368 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001369 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001370 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001371 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001372 }
Alex Light5098a612018-11-29 17:12:15 -08001373 } else {
1374 readOnlyPaths = append(readOnlyPaths, pathInApex)
1375 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001376 dir := f.installDir
1377 for !android.InList(dir, executablePaths) && dir != "" {
1378 executablePaths = append(executablePaths, dir)
1379 dir, _ = filepath.Split(dir) // move up to the parent
1380 if len(dir) > 0 {
1381 // remove trailing slash
1382 dir = dir[:len(dir)-1]
1383 }
Alex Light5098a612018-11-29 17:12:15 -08001384 }
1385 }
1386 sort.Strings(readOnlyPaths)
1387 sort.Strings(executablePaths)
1388 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1389 ctx.Build(pctx, android.BuildParams{
1390 Rule: generateFsConfig,
1391 Output: cannedFsConfig,
1392 Description: "generate fs config",
1393 Args: map[string]string{
1394 "ro_paths": strings.Join(readOnlyPaths, " "),
1395 "exec_paths": strings.Join(executablePaths, " "),
1396 },
1397 })
1398
1399 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1400 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1401 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1402 if !fileContextsOptionalPath.Valid() {
1403 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1404 return
1405 }
1406 fileContexts := fileContextsOptionalPath.Path()
1407
Jiyong Park835d82b2018-12-27 16:04:18 +09001408 optFlags := []string{}
1409
Alex Light5098a612018-11-29 17:12:15 -08001410 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001411 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1412 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001413
Jiyong Park7f67f482019-01-05 12:57:48 +09001414 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1415 if overridden {
1416 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1417 }
1418
Jiyong Park40e26a22019-02-08 02:53:06 +09001419 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001420 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001421 implicitInputs = append(implicitInputs, androidManifestFile)
1422 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1423 }
1424
Jiyong Park71b519d2019-04-18 17:25:49 +09001425 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1426 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1427 ctx.Config().UnbundledBuild() &&
1428 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1429 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1430 apiFingerprint := java.ApiFingerprintPath(ctx)
1431 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1432 implicitInputs = append(implicitInputs, apiFingerprint)
1433 }
1434 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1435
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001436 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1437 if noticeFile.Valid() {
1438 // If there's a NOTICE file, embed it as an asset file in the APEX.
1439 implicitInputs = append(implicitInputs, noticeFile.Path())
1440 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1441 }
1442
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001443 if !ctx.Config().UnbundledBuild() && a.installable() {
1444 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1445 // don't need hashtree for activation. Therefore, by removing hashtree from
1446 // apex bundle (filesystem image in it, to be specific), we can save storage.
1447 optFlags = append(optFlags, "--no_hashtree")
1448 }
1449
Alex Light5098a612018-11-29 17:12:15 -08001450 ctx.Build(pctx, android.BuildParams{
1451 Rule: apexRule,
1452 Implicits: implicitInputs,
1453 Output: unsignedOutputFile,
1454 Description: "apex (" + apexType.name() + ")",
1455 Args: map[string]string{
1456 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1457 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1458 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001459 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001460 "file_contexts": fileContexts.String(),
1461 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001462 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001463 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001464 },
1465 })
1466
1467 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1468 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1469 a.bundleModuleFile = bundleModuleFile
1470
1471 ctx.Build(pctx, android.BuildParams{
1472 Rule: apexProtoConvertRule,
1473 Input: unsignedOutputFile,
1474 Output: apexProtoFile,
1475 Description: "apex proto convert",
1476 })
1477
1478 ctx.Build(pctx, android.BuildParams{
1479 Rule: apexBundleRule,
1480 Input: apexProtoFile,
1481 Output: a.bundleModuleFile,
1482 Description: "apex bundle module",
1483 Args: map[string]string{
1484 "abi": strings.Join(abis, "."),
1485 },
1486 })
1487 } else {
1488 ctx.Build(pctx, android.BuildParams{
1489 Rule: zipApexRule,
1490 Implicits: implicitInputs,
1491 Output: unsignedOutputFile,
1492 Description: "apex (" + apexType.name() + ")",
1493 Args: map[string]string{
1494 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1495 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1496 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001497 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001498 },
1499 })
Colin Crossa4925902018-11-16 11:36:28 -08001500 }
Colin Crossa4925902018-11-16 11:36:28 -08001501
Alex Light5098a612018-11-29 17:12:15 -08001502 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001503 ctx.Build(pctx, android.BuildParams{
1504 Rule: java.Signapk,
1505 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001506 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001507 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001508 Implicits: []android.Path{
1509 a.container_certificate_file,
1510 a.container_private_key_file,
1511 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001512 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001513 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001514 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001515 },
1516 })
Alex Light5098a612018-11-29 17:12:15 -08001517
1518 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001519 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001520 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001521 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001522}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001523
Jiyong Park8fd61922018-11-08 02:50:25 +09001524func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001525 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001526 // 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 +09001527 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001528 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001529
Jiyong Park42cca6c2019-04-01 11:15:50 +09001530 // rename to apex_pubkey
1531 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1532 ctx.Build(pctx, android.BuildParams{
1533 Rule: android.Cp,
1534 Input: a.public_key_file,
1535 Output: copiedPubkey,
1536 })
1537 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1538
Jiyong Park23c52b02019-02-02 13:13:47 +09001539 if ctx.Config().FlattenApex() {
1540 for _, fi := range a.filesInfo {
1541 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001542 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1543 for _, sym := range fi.symlinks {
1544 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1545 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001546 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001547 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001548 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001549}
1550
1551func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001552 if a.properties.HideFromMake {
1553 return android.AndroidMkData{
1554 Disabled: true,
1555 }
1556 }
Alex Light5098a612018-11-29 17:12:15 -08001557 writers := []android.AndroidMkData{}
1558 if a.apexTypes.image() {
1559 writers = append(writers, a.androidMkForType(imageApex))
1560 }
1561 if a.apexTypes.zip() {
1562 writers = append(writers, a.androidMkForType(zipApex))
1563 }
1564 return android.AndroidMkData{
1565 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1566 for _, data := range writers {
1567 data.Custom(w, name, prefix, moduleDir, data)
1568 }
1569 }}
1570}
1571
Alex Lightf1801bc2019-02-13 11:10:07 -08001572func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001573 moduleNames := []string{}
1574
1575 for _, fi := range a.filesInfo {
1576 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1577 continue
1578 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001579 if a.properties.Flattened && !apexType.image() {
1580 continue
Jiyong Park94427262019-02-05 23:18:47 +09001581 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001582
1583 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001584 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001585 suffix = ".flattened"
1586 }
1587
1588 if !android.InList(fi.moduleName, moduleNames) {
1589 moduleNames = append(moduleNames, fi.moduleName+suffix)
1590 }
1591
Jiyong Park94427262019-02-05 23:18:47 +09001592 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1593 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001594 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001595 // /apex/<apex_name>/{lib|framework|...}
Jiyong Park05e70dd2019-03-18 14:26:32 +09001596 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1597 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001598 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001599 // /system/apex/<name>/{lib|framework|...}
1600 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1601 a.installDir.RelPathString(), name, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001602 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001603 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1604 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001605 if len(fi.symlinks) > 0 {
1606 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1607 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001608
1609 if fi.module != nil && fi.module.NoticeFile().Valid() {
1610 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1611 }
Jiyong Park94427262019-02-05 23:18:47 +09001612 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001613 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001614 }
1615 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1616 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1617 if fi.module != nil {
1618 archStr := fi.module.Target().Arch.ArchType.String()
1619 host := false
1620 switch fi.module.Target().Os.Class {
1621 case android.Host:
1622 if archStr != "common" {
1623 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1624 }
1625 host = true
1626 case android.HostCross:
1627 if archStr != "common" {
1628 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1629 }
1630 host = true
1631 case android.Device:
1632 if archStr != "common" {
1633 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1634 }
1635 }
1636 if host {
1637 makeOs := fi.module.Target().Os.String()
1638 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1639 makeOs = "linux"
1640 }
1641 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1642 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1643 }
1644 }
1645 if fi.class == javaSharedLib {
1646 javaModule := fi.module.(*java.Library)
1647 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1648 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1649 // we will have foo.jar.jar
1650 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1651 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1652 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1653 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1654 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1655 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001656 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001657 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001658 if cc, ok := fi.module.(*cc.Module); ok {
1659 if cc.UnstrippedOutputFile() != nil {
1660 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1661 }
1662 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001663 if cc.CoverageOutputFile().Valid() {
1664 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1665 }
Jiyong Park94427262019-02-05 23:18:47 +09001666 }
1667 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1668 } else {
1669 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1670 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1671 }
1672 }
1673 return moduleNames
1674}
1675
Alex Light5098a612018-11-29 17:12:15 -08001676func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001677 return android.AndroidMkData{
1678 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1679 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001680 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001681 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001682 }
1683
Sundong Ahne8fb7242019-09-17 13:50:45 +09001684 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001685 name = name + ".flattened"
1686 }
1687
1688 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001689 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001690 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1691 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1692 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001693 if len(moduleNames) > 0 {
1694 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1695 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001696 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001697 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1698
Sundong Ahne8fb7242019-09-17 13:50:45 +09001699 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001700 // zip-apex is the less common type so have the name refer to the image-apex
1701 // only and use {name}.zip if you want the zip-apex
1702 if apexType == zipApex && a.apexTypes == both {
1703 name = name + ".zip"
1704 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001705 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1706 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1707 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1708 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001709 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001710 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001711 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001712 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001713 if len(moduleNames) > 0 {
1714 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1715 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001716 if len(a.externalDeps) > 0 {
1717 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1718 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001719 if a.prebuiltFileToDelete != "" {
1720 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1721 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1722 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001723 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001724
Alex Light5098a612018-11-29 17:12:15 -08001725 if apexType == imageApex {
1726 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1727 }
Jiyong Park719b4462019-01-13 00:39:51 +09001728 }
1729 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001730}
1731
Jooyung Han344d5432019-08-23 11:17:39 +09001732func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001733 module := &apexBundle{
1734 outputFiles: map[apexPackaging]android.WritablePath{},
1735 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001736 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001737 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001738 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001739 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1740 })
Alex Light5098a612018-11-29 17:12:15 -08001741 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001742 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001743 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001744 return module
1745}
Jiyong Park30ca9372019-02-07 16:27:23 +09001746
Jooyung Han344d5432019-08-23 11:17:39 +09001747func ApexBundleFactory(testApex bool) android.Module {
1748 bundle := newApexBundle()
1749 bundle.testApex = testApex
1750 return bundle
1751}
1752
1753func testApexBundleFactory() android.Module {
1754 bundle := newApexBundle()
1755 bundle.testApex = true
1756 return bundle
1757}
1758
Jiyong Parkd1063c12019-07-17 20:08:41 +09001759func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001760 return newApexBundle()
1761}
1762
1763// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1764// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1765// If not specified, then the "current" versions are gathered.
1766func vndkApexBundleFactory() android.Module {
1767 bundle := newApexBundle()
1768 bundle.vndkApex = true
1769 bundle.AddProperties(&bundle.vndkProperties)
1770 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1771 ctx.AppendProperties(&struct {
1772 Compile_multilib *string
1773 }{
1774 proptools.StringPtr("both"),
1775 })
1776 })
1777 return bundle
1778}
1779
Jiyong Park30ca9372019-02-07 16:27:23 +09001780//
1781// Defaults
1782//
1783type Defaults struct {
1784 android.ModuleBase
1785 android.DefaultsModuleBase
1786}
1787
Jiyong Park30ca9372019-02-07 16:27:23 +09001788func defaultsFactory() android.Module {
1789 return DefaultsFactory()
1790}
1791
1792func DefaultsFactory(props ...interface{}) android.Module {
1793 module := &Defaults{}
1794
1795 module.AddProperties(props...)
1796 module.AddProperties(
1797 &apexBundleProperties{},
1798 &apexTargetBundleProperties{},
1799 )
1800
1801 android.InitDefaultsModule(module)
1802 return module
1803}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001804
1805//
1806// Prebuilt APEX
1807//
1808type Prebuilt struct {
1809 android.ModuleBase
1810 prebuilt android.Prebuilt
1811
1812 properties PrebuiltProperties
1813
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001814 inputApex android.Path
1815 installDir android.OutputPath
1816 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001817 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001818}
1819
1820type PrebuiltProperties struct {
1821 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001822 Source string `blueprint:"mutated"`
1823 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001824
1825 Src *string
1826 Arch struct {
1827 Arm struct {
1828 Src *string
1829 }
1830 Arm64 struct {
1831 Src *string
1832 }
1833 X86 struct {
1834 Src *string
1835 }
1836 X86_64 struct {
1837 Src *string
1838 }
1839 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001840
1841 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001842 // Optional name for the installed apex. If unspecified, name of the
1843 // module is used as the file name
1844 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001845
1846 // Names of modules to be overridden. Listed modules can only be other binaries
1847 // (in Make or Soong).
1848 // This does not completely prevent installation of the overridden binaries, but if both
1849 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1850 // from PRODUCT_PACKAGES.
1851 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001852}
1853
1854func (p *Prebuilt) installable() bool {
1855 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001856}
1857
1858func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001859 // If the device is configured to use flattened APEX, force disable the prebuilt because
1860 // the prebuilt is a non-flattened one.
1861 forceDisable := ctx.Config().FlattenApex()
1862
1863 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1864 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001865 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001866
Kun Niu10c9f832019-07-29 16:28:57 -07001867 // Force disable the prebuilts when coverage is enabled.
1868 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1869 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1870
Jiyong Park50b81e52019-07-11 11:24:41 +09001871 // b/137216042 don't use prebuilts when address sanitizer is on
1872 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1873 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1874
1875 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001876 p.properties.ForceDisable = true
1877 return
1878 }
1879
Jiyong Parkc95714e2019-03-29 14:23:10 +09001880 // This is called before prebuilt_select and prebuilt_postdeps mutators
1881 // The mutators requires that src to be set correctly for each arch so that
1882 // arch variants are disabled when src is not provided for the arch.
1883 if len(ctx.MultiTargets()) != 1 {
1884 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1885 return
1886 }
1887 var src string
1888 switch ctx.MultiTargets()[0].Arch.ArchType {
1889 case android.Arm:
1890 src = String(p.properties.Arch.Arm.Src)
1891 case android.Arm64:
1892 src = String(p.properties.Arch.Arm64.Src)
1893 case android.X86:
1894 src = String(p.properties.Arch.X86.Src)
1895 case android.X86_64:
1896 src = String(p.properties.Arch.X86_64.Src)
1897 default:
1898 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1899 return
1900 }
1901 if src == "" {
1902 src = String(p.properties.Src)
1903 }
1904 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001905}
1906
Jiyong Park03b68dd2019-07-26 23:20:40 +09001907func (p *Prebuilt) isForceDisabled() bool {
1908 return p.properties.ForceDisable
1909}
1910
Colin Cross41955e82019-05-29 14:40:35 -07001911func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1912 switch tag {
1913 case "":
1914 return android.Paths{p.outputApex}, nil
1915 default:
1916 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1917 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001918}
1919
Jiyong Park4d277042019-04-23 18:00:10 +09001920func (p *Prebuilt) InstallFilename() string {
1921 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1922}
1923
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001924func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001925 if p.properties.ForceDisable {
1926 return
1927 }
1928
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001929 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001930 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001931 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001932 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001933 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1934 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1935 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001936 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1937 ctx.Build(pctx, android.BuildParams{
1938 Rule: android.Cp,
1939 Input: p.inputApex,
1940 Output: p.outputApex,
1941 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001942 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001943 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001944 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001945}
1946
1947func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1948 return &p.prebuilt
1949}
1950
1951func (p *Prebuilt) Name() string {
1952 return p.prebuilt.Name(p.ModuleBase.Name())
1953}
1954
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001955func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1956 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001957 Class: "ETC",
1958 OutputFile: android.OptionalPathForPath(p.inputApex),
1959 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001960 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1961 func(entries *android.AndroidMkEntries) {
1962 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1963 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1964 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1965 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
1966 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001967 },
1968 }
1969}
1970
1971// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1972func PrebuiltFactory() android.Module {
1973 module := &Prebuilt{}
1974 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001975 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001976 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001977 return module
1978}