blob: 5f714259b6006f1d18d83fea59e419a7ca399d4c [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
19 "io"
20 "path/filepath"
21 "runtime"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
36var (
37 pctx = android.NewPackageContext("android/apex")
38
39 // Create a canned fs config file where all files and directories are
40 // by default set to (uid/gid/mode) = (1000/1000/0644)
41 // TODO(b/113082813) make this configurable using config.fs syntax
42 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000043 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000044 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090045 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090046 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090047 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090048 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090049
Jooyung Hand15aa1f2019-09-27 00:38:03 +090050 apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
Jooyung Hane1633032019-08-01 17:41:43 +090051 Command: `rm -f $out && ${jsonmodify} $in ` +
52 `-a provideNativeLibs ${provideNativeLibs} ` +
Jooyung Hand15aa1f2019-09-27 00:38:03 +090053 `-a requireNativeLibs ${requireNativeLibs} ` +
54 `${opt} ` +
55 `-o $out`,
Jooyung Hane1633032019-08-01 17:41:43 +090056 CommandDeps: []string{"${jsonmodify}"},
Jooyung Hand15aa1f2019-09-27 00:38:03 +090057 Description: "prepare ${out}",
58 }, "provideNativeLibs", "requireNativeLibs", "opt")
Jooyung Hane1633032019-08-01 17:41:43 +090059
Jiyong Park48ca7dc2018-10-10 14:01:00 +090060 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
61 // against the binary policy using sefcontext_compiler -p <policy>.
62
63 // TODO(b/114327326): automate the generation of file_contexts
64 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
65 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010066 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090068 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069 `--file_contexts ${file_contexts} ` +
70 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080071 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090072 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090073 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
74 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000075 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010076 Rspfile: "${out}.copy_commands",
77 RspfileContent: "${copy_commands}",
78 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090079 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080080
Alex Light5098a612018-11-29 17:12:15 -080081 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
82 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010083 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080084 `APEXER_TOOL_PATH=${tool_path} ` +
85 `${apexer} --force --manifest ${manifest} ` +
86 `--payload_type zip ` +
87 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010088 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
89 Rspfile: "${out}.copy_commands",
90 RspfileContent: "${copy_commands}",
91 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080092 }, "tool_path", "image_dir", "copy_commands", "manifest")
93
Colin Crossa4925902018-11-16 11:36:28 -080094 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
95 blueprint.RuleParams{
96 Command: `${aapt2} convert --output-format proto $in -o $out`,
97 CommandDeps: []string{"${aapt2}"},
98 })
99
100 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +0900101 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +0000102 `apex_payload.img:apex/${abi}.img ` +
103 `apex_manifest.json:root/apex_manifest.json ` +
Jaewoong Jungb00c1fb2019-09-04 13:26:18 -0700104 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
105 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
Colin Crossa4925902018-11-16 11:36:28 -0800106 CommandDeps: []string{"${zip2zip}"},
107 Description: "app bundle",
108 }, "abi")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100109
110 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
111 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
112 Rspfile: "${out}.emit_commands",
113 RspfileContent: "${emit_commands}",
114 Description: "Emit APEX image content",
115 }, "emit_commands")
116
117 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
118 Command: `diff --unchanged-group-format='' \` +
119 `--changed-group-format='%<' \` +
120 `${image_content_file} ${whitelisted_files_file} || (` +
121 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
122 ` "To fix the build run following command:" && ` +
123 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
124 `exit 1)`,
125 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
126 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900127)
128
Alex Light5098a612018-11-29 17:12:15 -0800129var imageApexSuffix = ".apex"
130var zipApexSuffix = ".zipapex"
131
132var imageApexType = "image"
133var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900134
135type dependencyTag struct {
136 blueprint.BaseDependencyTag
137 name string
138}
139
140var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900141 sharedLibTag = dependencyTag{name: "sharedLib"}
142 executableTag = dependencyTag{name: "executable"}
143 javaLibTag = dependencyTag{name: "javaLib"}
144 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100145 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900146 keyTag = dependencyTag{name: "key"}
147 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900148 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900149 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900150)
151
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900152var (
153 whitelistNoApex = map[string][]string{
154 "apex_test_build_features": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900155 "com.android.media.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 }
Jooyung Han90eee022019-10-01 20:02:42 +0900225
226 vndkVersion := proptools.String(ab.vndkProperties.Vndk_version)
227
Jooyung Han344d5432019-08-23 11:17:39 +0900228 vndkApexListMutex.Lock()
229 defer vndkApexListMutex.Unlock()
230 vndkApexList := vndkApexList(mctx.Config())
231 if other, ok := vndkApexList[vndkVersion]; ok {
Jooyung Han90eee022019-10-01 20:02:42 +0900232 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.BaseModuleName())
Jooyung Han344d5432019-08-23 11:17:39 +0900233 }
234 vndkApexList[vndkVersion] = ab
235 }
236}
237
238// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
239// It filters only libs with matching targets.
240func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
241 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
242 vndkApexList := vndkApexList(mctx.Config())
243 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
244 targetArch := cc.Target().String()
245 for _, target := range ab.MultiTargets() {
246 if target.String() == targetArch {
247 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
248 break
249 }
250 }
251 }
252 }
253}
254
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900255// Mark the direct and transitive dependencies of apex bundles so that they
256// can be built for the apex bundles.
257func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800258 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800259 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900260 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900261 depName := mctx.OtherModuleName(child)
262 // If the parent is apexBundle, this child is directly depended.
263 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800264 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800265 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
266 // non-installable apex's cannot be installed and so should not prevent libraries from being
267 // installed to the system.
268 android.UpdateApexDependency(apexBundleName, depName, directDep)
269 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900270
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900271 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900272 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900273 return true
274 } else {
275 return false
276 }
277 })
278 }
279}
280
281// Create apex variations if a module is included in APEX(s).
282func apexMutator(mctx android.BottomUpMutatorContext) {
283 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900284 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900285 } else if _, ok := mctx.Module().(*apexBundle); ok {
286 // apex bundle itself is mutated so that it and its modules have same
287 // apex variant.
288 apexBundleName := mctx.ModuleName()
289 mctx.CreateVariations(apexBundleName)
290 }
291}
Sundong Ahne9b55722019-09-06 17:37:42 +0900292
293func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900294 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900295 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
296 modules := mctx.CreateLocalVariations("", "flattened")
297 modules[0].(*apexBundle).SetFlattened(false)
298 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900299 } else {
300 ab.SetFlattened(true)
301 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900302 }
303 }
304}
305
Jooyung Han5c998b92019-06-27 11:30:33 +0900306func apexUsesMutator(mctx android.BottomUpMutatorContext) {
307 if ab, ok := mctx.Module().(*apexBundle); ok {
308 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
309 }
310}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900311
Alex Light9670d332019-01-29 18:07:33 -0800312type apexNativeDependencies struct {
313 // List of native libraries
314 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900315
Alex Light9670d332019-01-29 18:07:33 -0800316 // List of native executables
317 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900318
Roland Levillain630846d2019-06-26 12:48:34 +0100319 // List of native tests
320 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800321}
Jooyung Han344d5432019-08-23 11:17:39 +0900322
Alex Light9670d332019-01-29 18:07:33 -0800323type apexMultilibProperties struct {
324 // Native dependencies whose compile_multilib is "first"
325 First apexNativeDependencies
326
327 // Native dependencies whose compile_multilib is "both"
328 Both apexNativeDependencies
329
330 // Native dependencies whose compile_multilib is "prefer32"
331 Prefer32 apexNativeDependencies
332
333 // Native dependencies whose compile_multilib is "32"
334 Lib32 apexNativeDependencies
335
336 // Native dependencies whose compile_multilib is "64"
337 Lib64 apexNativeDependencies
338}
339
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900340type apexBundleProperties struct {
341 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000342 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800343 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900344
Jiyong Park40e26a22019-02-08 02:53:06 +0900345 // AndroidManifest.xml file used for the zip container of this APEX bundle.
346 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800347 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900348
Roland Levillain411c5842019-09-19 16:37:20 +0100349 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
350 // device (/apex/<apex_name>).
351 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900352 Apex_name *string
353
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900354 // Determines the file contexts file for setting security context to each file in this APEX bundle.
355 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
356 // used.
357 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900358 File_contexts *string
359
360 // List of native shared libs that are embedded inside this APEX bundle
361 Native_shared_libs []string
362
Roland Levillain630846d2019-06-26 12:48:34 +0100363 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900364 Binaries []string
365
366 // List of java libraries that are embedded inside this APEX bundle
367 Java_libs []string
368
369 // List of prebuilt files that are embedded inside this APEX bundle
370 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900371
Roland Levillain630846d2019-06-26 12:48:34 +0100372 // List of tests that are embedded inside this APEX bundle
373 Tests []string
374
Jiyong Parkff1458f2018-10-12 21:49:38 +0900375 // Name of the apex_key module that provides the private key to sign APEX
376 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900377
Alex Light5098a612018-11-29 17:12:15 -0800378 // The type of APEX to build. Controls what the APEX payload is. Either
379 // 'image', 'zip' or 'both'. Default: 'image'.
380 Payload_type *string
381
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900382 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
383 // or an android_app_certificate module name in the form ":module".
384 Certificate *string
385
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900386 // Whether this APEX is installable to one of the partitions. Default: true.
387 Installable *bool
388
Jiyong Parkda6eb592018-12-19 17:12:36 +0900389 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
390 // Default is false.
391 Use_vendor *bool
392
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800393 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
394 Ignore_system_library_special_case *bool
395
Alex Light9670d332019-01-29 18:07:33 -0800396 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900397
Jiyong Parkf97782b2019-02-13 20:28:58 +0900398 // List of sanitizer names that this APEX is enabled for
399 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900400
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900401 PreventInstall bool `blueprint:"mutated"`
402
403 HideFromMake bool `blueprint:"mutated"`
404
Jooyung Han5c998b92019-06-27 11:30:33 +0900405 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
406 Provide_cpp_shared_libs *bool
407
408 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
409 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100410
411 // A txt file containing list of files that are whitelisted to be included in this APEX.
412 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900413
414 // List of APKs to package inside APEX
415 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900416
Sundong Ahne8fb7242019-09-17 13:50:45 +0900417 // To distinguish between flattened and non-flattened apex.
418 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900419 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900420
Sundong Ahne8fb7242019-09-17 13:50:45 +0900421 // if true, it means that TARGET_FLATTEN_APEX is true and
422 // TARGET_BUILD_APPS is false
423 FlattenedConfigValue bool `blueprint:"mutated"`
424
Jiyong Parkd1063c12019-07-17 20:08:41 +0900425 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
426 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
427 // is implied. This value affects all modules included in this APEX. In other words, they are
428 // also built with the SDKs specified here.
429 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800430}
431
432type apexTargetBundleProperties struct {
433 Target struct {
434 // Multilib properties only for android.
435 Android struct {
436 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900437 }
Jooyung Han344d5432019-08-23 11:17:39 +0900438
Alex Light9670d332019-01-29 18:07:33 -0800439 // Multilib properties only for host.
440 Host struct {
441 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900442 }
Jooyung Han344d5432019-08-23 11:17:39 +0900443
Alex Light9670d332019-01-29 18:07:33 -0800444 // Multilib properties only for host linux_bionic.
445 Linux_bionic struct {
446 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900447 }
Jooyung Han344d5432019-08-23 11:17:39 +0900448
Alex Light9670d332019-01-29 18:07:33 -0800449 // Multilib properties only for host linux_glibc.
450 Linux_glibc struct {
451 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900452 }
453 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900454}
455
Jooyung Han344d5432019-08-23 11:17:39 +0900456type apexVndkProperties struct {
457 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
458 Vndk_version *string
459}
460
Jiyong Park8fd61922018-11-08 02:50:25 +0900461type apexFileClass int
462
463const (
464 etc apexFileClass = iota
465 nativeSharedLib
466 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900467 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800468 pyBinary
469 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900470 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100471 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900472 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900473)
474
Alex Light5098a612018-11-29 17:12:15 -0800475type apexPackaging int
476
477const (
478 imageApex apexPackaging = iota
479 zipApex
480 both
481)
482
483func (a apexPackaging) image() bool {
484 switch a {
485 case imageApex, both:
486 return true
487 }
488 return false
489}
490
491func (a apexPackaging) zip() bool {
492 switch a {
493 case zipApex, both:
494 return true
495 }
496 return false
497}
498
499func (a apexPackaging) suffix() string {
500 switch a {
501 case imageApex:
502 return imageApexSuffix
503 case zipApex:
504 return zipApexSuffix
505 case both:
506 panic(fmt.Errorf("must be either zip or image"))
507 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100508 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800509 }
510}
511
512func (a apexPackaging) name() string {
513 switch a {
514 case imageApex:
515 return imageApexType
516 case zipApex:
517 return zipApexType
518 case both:
519 panic(fmt.Errorf("must be either zip or image"))
520 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100521 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800522 }
523}
524
Jiyong Park8fd61922018-11-08 02:50:25 +0900525func (class apexFileClass) NameInMake() string {
526 switch class {
527 case etc:
528 return "ETC"
529 case nativeSharedLib:
530 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800531 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900532 return "EXECUTABLES"
533 case javaSharedLib:
534 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100535 case nativeTest:
536 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900537 case app:
538 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900539 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100540 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900541 }
542}
543
544type apexFile struct {
545 builtFile android.Path
546 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900547 installDir string
548 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900549 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800550 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900551}
552
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900553type apexBundle struct {
554 android.ModuleBase
555 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900556 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900557
Alex Light9670d332019-01-29 18:07:33 -0800558 properties apexBundleProperties
559 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900560 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900561
Alex Light5098a612018-11-29 17:12:15 -0800562 apexTypes apexPackaging
563
Colin Crossa4925902018-11-16 11:36:28 -0800564 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800565 outputFiles map[apexPackaging]android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700566 flattenedOutput android.InstallPath
567 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900568
Jiyong Park03b68dd2019-07-26 23:20:40 +0900569 prebuiltFileToDelete string
570
Jiyong Park42cca6c2019-04-01 11:15:50 +0900571 public_key_file android.Path
572 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900573
574 container_certificate_file android.Path
575 container_private_key_file android.Path
576
Jiyong Park8fd61922018-11-08 02:50:25 +0900577 // list of files to be included in this apex
578 filesInfo []apexFile
579
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900580 // list of module names that this APEX is depending on
581 externalDeps []string
582
Alex Light0851b882019-02-07 13:20:53 -0800583 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900584 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900585
586 // intermediate path for apex_manifest.json
587 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900588}
589
Jiyong Park397e55e2018-10-24 21:09:55 +0900590func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100591 native_shared_libs []string, binaries []string, tests []string,
592 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900593 // Use *FarVariation* to be able to depend on modules having
594 // conflicting variations with this module. This is required since
595 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
596 // for native shared libs.
597 ctx.AddFarVariationDependencies([]blueprint.Variation{
598 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900599 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900600 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900601 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900602 }, sharedLibTag, native_shared_libs...)
603
604 ctx.AddFarVariationDependencies([]blueprint.Variation{
605 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900606 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900607 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100608
609 ctx.AddFarVariationDependencies([]blueprint.Variation{
610 {Mutator: "arch", Variation: arch},
611 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100612 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100613 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900614}
615
Alex Light9670d332019-01-29 18:07:33 -0800616func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
617 if ctx.Os().Class == android.Device {
618 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
619 } else {
620 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
621 if ctx.Os().Bionic() {
622 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
623 } else {
624 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
625 }
626 }
627}
628
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900629func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800630
Jiyong Park397e55e2018-10-24 21:09:55 +0900631 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900632 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800633
634 a.combineProperties(ctx)
635
Jiyong Park397e55e2018-10-24 21:09:55 +0900636 has32BitTarget := false
637 for _, target := range targets {
638 if target.Arch.ArchType.Multilib == "lib32" {
639 has32BitTarget = true
640 }
641 }
642 for i, target := range targets {
643 // When multilib.* is omitted for native_shared_libs, it implies
644 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900645 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900646 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900647 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900648 {Mutator: "link", Variation: "shared"},
649 }, sharedLibTag, a.properties.Native_shared_libs...)
650
Roland Levillain630846d2019-06-26 12:48:34 +0100651 // When multilib.* is omitted for tests, it implies
652 // multilib.both.
653 ctx.AddFarVariationDependencies([]blueprint.Variation{
654 {Mutator: "arch", Variation: target.String()},
655 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100656 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100657 }, testTag, a.properties.Tests...)
658
Jiyong Park397e55e2018-10-24 21:09:55 +0900659 // Add native modules targetting both ABIs
660 addDependenciesForNativeModules(ctx,
661 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100662 a.properties.Multilib.Both.Binaries,
663 a.properties.Multilib.Both.Tests,
664 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900665 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900666
Alex Light3d673592019-01-18 14:37:31 -0800667 isPrimaryAbi := i == 0
668 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900669 // When multilib.* is omitted for binaries, it implies
670 // multilib.first.
671 ctx.AddFarVariationDependencies([]blueprint.Variation{
672 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900673 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900674 }, executableTag, a.properties.Binaries...)
675
676 // Add native modules targetting the first ABI
677 addDependenciesForNativeModules(ctx,
678 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100679 a.properties.Multilib.First.Binaries,
680 a.properties.Multilib.First.Tests,
681 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900682 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800683
684 // When multilib.* is omitted for prebuilts, it implies multilib.first.
685 ctx.AddFarVariationDependencies([]blueprint.Variation{
686 {Mutator: "arch", Variation: target.String()},
687 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900688 }
689
690 switch target.Arch.ArchType.Multilib {
691 case "lib32":
692 // Add native modules targetting 32-bit ABI
693 addDependenciesForNativeModules(ctx,
694 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100695 a.properties.Multilib.Lib32.Binaries,
696 a.properties.Multilib.Lib32.Tests,
697 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900698 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900699
700 addDependenciesForNativeModules(ctx,
701 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100702 a.properties.Multilib.Prefer32.Binaries,
703 a.properties.Multilib.Prefer32.Tests,
704 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900705 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900706 case "lib64":
707 // Add native modules targetting 64-bit ABI
708 addDependenciesForNativeModules(ctx,
709 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100710 a.properties.Multilib.Lib64.Binaries,
711 a.properties.Multilib.Lib64.Tests,
712 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900713 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900714
715 if !has32BitTarget {
716 addDependenciesForNativeModules(ctx,
717 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100718 a.properties.Multilib.Prefer32.Binaries,
719 a.properties.Multilib.Prefer32.Tests,
720 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900721 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900722 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700723
724 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
725 for _, sanitizer := range ctx.Config().SanitizeDevice() {
726 if sanitizer == "hwaddress" {
727 addDependenciesForNativeModules(ctx,
728 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100729 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700730 break
731 }
732 }
733 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900734 }
735
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900736 }
737
Jiyong Parkff1458f2018-10-12 21:49:38 +0900738 ctx.AddFarVariationDependencies([]blueprint.Variation{
739 {Mutator: "arch", Variation: "android_common"},
740 }, javaLibTag, a.properties.Java_libs...)
741
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900742 ctx.AddFarVariationDependencies([]blueprint.Variation{
743 {Mutator: "arch", Variation: "android_common"},
744 }, androidAppTag, a.properties.Apps...)
745
Jiyong Park23c52b02019-02-02 13:13:47 +0900746 if String(a.properties.Key) == "" {
747 ctx.ModuleErrorf("key is missing")
748 return
749 }
750 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900751
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900752 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900753 if cert != "" {
754 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900755 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900756
757 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
758 if len(a.properties.Uses_sdks) > 0 {
759 sdkRefs := []android.SdkRef{}
760 for _, str := range a.properties.Uses_sdks {
761 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
762 sdkRefs = append(sdkRefs, parsed)
763 }
764 a.BuildWithSdks(sdkRefs)
765 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900766}
767
Colin Cross0ea8ba82019-06-06 14:33:29 -0700768func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900769 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
770 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000771 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900772 }
773 return String(a.properties.Certificate)
774}
775
Colin Cross41955e82019-05-29 14:40:35 -0700776func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
777 switch tag {
778 case "":
779 if file, ok := a.outputFiles[imageApex]; ok {
780 return android.Paths{file}, nil
781 } else {
782 return nil, nil
783 }
Roland Levillain935639d2019-08-13 14:55:28 +0100784 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900785 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100786 flattenedApexPath := a.flattenedOutput
787 return android.Paths{flattenedApexPath}, nil
788 } else {
789 return nil, nil
790 }
Colin Cross41955e82019-05-29 14:40:35 -0700791 default:
792 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900793 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900794}
795
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900796func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900797 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900798}
799
Jiyong Park7c1dc612019-01-05 11:15:24 +0900800func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
801 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900802 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900803 } else {
804 return "core"
805 }
806}
807
Jiyong Parkf97782b2019-02-13 20:28:58 +0900808func (a *apexBundle) EnableSanitizer(sanitizerName string) {
809 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
810 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
811 }
812}
813
Jiyong Park388ef3f2019-01-28 19:47:32 +0900814func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900815 if android.InList(sanitizerName, a.properties.SanitizerNames) {
816 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900817 }
818
819 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900820 globalSanitizerNames := []string{}
821 if a.Host() {
822 globalSanitizerNames = ctx.Config().SanitizeHost()
823 } else {
824 arches := ctx.Config().SanitizeDeviceArch()
825 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
826 globalSanitizerNames = ctx.Config().SanitizeDevice()
827 }
828 }
829 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900830}
831
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900832func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
833 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
834}
835
836func (a *apexBundle) PreventInstall() {
837 a.properties.PreventInstall = true
838}
839
840func (a *apexBundle) HideFromMake() {
841 a.properties.HideFromMake = true
842}
843
Sundong Ahne9b55722019-09-06 17:37:42 +0900844func (a *apexBundle) SetFlattened(flattened bool) {
845 a.properties.Flattened = flattened
846}
847
Sundong Ahne8fb7242019-09-17 13:50:45 +0900848func (a *apexBundle) SetFlattenedConfigValue() {
849 a.properties.FlattenedConfigValue = true
850}
851
852// isFlattenedVariant returns true when the current module is the flattened
853// variant of an apex that has both a flattened and an unflattened variant.
854// It returns false when the current module is flattened but there is no
855// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
856// true. It can be used to avoid collisions between the install paths of the
857// flattened and unflattened variants.
858func (a *apexBundle) isFlattenedVariant() bool {
859 return a.properties.Flattened && !a.properties.FlattenedConfigValue
860}
861
Martin Stjernholm279de572019-09-10 23:18:20 +0100862func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863 // Decide the APEX-local directory by the multilib of the library
864 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100865 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900866 case "lib32":
867 dirInApex = "lib"
868 case "lib64":
869 dirInApex = "lib64"
870 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100871 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700872 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100873 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())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700895 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200896 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900897 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900898 fileToCopy = cc.OutputFile().Path()
899 return
900}
901
Alex Light778127a2019-02-27 14:19:50 -0800902func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
903 dirInApex = "bin"
904 fileToCopy = py.HostToolPath().Path()
905 return
906}
907func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
908 dirInApex = "bin"
909 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
910 if err != nil {
911 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
912 return
913 }
914 fileToCopy = android.PathForOutput(ctx, s)
915 return
916}
917
Jiyong Park04480cf2019-02-06 00:16:29 +0900918func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
919 dirInApex = filepath.Join("bin", sh.SubDir())
920 fileToCopy = sh.OutputFile()
921 return
922}
923
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900924func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
925 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900926 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900927 return
928}
929
Jiyong Park9e6c2422019-08-09 20:39:45 +0900930func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
931 dirInApex = "javalib"
932 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
933 implJars := java.ImplementationJars()
934 if len(implJars) != 1 {
935 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
936 strings.Join(implJars.Strings(), ", ")))
937 }
938 fileToCopy = implJars[0]
939 return
940}
941
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900942func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
943 dirInApex = filepath.Join("etc", prebuilt.SubDir())
944 fileToCopy = prebuilt.OutputFile()
945 return
946}
947
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900948func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
949 dirInApex = filepath.Join("app", pkgName)
950 fileToCopy = app.OutputFile()
951 return
952}
953
Roland Levillain935639d2019-08-13 14:55:28 +0100954// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
955type flattenedApexContext struct {
956 android.ModuleContext
957}
958
959func (c *flattenedApexContext) InstallBypassMake() bool {
960 return true
961}
962
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900963func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900964 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965
Alex Light5098a612018-11-29 17:12:15 -0800966 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
967 a.apexTypes = imageApex
968 } else if *a.properties.Payload_type == "zip" {
969 a.apexTypes = zipApex
970 } else if *a.properties.Payload_type == "both" {
971 a.apexTypes = both
972 } else {
973 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
974 return
975 }
976
Roland Levillain630846d2019-06-26 12:48:34 +0100977 if len(a.properties.Tests) > 0 && !a.testApex {
978 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
979 return
980 }
981
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800982 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
983
Jooyung Hane1633032019-08-01 17:41:43 +0900984 // native lib dependencies
985 var provideNativeLibs []string
986 var requireNativeLibs []string
987
Jooyung Han5c998b92019-06-27 11:30:33 +0900988 // Check if "uses" requirements are met with dependent apexBundles
989 var providedNativeSharedLibs []string
990 useVendor := proptools.Bool(a.properties.Use_vendor)
991 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
992 if ctx.OtherModuleDependencyTag(m) != usesTag {
993 return
994 }
995 otherName := ctx.OtherModuleName(m)
996 other, ok := m.(*apexBundle)
997 if !ok {
998 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
999 return
1000 }
1001 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1002 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1003 return
1004 }
1005 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1006 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1007 return
1008 }
1009 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1010 })
1011
Alex Light778127a2019-02-27 14:19:50 -08001012 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001013 depTag := ctx.OtherModuleDependencyTag(child)
1014 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001015 if _, ok := parent.(*apexBundle); ok {
1016 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017 switch depTag {
1018 case sharedLibTag:
1019 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001020 if cc.HasStubsVariants() {
1021 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1022 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001023 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001024 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001025 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001026 } else {
1027 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001028 }
1029 case executableTag:
1030 if cc, ok := child.(*cc.Module); ok {
1031 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001032 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001034 } else if sh, ok := child.(*android.ShBinary); ok {
1035 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -07001036 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
Alex Light778127a2019-02-27 14:19:50 -08001037 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1038 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1039 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1040 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1041 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1042 // NB: Since go binaries are static we don't need the module for anything here, which is
1043 // good since the go tool is a blueprint.Module not an android.Module like we would
1044 // normally use.
1045 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001046 } else {
Alex Light778127a2019-02-27 14:19:50 -08001047 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 +09001048 }
1049 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001050 if javaLib, ok := child.(*java.Library); ok {
1051 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001052 if fileToCopy == nil {
1053 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1054 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001055 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1056 }
1057 return true
1058 } else if javaLib, ok := child.(*java.Import); ok {
1059 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1060 if fileToCopy == nil {
1061 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1062 } else {
1063 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001064 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001065 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001066 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001067 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068 }
1069 case prebuiltTag:
1070 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1071 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001072 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001073 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001074 } else {
1075 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1076 }
Roland Levillain630846d2019-06-26 12:48:34 +01001077 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001078 if ccTest, ok := child.(*cc.Module); ok {
1079 if ccTest.IsTestPerSrcAllTestsVariation() {
1080 // Multiple-output test module (where `test_per_src: true`).
1081 //
1082 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1083 // We do not add this variation to `filesInfo`, as it has no output;
1084 // however, we do add the other variations of this module as indirect
1085 // dependencies (see below).
1086 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001087 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001088 // Single-output test module (where `test_per_src: false`).
1089 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1090 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001091 }
Roland Levillain630846d2019-06-26 12:48:34 +01001092 return true
1093 } else {
1094 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1095 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001096 case keyTag:
1097 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001098 a.private_key_file = key.private_key_file
1099 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001100 return false
1101 } else {
1102 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001103 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001104 case certificateTag:
1105 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001106 a.container_certificate_file = dep.Certificate.Pem
1107 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001108 return false
1109 } else {
1110 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1111 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001112 case android.PrebuiltDepTag:
1113 // If the prebuilt is force disabled, remember to delete the prebuilt file
1114 // that might have been installed in the previous builds
1115 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1116 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1117 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001118 case androidAppTag:
1119 if ap, ok := child.(*java.AndroidApp); ok {
1120 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1121 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1122 return true
1123 } else {
1124 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1125 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001126 }
1127 } else {
1128 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001129 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001130 // We cannot use a switch statement on `depTag` here as the checked
1131 // tags used below are private (e.g. `cc.sharedDepTag`).
1132 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1133 if cc, ok := child.(*cc.Module); ok {
1134 if android.InList(cc.Name(), providedNativeSharedLibs) {
1135 // If we're using a shared library which is provided from other APEX,
1136 // don't include it in this APEX
1137 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001138 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001139 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1140 // If the dependency is a stubs lib, don't include it in this APEX,
1141 // but make sure that the lib is installed on the device.
1142 // In case no APEX is having the lib, the lib is installed to the system
1143 // partition.
1144 //
1145 // Always include if we are a host-apex however since those won't have any
1146 // system libraries.
1147 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1148 a.externalDeps = append(a.externalDeps, cc.Name())
1149 }
Jooyung Hane1633032019-08-01 17:41:43 +09001150 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001151 // Don't track further
1152 return false
1153 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001154 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001155 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1156 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001157 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001158 } else if cc.IsTestPerSrcDepTag(depTag) {
1159 if cc, ok := child.(*cc.Module); ok {
1160 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1161 // Handle modules created as `test_per_src` variations of a single test module:
1162 // use the name of the generated test binary (`fileToCopy`) instead of the name
1163 // of the original test module (`depName`, shared by all `test_per_src`
1164 // variations of that module).
1165 moduleName := filepath.Base(fileToCopy.String())
1166 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1167 return true
1168 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001169 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001170 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jooyung Hancc372c52019-09-25 15:18:44 +09001171 } else if depTag == android.DefaultsDepTag {
1172 return false
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 Park127b40b2019-09-30 16:04:35 +09001216 // check apex_available requirements
1217 for _, fi := range filesInfo {
1218 if am, ok := fi.module.(android.ApexModule); ok {
1219 if !am.AvailableFor(ctx.ModuleName()) {
1220 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
1221 return
1222 }
1223 }
1224 }
1225
Jiyong Park8fd61922018-11-08 02:50:25 +09001226 // prepend the name of this APEX to the module names. These names will be the names of
1227 // modules that will be defined if the APEX is flattened.
1228 for i := range filesInfo {
1229 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
1230 }
1231
Jiyong Park8fd61922018-11-08 02:50:25 +09001232 a.installDir = android.PathForModuleInstall(ctx, "apex")
1233 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001234
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001235 // prepare apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001236 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
Jooyung Hane1633032019-08-01 17:41:43 +09001237 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001238
1239 // put dependency({provide|require}NativeLibs) in apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001240 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1241 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001242
1243 // apex name can be overridden
1244 optCommands := []string{}
1245 if a.properties.Apex_name != nil {
1246 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
1247 }
1248
Jooyung Hane1633032019-08-01 17:41:43 +09001249 ctx.Build(pctx, android.BuildParams{
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001250 Rule: apexManifestRule,
Jooyung Hane1633032019-08-01 17:41:43 +09001251 Input: manifestSrc,
1252 Output: a.manifestOut,
1253 Args: map[string]string{
1254 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1255 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001256 "opt": strings.Join(optCommands, " "),
Jooyung Hane1633032019-08-01 17:41:43 +09001257 },
1258 })
1259
Roland Levillain935639d2019-08-13 14:55:28 +01001260 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1261 // reply true to `InstallBypassMake()` (thus making the call
1262 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1263 // instead of `android.PathForOutput`) to return the correct path to the flattened
1264 // APEX (as its contents is installed by Make, not Soong).
1265 factx := flattenedApexContext{ctx}
1266 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
1267
Alex Light5098a612018-11-29 17:12:15 -08001268 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001269 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001270 }
1271 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001272 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001273 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001274 // in other modules. It is in AndroidMk where the selection of flattened
1275 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001276 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001277 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001278 }
1279}
1280
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001281func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001282 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001283 for _, f := range a.filesInfo {
1284 if f.module != nil {
1285 notice := f.module.NoticeFile()
1286 if notice.Valid() {
1287 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001288 }
1289 }
1290 }
1291 // append the notice file specified in the apex module itself
1292 if a.NoticeFile().Valid() {
1293 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001294 }
1295
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001296 if len(noticeFiles) == 0 {
1297 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001298 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001299
Jaewoong Jung98772792019-07-01 17:15:13 -07001300 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001301}
1302
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001303func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001304 cert := String(a.properties.Certificate)
1305 if cert != "" && android.SrcIsModule(cert) == "" {
1306 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001307 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1308 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001309 } else if cert == "" {
1310 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001311 a.container_certificate_file = pem
1312 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001313 }
1314
Alex Light5098a612018-11-29 17:12:15 -08001315 var abis []string
1316 for _, target := range ctx.MultiTargets() {
1317 if len(target.Arch.Abi) > 0 {
1318 abis = append(abis, target.Arch.Abi[0])
1319 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001320 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001321
Alex Light5098a612018-11-29 17:12:15 -08001322 abis = android.FirstUniqueStrings(abis)
1323
1324 suffix := apexType.suffix()
1325 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001326
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001327 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001328 for _, f := range a.filesInfo {
1329 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001330 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001331
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001332 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001333 emitCommands := []string{}
1334 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1335 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001336 for i, src := range filesToCopy {
1337 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001338 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001339 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001340 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1341 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001342 for _, sym := range a.filesInfo[i].symlinks {
1343 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1344 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1345 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001346 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001347 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001348 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001349
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001350 if a.properties.Whitelisted_files != nil {
1351 ctx.Build(pctx, android.BuildParams{
1352 Rule: emitApexContentRule,
1353 Implicits: implicitInputs,
1354 Output: imageContentFile,
1355 Description: "emit apex image content",
1356 Args: map[string]string{
1357 "emit_commands": strings.Join(emitCommands, " && "),
1358 },
1359 })
1360 implicitInputs = append(implicitInputs, imageContentFile)
1361 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1362
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001363 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001364 ctx.Build(pctx, android.BuildParams{
1365 Rule: diffApexContentRule,
1366 Implicits: implicitInputs,
1367 Output: phonyOutput,
1368 Description: "diff apex image content",
1369 Args: map[string]string{
1370 "whitelisted_files_file": whitelistedFilesFile.String(),
1371 "image_content_file": imageContentFile.String(),
1372 "apex_module_name": ctx.ModuleName(),
1373 },
1374 })
1375
1376 implicitInputs = append(implicitInputs, phonyOutput)
1377 }
1378
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001379 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1380 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001381
Alex Light5098a612018-11-29 17:12:15 -08001382 if apexType.image() {
1383 // files and dirs that will be created in APEX
1384 var readOnlyPaths []string
1385 var executablePaths []string // this also includes dirs
1386 for _, f := range a.filesInfo {
1387 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001388 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001389 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001390 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001391 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001392 }
Alex Light5098a612018-11-29 17:12:15 -08001393 } else {
1394 readOnlyPaths = append(readOnlyPaths, pathInApex)
1395 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001396 dir := f.installDir
1397 for !android.InList(dir, executablePaths) && dir != "" {
1398 executablePaths = append(executablePaths, dir)
1399 dir, _ = filepath.Split(dir) // move up to the parent
1400 if len(dir) > 0 {
1401 // remove trailing slash
1402 dir = dir[:len(dir)-1]
1403 }
Alex Light5098a612018-11-29 17:12:15 -08001404 }
1405 }
1406 sort.Strings(readOnlyPaths)
1407 sort.Strings(executablePaths)
1408 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1409 ctx.Build(pctx, android.BuildParams{
1410 Rule: generateFsConfig,
1411 Output: cannedFsConfig,
1412 Description: "generate fs config",
1413 Args: map[string]string{
1414 "ro_paths": strings.Join(readOnlyPaths, " "),
1415 "exec_paths": strings.Join(executablePaths, " "),
1416 },
1417 })
1418
1419 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1420 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1421 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1422 if !fileContextsOptionalPath.Valid() {
1423 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1424 return
1425 }
1426 fileContexts := fileContextsOptionalPath.Path()
1427
Jiyong Park835d82b2018-12-27 16:04:18 +09001428 optFlags := []string{}
1429
Alex Light5098a612018-11-29 17:12:15 -08001430 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001431 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1432 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001433
Jiyong Park7f67f482019-01-05 12:57:48 +09001434 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1435 if overridden {
1436 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1437 }
1438
Jiyong Park40e26a22019-02-08 02:53:06 +09001439 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001440 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001441 implicitInputs = append(implicitInputs, androidManifestFile)
1442 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1443 }
1444
Jiyong Park71b519d2019-04-18 17:25:49 +09001445 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1446 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1447 ctx.Config().UnbundledBuild() &&
1448 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1449 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1450 apiFingerprint := java.ApiFingerprintPath(ctx)
1451 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1452 implicitInputs = append(implicitInputs, apiFingerprint)
1453 }
1454 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1455
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001456 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1457 if noticeFile.Valid() {
1458 // If there's a NOTICE file, embed it as an asset file in the APEX.
1459 implicitInputs = append(implicitInputs, noticeFile.Path())
1460 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1461 }
1462
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001463 if !ctx.Config().UnbundledBuild() && a.installable() {
1464 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1465 // don't need hashtree for activation. Therefore, by removing hashtree from
1466 // apex bundle (filesystem image in it, to be specific), we can save storage.
1467 optFlags = append(optFlags, "--no_hashtree")
1468 }
1469
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001470 if a.properties.Apex_name != nil {
1471 // If apex_name is set, apexer can skip checking if key name matches with apex name.
1472 // Note that apex_manifest is also mended.
1473 optFlags = append(optFlags, "--do_not_check_keyname")
1474 }
1475
Alex Light5098a612018-11-29 17:12:15 -08001476 ctx.Build(pctx, android.BuildParams{
1477 Rule: apexRule,
1478 Implicits: implicitInputs,
1479 Output: unsignedOutputFile,
1480 Description: "apex (" + apexType.name() + ")",
1481 Args: map[string]string{
1482 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1483 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1484 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001485 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001486 "file_contexts": fileContexts.String(),
1487 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001488 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001489 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001490 },
1491 })
1492
1493 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1494 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1495 a.bundleModuleFile = bundleModuleFile
1496
1497 ctx.Build(pctx, android.BuildParams{
1498 Rule: apexProtoConvertRule,
1499 Input: unsignedOutputFile,
1500 Output: apexProtoFile,
1501 Description: "apex proto convert",
1502 })
1503
1504 ctx.Build(pctx, android.BuildParams{
1505 Rule: apexBundleRule,
1506 Input: apexProtoFile,
1507 Output: a.bundleModuleFile,
1508 Description: "apex bundle module",
1509 Args: map[string]string{
1510 "abi": strings.Join(abis, "."),
1511 },
1512 })
1513 } else {
1514 ctx.Build(pctx, android.BuildParams{
1515 Rule: zipApexRule,
1516 Implicits: implicitInputs,
1517 Output: unsignedOutputFile,
1518 Description: "apex (" + apexType.name() + ")",
1519 Args: map[string]string{
1520 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1521 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1522 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001523 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001524 },
1525 })
Colin Crossa4925902018-11-16 11:36:28 -08001526 }
Colin Crossa4925902018-11-16 11:36:28 -08001527
Alex Light5098a612018-11-29 17:12:15 -08001528 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001529 ctx.Build(pctx, android.BuildParams{
1530 Rule: java.Signapk,
1531 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001532 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001533 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001534 Implicits: []android.Path{
1535 a.container_certificate_file,
1536 a.container_private_key_file,
1537 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001538 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001539 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001540 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001541 },
1542 })
Alex Light5098a612018-11-29 17:12:15 -08001543
1544 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001545 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001546 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001547 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001548}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001549
Jiyong Park8fd61922018-11-08 02:50:25 +09001550func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001551 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001552 // 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 +09001553 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001554 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001555
Jiyong Park42cca6c2019-04-01 11:15:50 +09001556 // rename to apex_pubkey
1557 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1558 ctx.Build(pctx, android.BuildParams{
1559 Rule: android.Cp,
1560 Input: a.public_key_file,
1561 Output: copiedPubkey,
1562 })
1563 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1564
Jiyong Park23c52b02019-02-02 13:13:47 +09001565 if ctx.Config().FlattenApex() {
1566 for _, fi := range a.filesInfo {
1567 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001568 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1569 for _, sym := range fi.symlinks {
1570 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1571 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001572 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001573 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001574 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001575}
1576
1577func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001578 if a.properties.HideFromMake {
1579 return android.AndroidMkData{
1580 Disabled: true,
1581 }
1582 }
Alex Light5098a612018-11-29 17:12:15 -08001583 writers := []android.AndroidMkData{}
1584 if a.apexTypes.image() {
1585 writers = append(writers, a.androidMkForType(imageApex))
1586 }
1587 if a.apexTypes.zip() {
1588 writers = append(writers, a.androidMkForType(zipApex))
1589 }
1590 return android.AndroidMkData{
1591 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1592 for _, data := range writers {
1593 data.Custom(w, name, prefix, moduleDir, data)
1594 }
1595 }}
1596}
1597
Alex Lightf1801bc2019-02-13 11:10:07 -08001598func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001599 moduleNames := []string{}
1600
1601 for _, fi := range a.filesInfo {
1602 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1603 continue
1604 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001605 if a.properties.Flattened && !apexType.image() {
1606 continue
Jiyong Park94427262019-02-05 23:18:47 +09001607 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001608
1609 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001610 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001611 suffix = ".flattened"
1612 }
1613
1614 if !android.InList(fi.moduleName, moduleNames) {
1615 moduleNames = append(moduleNames, fi.moduleName+suffix)
1616 }
1617
Jiyong Park94427262019-02-05 23:18:47 +09001618 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1619 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001620 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001621 // /apex/<apex_name>/{lib|framework|...}
Jiyong Park05e70dd2019-03-18 14:26:32 +09001622 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1623 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001624 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001625 // /system/apex/<name>/{lib|framework|...}
Colin Crossff6c33d2019-10-02 16:01:35 -07001626 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
1627 name, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001628 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001629 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1630 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001631 if len(fi.symlinks) > 0 {
1632 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1633 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001634
1635 if fi.module != nil && fi.module.NoticeFile().Valid() {
1636 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1637 }
Jiyong Park94427262019-02-05 23:18:47 +09001638 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001639 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001640 }
1641 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1642 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1643 if fi.module != nil {
1644 archStr := fi.module.Target().Arch.ArchType.String()
1645 host := false
1646 switch fi.module.Target().Os.Class {
1647 case android.Host:
1648 if archStr != "common" {
1649 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1650 }
1651 host = true
1652 case android.HostCross:
1653 if archStr != "common" {
1654 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1655 }
1656 host = true
1657 case android.Device:
1658 if archStr != "common" {
1659 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1660 }
1661 }
1662 if host {
1663 makeOs := fi.module.Target().Os.String()
1664 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1665 makeOs = "linux"
1666 }
1667 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1668 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1669 }
1670 }
1671 if fi.class == javaSharedLib {
1672 javaModule := fi.module.(*java.Library)
1673 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1674 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1675 // we will have foo.jar.jar
1676 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1677 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1678 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1679 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1680 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1681 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001682 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001683 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001684 if cc, ok := fi.module.(*cc.Module); ok {
1685 if cc.UnstrippedOutputFile() != nil {
1686 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1687 }
1688 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001689 if cc.CoverageOutputFile().Valid() {
1690 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1691 }
Jiyong Park94427262019-02-05 23:18:47 +09001692 }
1693 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1694 } else {
1695 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1696 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1697 }
1698 }
1699 return moduleNames
1700}
1701
Alex Light5098a612018-11-29 17:12:15 -08001702func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001703 return android.AndroidMkData{
1704 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1705 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001706 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001707 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001708 }
1709
Sundong Ahne8fb7242019-09-17 13:50:45 +09001710 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001711 name = name + ".flattened"
1712 }
1713
1714 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001715 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001716 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1717 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1718 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001719 if len(moduleNames) > 0 {
1720 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1721 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001722 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001723 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1724
Sundong Ahne8fb7242019-09-17 13:50:45 +09001725 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001726 // zip-apex is the less common type so have the name refer to the image-apex
1727 // only and use {name}.zip if you want the zip-apex
1728 if apexType == zipApex && a.apexTypes == both {
1729 name = name + ".zip"
1730 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001731 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1732 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1733 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1734 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001735 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Colin Crossff6c33d2019-10-02 16:01:35 -07001736 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
Colin Cross189ff982019-01-02 22:32:27 -08001737 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001738 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001739 if len(moduleNames) > 0 {
1740 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1741 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001742 if len(a.externalDeps) > 0 {
1743 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1744 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001745 if a.prebuiltFileToDelete != "" {
1746 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
Colin Crossff6c33d2019-10-02 16:01:35 -07001747 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
Jiyong Park03b68dd2019-07-26 23:20:40 +09001748 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001749 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001750
Alex Light5098a612018-11-29 17:12:15 -08001751 if apexType == imageApex {
1752 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1753 }
Jiyong Park719b4462019-01-13 00:39:51 +09001754 }
1755 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001756}
1757
Jooyung Han344d5432019-08-23 11:17:39 +09001758func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001759 module := &apexBundle{
1760 outputFiles: map[apexPackaging]android.WritablePath{},
1761 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001762 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001763 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001764 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001765 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1766 })
Alex Light5098a612018-11-29 17:12:15 -08001767 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001768 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001769 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001770 return module
1771}
Jiyong Park30ca9372019-02-07 16:27:23 +09001772
Jooyung Han344d5432019-08-23 11:17:39 +09001773func ApexBundleFactory(testApex bool) android.Module {
1774 bundle := newApexBundle()
1775 bundle.testApex = testApex
1776 return bundle
1777}
1778
1779func testApexBundleFactory() android.Module {
1780 bundle := newApexBundle()
1781 bundle.testApex = true
1782 return bundle
1783}
1784
Jiyong Parkd1063c12019-07-17 20:08:41 +09001785func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001786 return newApexBundle()
1787}
1788
1789// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1790// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1791// If not specified, then the "current" versions are gathered.
1792func vndkApexBundleFactory() android.Module {
1793 bundle := newApexBundle()
1794 bundle.vndkApex = true
1795 bundle.AddProperties(&bundle.vndkProperties)
1796 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1797 ctx.AppendProperties(&struct {
1798 Compile_multilib *string
1799 }{
1800 proptools.StringPtr("both"),
1801 })
Jooyung Han90eee022019-10-01 20:02:42 +09001802
1803 vndkVersion := proptools.StringDefault(bundle.vndkProperties.Vndk_version, "current")
1804 if vndkVersion == "current" {
1805 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1806 bundle.vndkProperties.Vndk_version = proptools.StringPtr(vndkVersion)
1807 }
1808
1809 // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
1810 bundle.properties.Apex_name = proptools.StringPtr("com.android.vndk.v" + vndkVersion)
Jooyung Han344d5432019-08-23 11:17:39 +09001811 })
1812 return bundle
1813}
1814
Jiyong Park30ca9372019-02-07 16:27:23 +09001815//
1816// Defaults
1817//
1818type Defaults struct {
1819 android.ModuleBase
1820 android.DefaultsModuleBase
1821}
1822
Jiyong Park30ca9372019-02-07 16:27:23 +09001823func defaultsFactory() android.Module {
1824 return DefaultsFactory()
1825}
1826
1827func DefaultsFactory(props ...interface{}) android.Module {
1828 module := &Defaults{}
1829
1830 module.AddProperties(props...)
1831 module.AddProperties(
1832 &apexBundleProperties{},
1833 &apexTargetBundleProperties{},
1834 )
1835
1836 android.InitDefaultsModule(module)
1837 return module
1838}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001839
1840//
1841// Prebuilt APEX
1842//
1843type Prebuilt struct {
1844 android.ModuleBase
1845 prebuilt android.Prebuilt
1846
1847 properties PrebuiltProperties
1848
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001849 inputApex android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001850 installDir android.InstallPath
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001851 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001852 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001853}
1854
1855type PrebuiltProperties struct {
1856 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001857 Source string `blueprint:"mutated"`
1858 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001859
1860 Src *string
1861 Arch struct {
1862 Arm struct {
1863 Src *string
1864 }
1865 Arm64 struct {
1866 Src *string
1867 }
1868 X86 struct {
1869 Src *string
1870 }
1871 X86_64 struct {
1872 Src *string
1873 }
1874 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001875
1876 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001877 // Optional name for the installed apex. If unspecified, name of the
1878 // module is used as the file name
1879 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001880
1881 // Names of modules to be overridden. Listed modules can only be other binaries
1882 // (in Make or Soong).
1883 // This does not completely prevent installation of the overridden binaries, but if both
1884 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1885 // from PRODUCT_PACKAGES.
1886 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001887}
1888
1889func (p *Prebuilt) installable() bool {
1890 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001891}
1892
1893func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001894 // If the device is configured to use flattened APEX, force disable the prebuilt because
1895 // the prebuilt is a non-flattened one.
1896 forceDisable := ctx.Config().FlattenApex()
1897
1898 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1899 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001900 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001901
Kun Niu10c9f832019-07-29 16:28:57 -07001902 // Force disable the prebuilts when coverage is enabled.
1903 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1904 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1905
Jiyong Park50b81e52019-07-11 11:24:41 +09001906 // b/137216042 don't use prebuilts when address sanitizer is on
1907 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1908 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1909
1910 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001911 p.properties.ForceDisable = true
1912 return
1913 }
1914
Jiyong Parkc95714e2019-03-29 14:23:10 +09001915 // This is called before prebuilt_select and prebuilt_postdeps mutators
1916 // The mutators requires that src to be set correctly for each arch so that
1917 // arch variants are disabled when src is not provided for the arch.
1918 if len(ctx.MultiTargets()) != 1 {
1919 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1920 return
1921 }
1922 var src string
1923 switch ctx.MultiTargets()[0].Arch.ArchType {
1924 case android.Arm:
1925 src = String(p.properties.Arch.Arm.Src)
1926 case android.Arm64:
1927 src = String(p.properties.Arch.Arm64.Src)
1928 case android.X86:
1929 src = String(p.properties.Arch.X86.Src)
1930 case android.X86_64:
1931 src = String(p.properties.Arch.X86_64.Src)
1932 default:
1933 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1934 return
1935 }
1936 if src == "" {
1937 src = String(p.properties.Src)
1938 }
1939 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001940}
1941
Jiyong Park03b68dd2019-07-26 23:20:40 +09001942func (p *Prebuilt) isForceDisabled() bool {
1943 return p.properties.ForceDisable
1944}
1945
Colin Cross41955e82019-05-29 14:40:35 -07001946func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1947 switch tag {
1948 case "":
1949 return android.Paths{p.outputApex}, nil
1950 default:
1951 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1952 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001953}
1954
Jiyong Park4d277042019-04-23 18:00:10 +09001955func (p *Prebuilt) InstallFilename() string {
1956 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1957}
1958
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001959func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001960 if p.properties.ForceDisable {
1961 return
1962 }
1963
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001964 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001965 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001966 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001967 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001968 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1969 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1970 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001971 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1972 ctx.Build(pctx, android.BuildParams{
1973 Rule: android.Cp,
1974 Input: p.inputApex,
1975 Output: p.outputApex,
1976 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001977 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001978 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001979 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001980}
1981
1982func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1983 return &p.prebuilt
1984}
1985
1986func (p *Prebuilt) Name() string {
1987 return p.prebuilt.Name(p.ModuleBase.Name())
1988}
1989
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001990func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1991 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001992 Class: "ETC",
1993 OutputFile: android.OptionalPathForPath(p.inputApex),
1994 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001995 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1996 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -07001997 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001998 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1999 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
2000 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
2001 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002002 },
2003 }
2004}
2005
2006// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
2007func PrebuiltFactory() android.Module {
2008 module := &Prebuilt{}
2009 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07002010 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09002011 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002012 return module
2013}