blob: bb90cb9576b15bc279dd24cbbf4a63ecb49d8c57 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
19 "io"
20 "path/filepath"
21 "runtime"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
36var (
37 pctx = android.NewPackageContext("android/apex")
38
39 // Create a canned fs config file where all files and directories are
40 // by default set to (uid/gid/mode) = (1000/1000/0644)
41 // TODO(b/113082813) make this configurable using config.fs syntax
42 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000043 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000044 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090045 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090046 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090047 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090048 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090049
Jooyung Hand15aa1f2019-09-27 00:38:03 +090050 apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
Jooyung Hane1633032019-08-01 17:41:43 +090051 Command: `rm -f $out && ${jsonmodify} $in ` +
52 `-a provideNativeLibs ${provideNativeLibs} ` +
Jooyung Hand15aa1f2019-09-27 00:38:03 +090053 `-a requireNativeLibs ${requireNativeLibs} ` +
54 `${opt} ` +
55 `-o $out`,
Jooyung Hane1633032019-08-01 17:41:43 +090056 CommandDeps: []string{"${jsonmodify}"},
Jooyung Hand15aa1f2019-09-27 00:38:03 +090057 Description: "prepare ${out}",
58 }, "provideNativeLibs", "requireNativeLibs", "opt")
Jooyung Hane1633032019-08-01 17:41:43 +090059
Jiyong Park48ca7dc2018-10-10 14:01:00 +090060 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
61 // against the binary policy using sefcontext_compiler -p <policy>.
62
63 // TODO(b/114327326): automate the generation of file_contexts
64 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
65 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010066 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090068 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069 `--file_contexts ${file_contexts} ` +
70 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080071 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090072 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090073 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
74 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000075 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010076 Rspfile: "${out}.copy_commands",
77 RspfileContent: "${copy_commands}",
78 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090079 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080080
Alex Light5098a612018-11-29 17:12:15 -080081 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
82 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010083 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080084 `APEXER_TOOL_PATH=${tool_path} ` +
85 `${apexer} --force --manifest ${manifest} ` +
86 `--payload_type zip ` +
87 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010088 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
89 Rspfile: "${out}.copy_commands",
90 RspfileContent: "${copy_commands}",
91 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080092 }, "tool_path", "image_dir", "copy_commands", "manifest")
93
Colin Crossa4925902018-11-16 11:36:28 -080094 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
95 blueprint.RuleParams{
96 Command: `${aapt2} convert --output-format proto $in -o $out`,
97 CommandDeps: []string{"${aapt2}"},
98 })
99
100 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +0900101 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +0000102 `apex_payload.img:apex/${abi}.img ` +
103 `apex_manifest.json:root/apex_manifest.json ` +
Jaewoong Jungb00c1fb2019-09-04 13:26:18 -0700104 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
105 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
Colin Crossa4925902018-11-16 11:36:28 -0800106 CommandDeps: []string{"${zip2zip}"},
107 Description: "app bundle",
108 }, "abi")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100109
110 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
111 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
112 Rspfile: "${out}.emit_commands",
113 RspfileContent: "${emit_commands}",
114 Description: "Emit APEX image content",
115 }, "emit_commands")
116
117 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
118 Command: `diff --unchanged-group-format='' \` +
119 `--changed-group-format='%<' \` +
120 `${image_content_file} ${whitelisted_files_file} || (` +
121 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
122 ` "To fix the build run following command:" && ` +
123 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
124 `exit 1)`,
125 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
126 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900127)
128
Alex Light5098a612018-11-29 17:12:15 -0800129var imageApexSuffix = ".apex"
130var zipApexSuffix = ".zipapex"
131
132var imageApexType = "image"
133var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900134
135type dependencyTag struct {
136 blueprint.BaseDependencyTag
137 name string
138}
139
140var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900141 sharedLibTag = dependencyTag{name: "sharedLib"}
142 executableTag = dependencyTag{name: "executable"}
143 javaLibTag = dependencyTag{name: "javaLib"}
144 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100145 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900146 keyTag = dependencyTag{name: "key"}
147 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900148 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900149 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900150)
151
152func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700153 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900154 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900155 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100156 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
157 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
158 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
159 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000160 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100161 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
162 } else {
163 return pctx.HostBinToolPath(ctx, tool).String()
164 }
165 })
166 }
167 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900168 pctx.HostBinToolVariable("avbtool", "avbtool")
169 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
170 pctx.HostBinToolVariable("merge_zips", "merge_zips")
171 pctx.HostBinToolVariable("mke2fs", "mke2fs")
172 pctx.HostBinToolVariable("resize2fs", "resize2fs")
173 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
174 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800175 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900176 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900177 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900178
Jiyong Parkd1063c12019-07-17 20:08:41 +0900179 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800180 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900181 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900182 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700183 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900184
Jooyung Han48dd4b52019-10-16 22:43:42 +0000185 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
186 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
187 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
188 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900189 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900190
191 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
192 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
193 sort.Strings(*apexFileContextsInfos)
194 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
195 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900196}
197
198func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
199 ctx.TopDown("apex_deps", apexDepsMutator)
200 ctx.BottomUp("apex", apexMutator).Parallel()
201 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
202 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900203}
204
Jooyung Han344d5432019-08-23 11:17:39 +0900205var (
206 vndkApexListKey = android.NewOnceKey("vndkApexList")
207 vndkApexListMutex sync.Mutex
208)
209
Jooyung Han48dd4b52019-10-16 22:43:42 +0000210func vndkApexList(config android.Config) map[string]*apexBundle {
Jooyung Han344d5432019-08-23 11:17:39 +0900211 return config.Once(vndkApexListKey, func() interface{} {
Jooyung Han48dd4b52019-10-16 22:43:42 +0000212 return map[string]*apexBundle{}
213 }).(map[string]*apexBundle)
Jooyung Han344d5432019-08-23 11:17:39 +0900214}
215
Jooyung Han48dd4b52019-10-16 22:43:42 +0000216// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
217func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
Jooyung Han344d5432019-08-23 11:17:39 +0900218 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
219 if ab.IsNativeBridgeSupported() {
220 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
221 }
Jooyung Han90eee022019-10-01 20:02:42 +0900222
Jooyung Han48dd4b52019-10-16 22:43:42 +0000223 vndkVersion := proptools.String(ab.vndkProperties.Vndk_version)
Jooyung Han90eee022019-10-01 20:02:42 +0900224
Jooyung Han344d5432019-08-23 11:17:39 +0900225 vndkApexListMutex.Lock()
226 defer vndkApexListMutex.Unlock()
227 vndkApexList := vndkApexList(mctx.Config())
228 if other, ok := vndkApexList[vndkVersion]; ok {
Jooyung Han48dd4b52019-10-16 22:43:42 +0000229 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.BaseModuleName())
Jooyung Han344d5432019-08-23 11:17:39 +0900230 }
Jooyung Han48dd4b52019-10-16 22:43:42 +0000231 vndkApexList[vndkVersion] = ab
Jooyung Han344d5432019-08-23 11:17:39 +0900232 }
233}
234
Jooyung Han48dd4b52019-10-16 22:43:42 +0000235// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
236// It filters only libs with matching targets.
237func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
238 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
Jooyung Han344d5432019-08-23 11:17:39 +0900239 vndkApexList := vndkApexList(mctx.Config())
Jooyung Han48dd4b52019-10-16 22:43:42 +0000240 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
241 targetArch := cc.Target().String()
242 for _, target := range ab.MultiTargets() {
243 if target.String() == targetArch {
244 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
245 break
246 }
247 }
Jooyung Han344d5432019-08-23 11:17:39 +0900248 }
249 }
250}
251
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900252// Mark the direct and transitive dependencies of apex bundles so that they
253// can be built for the apex bundles.
254func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800255 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800256 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900257 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900258 depName := mctx.OtherModuleName(child)
259 // If the parent is apexBundle, this child is directly depended.
260 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800261 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800262 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
263 // non-installable apex's cannot be installed and so should not prevent libraries from being
264 // installed to the system.
265 android.UpdateApexDependency(apexBundleName, depName, directDep)
266 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900267
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900268 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900269 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900270 return true
271 } else {
272 return false
273 }
274 })
275 }
276}
277
278// Create apex variations if a module is included in APEX(s).
279func apexMutator(mctx android.BottomUpMutatorContext) {
280 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900281 am.CreateApexVariations(mctx)
Jooyung Han7a78a922019-10-08 21:59:58 +0900282 } else if a, ok := mctx.Module().(*apexBundle); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900283 // apex bundle itself is mutated so that it and its modules have same
284 // apex variant.
285 apexBundleName := mctx.ModuleName()
286 mctx.CreateVariations(apexBundleName)
Jooyung Han7a78a922019-10-08 21:59:58 +0900287
288 // collects APEX list
289 if mctx.Device() && a.installable() {
290 addApexFileContextsInfos(mctx, a)
291 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900292 }
293}
Sundong Ahne9b55722019-09-06 17:37:42 +0900294
Jooyung Han7a78a922019-10-08 21:59:58 +0900295var (
296 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
297 apexFileContextsInfosMutex sync.Mutex
298)
299
300func apexFileContextsInfos(config android.Config) *[]string {
301 return config.Once(apexFileContextsInfosKey, func() interface{} {
302 return &[]string{}
303 }).(*[]string)
304}
305
306func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) {
307 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
308 fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
309
310 apexFileContextsInfosMutex.Lock()
311 defer apexFileContextsInfosMutex.Unlock()
312 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
313 *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName)
314}
315
Sundong Ahne9b55722019-09-06 17:37:42 +0900316func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900317 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900318 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
319 modules := mctx.CreateLocalVariations("", "flattened")
320 modules[0].(*apexBundle).SetFlattened(false)
321 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900322 } else {
323 ab.SetFlattened(true)
324 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900325 }
326 }
327}
328
Jooyung Han5c998b92019-06-27 11:30:33 +0900329func apexUsesMutator(mctx android.BottomUpMutatorContext) {
330 if ab, ok := mctx.Module().(*apexBundle); ok {
331 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
332 }
333}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900334
Alex Light9670d332019-01-29 18:07:33 -0800335type apexNativeDependencies struct {
336 // List of native libraries
337 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900338
Alex Light9670d332019-01-29 18:07:33 -0800339 // List of native executables
340 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900341
Roland Levillain630846d2019-06-26 12:48:34 +0100342 // List of native tests
343 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800344}
Jooyung Han344d5432019-08-23 11:17:39 +0900345
Alex Light9670d332019-01-29 18:07:33 -0800346type apexMultilibProperties struct {
347 // Native dependencies whose compile_multilib is "first"
348 First apexNativeDependencies
349
350 // Native dependencies whose compile_multilib is "both"
351 Both apexNativeDependencies
352
353 // Native dependencies whose compile_multilib is "prefer32"
354 Prefer32 apexNativeDependencies
355
356 // Native dependencies whose compile_multilib is "32"
357 Lib32 apexNativeDependencies
358
359 // Native dependencies whose compile_multilib is "64"
360 Lib64 apexNativeDependencies
361}
362
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900363type apexBundleProperties struct {
364 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000365 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800366 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900367
Jiyong Park40e26a22019-02-08 02:53:06 +0900368 // AndroidManifest.xml file used for the zip container of this APEX bundle.
369 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800370 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900371
Roland Levillain411c5842019-09-19 16:37:20 +0100372 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
373 // device (/apex/<apex_name>).
374 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900375 Apex_name *string
376
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900377 // Determines the file contexts file for setting security context to each file in this APEX bundle.
378 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
379 // used.
380 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900381 File_contexts *string
382
383 // List of native shared libs that are embedded inside this APEX bundle
384 Native_shared_libs []string
385
Roland Levillain630846d2019-06-26 12:48:34 +0100386 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900387 Binaries []string
388
389 // List of java libraries that are embedded inside this APEX bundle
390 Java_libs []string
391
392 // List of prebuilt files that are embedded inside this APEX bundle
393 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900394
Roland Levillain630846d2019-06-26 12:48:34 +0100395 // List of tests that are embedded inside this APEX bundle
396 Tests []string
397
Jiyong Parkff1458f2018-10-12 21:49:38 +0900398 // Name of the apex_key module that provides the private key to sign APEX
399 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900400
Alex Light5098a612018-11-29 17:12:15 -0800401 // The type of APEX to build. Controls what the APEX payload is. Either
402 // 'image', 'zip' or 'both'. Default: 'image'.
403 Payload_type *string
404
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900405 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
406 // or an android_app_certificate module name in the form ":module".
407 Certificate *string
408
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900409 // Whether this APEX is installable to one of the partitions. Default: true.
410 Installable *bool
411
Jiyong Parkda6eb592018-12-19 17:12:36 +0900412 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
413 // Default is false.
414 Use_vendor *bool
415
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800416 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
417 Ignore_system_library_special_case *bool
418
Alex Light9670d332019-01-29 18:07:33 -0800419 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900420
Jiyong Parkf97782b2019-02-13 20:28:58 +0900421 // List of sanitizer names that this APEX is enabled for
422 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900423
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900424 PreventInstall bool `blueprint:"mutated"`
425
426 HideFromMake bool `blueprint:"mutated"`
427
Jooyung Han5c998b92019-06-27 11:30:33 +0900428 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
429 Provide_cpp_shared_libs *bool
430
431 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
432 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100433
434 // A txt file containing list of files that are whitelisted to be included in this APEX.
435 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900436
437 // List of APKs to package inside APEX
438 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900439
Sundong Ahne8fb7242019-09-17 13:50:45 +0900440 // To distinguish between flattened and non-flattened apex.
441 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900442 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900443
Sundong Ahne8fb7242019-09-17 13:50:45 +0900444 // if true, it means that TARGET_FLATTEN_APEX is true and
445 // TARGET_BUILD_APPS is false
446 FlattenedConfigValue bool `blueprint:"mutated"`
447
Jiyong Parkd1063c12019-07-17 20:08:41 +0900448 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
449 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
450 // is implied. This value affects all modules included in this APEX. In other words, they are
451 // also built with the SDKs specified here.
452 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800453}
454
455type apexTargetBundleProperties struct {
456 Target struct {
457 // Multilib properties only for android.
458 Android struct {
459 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900460 }
Jooyung Han344d5432019-08-23 11:17:39 +0900461
Alex Light9670d332019-01-29 18:07:33 -0800462 // Multilib properties only for host.
463 Host struct {
464 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900465 }
Jooyung Han344d5432019-08-23 11:17:39 +0900466
Alex Light9670d332019-01-29 18:07:33 -0800467 // Multilib properties only for host linux_bionic.
468 Linux_bionic struct {
469 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900470 }
Jooyung Han344d5432019-08-23 11:17:39 +0900471
Alex Light9670d332019-01-29 18:07:33 -0800472 // Multilib properties only for host linux_glibc.
473 Linux_glibc struct {
474 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900475 }
476 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900477}
478
Jooyung Han344d5432019-08-23 11:17:39 +0900479type apexVndkProperties struct {
480 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
481 Vndk_version *string
482}
483
Jiyong Park8fd61922018-11-08 02:50:25 +0900484type apexFileClass int
485
486const (
487 etc apexFileClass = iota
488 nativeSharedLib
489 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900490 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800491 pyBinary
492 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900493 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100494 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900495 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900496)
497
Alex Light5098a612018-11-29 17:12:15 -0800498type apexPackaging int
499
500const (
501 imageApex apexPackaging = iota
502 zipApex
503 both
504)
505
506func (a apexPackaging) image() bool {
507 switch a {
508 case imageApex, both:
509 return true
510 }
511 return false
512}
513
514func (a apexPackaging) zip() bool {
515 switch a {
516 case zipApex, both:
517 return true
518 }
519 return false
520}
521
522func (a apexPackaging) suffix() string {
523 switch a {
524 case imageApex:
525 return imageApexSuffix
526 case zipApex:
527 return zipApexSuffix
528 case both:
529 panic(fmt.Errorf("must be either zip or image"))
530 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100531 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800532 }
533}
534
535func (a apexPackaging) name() string {
536 switch a {
537 case imageApex:
538 return imageApexType
539 case zipApex:
540 return zipApexType
541 case both:
542 panic(fmt.Errorf("must be either zip or image"))
543 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100544 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800545 }
546}
547
Jiyong Park8fd61922018-11-08 02:50:25 +0900548func (class apexFileClass) NameInMake() string {
549 switch class {
550 case etc:
551 return "ETC"
552 case nativeSharedLib:
553 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800554 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900555 return "EXECUTABLES"
556 case javaSharedLib:
557 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100558 case nativeTest:
559 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900560 case app:
561 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900562 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100563 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900564 }
565}
566
567type apexFile struct {
568 builtFile android.Path
569 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900570 installDir string
571 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900572 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800573 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900574}
575
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900576type apexBundle struct {
577 android.ModuleBase
578 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900579 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900580
Alex Light9670d332019-01-29 18:07:33 -0800581 properties apexBundleProperties
582 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900583 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900584
Alex Light5098a612018-11-29 17:12:15 -0800585 apexTypes apexPackaging
586
Colin Crossa4925902018-11-16 11:36:28 -0800587 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800588 outputFiles map[apexPackaging]android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700589 flattenedOutput android.InstallPath
590 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900591
Jiyong Park03b68dd2019-07-26 23:20:40 +0900592 prebuiltFileToDelete string
593
Jiyong Park42cca6c2019-04-01 11:15:50 +0900594 public_key_file android.Path
595 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900596
597 container_certificate_file android.Path
598 container_private_key_file android.Path
599
Jiyong Park8fd61922018-11-08 02:50:25 +0900600 // list of files to be included in this apex
601 filesInfo []apexFile
602
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900603 // list of module names that this APEX is depending on
604 externalDeps []string
605
Alex Light0851b882019-02-07 13:20:53 -0800606 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900607 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900608
609 // intermediate path for apex_manifest.json
610 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900611}
612
Jiyong Park397e55e2018-10-24 21:09:55 +0900613func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100614 native_shared_libs []string, binaries []string, tests []string,
615 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900616 // Use *FarVariation* to be able to depend on modules having
617 // conflicting variations with this module. This is required since
618 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
619 // for native shared libs.
620 ctx.AddFarVariationDependencies([]blueprint.Variation{
621 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900622 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900623 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900624 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900625 }, sharedLibTag, native_shared_libs...)
626
627 ctx.AddFarVariationDependencies([]blueprint.Variation{
628 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900629 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900630 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100631
632 ctx.AddFarVariationDependencies([]blueprint.Variation{
633 {Mutator: "arch", Variation: arch},
634 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100635 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100636 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900637}
638
Alex Light9670d332019-01-29 18:07:33 -0800639func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
640 if ctx.Os().Class == android.Device {
641 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
642 } else {
643 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
644 if ctx.Os().Bionic() {
645 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
646 } else {
647 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
648 }
649 }
650}
651
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900652func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han48dd4b52019-10-16 22:43:42 +0000653
Jiyong Park397e55e2018-10-24 21:09:55 +0900654 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900655 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800656
657 a.combineProperties(ctx)
658
Jiyong Park397e55e2018-10-24 21:09:55 +0900659 has32BitTarget := false
660 for _, target := range targets {
661 if target.Arch.ArchType.Multilib == "lib32" {
662 has32BitTarget = true
663 }
664 }
665 for i, target := range targets {
666 // When multilib.* is omitted for native_shared_libs, it implies
667 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900668 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900669 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900670 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900671 {Mutator: "link", Variation: "shared"},
672 }, sharedLibTag, a.properties.Native_shared_libs...)
673
Roland Levillain630846d2019-06-26 12:48:34 +0100674 // When multilib.* is omitted for tests, it implies
675 // multilib.both.
676 ctx.AddFarVariationDependencies([]blueprint.Variation{
677 {Mutator: "arch", Variation: target.String()},
678 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100679 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100680 }, testTag, a.properties.Tests...)
681
Jiyong Park397e55e2018-10-24 21:09:55 +0900682 // Add native modules targetting both ABIs
683 addDependenciesForNativeModules(ctx,
684 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100685 a.properties.Multilib.Both.Binaries,
686 a.properties.Multilib.Both.Tests,
687 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900688 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900689
Alex Light3d673592019-01-18 14:37:31 -0800690 isPrimaryAbi := i == 0
691 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900692 // When multilib.* is omitted for binaries, it implies
693 // multilib.first.
694 ctx.AddFarVariationDependencies([]blueprint.Variation{
695 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900696 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900697 }, executableTag, a.properties.Binaries...)
698
699 // Add native modules targetting the first ABI
700 addDependenciesForNativeModules(ctx,
701 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100702 a.properties.Multilib.First.Binaries,
703 a.properties.Multilib.First.Tests,
704 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900705 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800706
707 // When multilib.* is omitted for prebuilts, it implies multilib.first.
708 ctx.AddFarVariationDependencies([]blueprint.Variation{
709 {Mutator: "arch", Variation: target.String()},
710 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900711 }
712
713 switch target.Arch.ArchType.Multilib {
714 case "lib32":
715 // Add native modules targetting 32-bit ABI
716 addDependenciesForNativeModules(ctx,
717 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100718 a.properties.Multilib.Lib32.Binaries,
719 a.properties.Multilib.Lib32.Tests,
720 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900721 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900722
723 addDependenciesForNativeModules(ctx,
724 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100725 a.properties.Multilib.Prefer32.Binaries,
726 a.properties.Multilib.Prefer32.Tests,
727 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900728 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900729 case "lib64":
730 // Add native modules targetting 64-bit ABI
731 addDependenciesForNativeModules(ctx,
732 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100733 a.properties.Multilib.Lib64.Binaries,
734 a.properties.Multilib.Lib64.Tests,
735 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900736 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900737
738 if !has32BitTarget {
739 addDependenciesForNativeModules(ctx,
740 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100741 a.properties.Multilib.Prefer32.Binaries,
742 a.properties.Multilib.Prefer32.Tests,
743 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900744 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900745 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700746
747 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
748 for _, sanitizer := range ctx.Config().SanitizeDevice() {
749 if sanitizer == "hwaddress" {
750 addDependenciesForNativeModules(ctx,
751 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100752 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700753 break
754 }
755 }
756 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900757 }
758
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900759 }
760
Jiyong Parkff1458f2018-10-12 21:49:38 +0900761 ctx.AddFarVariationDependencies([]blueprint.Variation{
762 {Mutator: "arch", Variation: "android_common"},
763 }, javaLibTag, a.properties.Java_libs...)
764
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900765 ctx.AddFarVariationDependencies([]blueprint.Variation{
766 {Mutator: "arch", Variation: "android_common"},
767 }, androidAppTag, a.properties.Apps...)
768
Jiyong Park23c52b02019-02-02 13:13:47 +0900769 if String(a.properties.Key) == "" {
770 ctx.ModuleErrorf("key is missing")
771 return
772 }
773 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900774
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900775 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900776 if cert != "" {
777 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900778 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900779
780 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
781 if len(a.properties.Uses_sdks) > 0 {
782 sdkRefs := []android.SdkRef{}
783 for _, str := range a.properties.Uses_sdks {
784 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
785 sdkRefs = append(sdkRefs, parsed)
786 }
787 a.BuildWithSdks(sdkRefs)
788 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900789}
790
Colin Cross0ea8ba82019-06-06 14:33:29 -0700791func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900792 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
793 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000794 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900795 }
796 return String(a.properties.Certificate)
797}
798
Colin Cross41955e82019-05-29 14:40:35 -0700799func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
800 switch tag {
801 case "":
802 if file, ok := a.outputFiles[imageApex]; ok {
803 return android.Paths{file}, nil
804 } else {
805 return nil, nil
806 }
Roland Levillain935639d2019-08-13 14:55:28 +0100807 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900808 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100809 flattenedApexPath := a.flattenedOutput
810 return android.Paths{flattenedApexPath}, nil
811 } else {
812 return nil, nil
813 }
Colin Cross41955e82019-05-29 14:40:35 -0700814 default:
815 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900816 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900817}
818
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900819func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900820 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900821}
822
Jiyong Park7c1dc612019-01-05 11:15:24 +0900823func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
824 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900825 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900826 } else {
827 return "core"
828 }
829}
830
Jiyong Parkf97782b2019-02-13 20:28:58 +0900831func (a *apexBundle) EnableSanitizer(sanitizerName string) {
832 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
833 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
834 }
835}
836
Jiyong Park388ef3f2019-01-28 19:47:32 +0900837func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900838 if android.InList(sanitizerName, a.properties.SanitizerNames) {
839 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900840 }
841
842 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900843 globalSanitizerNames := []string{}
844 if a.Host() {
845 globalSanitizerNames = ctx.Config().SanitizeHost()
846 } else {
847 arches := ctx.Config().SanitizeDeviceArch()
848 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
849 globalSanitizerNames = ctx.Config().SanitizeDevice()
850 }
851 }
852 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900853}
854
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900855func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
856 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
857}
858
859func (a *apexBundle) PreventInstall() {
860 a.properties.PreventInstall = true
861}
862
863func (a *apexBundle) HideFromMake() {
864 a.properties.HideFromMake = true
865}
866
Sundong Ahne9b55722019-09-06 17:37:42 +0900867func (a *apexBundle) SetFlattened(flattened bool) {
868 a.properties.Flattened = flattened
869}
870
Sundong Ahne8fb7242019-09-17 13:50:45 +0900871func (a *apexBundle) SetFlattenedConfigValue() {
872 a.properties.FlattenedConfigValue = true
873}
874
875// isFlattenedVariant returns true when the current module is the flattened
876// variant of an apex that has both a flattened and an unflattened variant.
877// It returns false when the current module is flattened but there is no
878// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
879// true. It can be used to avoid collisions between the install paths of the
880// flattened and unflattened variants.
881func (a *apexBundle) isFlattenedVariant() bool {
882 return a.properties.Flattened && !a.properties.FlattenedConfigValue
883}
884
Martin Stjernholm279de572019-09-10 23:18:20 +0100885func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900886 // Decide the APEX-local directory by the multilib of the library
887 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100888 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900889 case "lib32":
890 dirInApex = "lib"
891 case "lib64":
892 dirInApex = "lib64"
893 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100894 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700895 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100896 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900897 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100898 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
899 // Special case for Bionic libs and other libs installed with them. This is
900 // to prevent those libs from being included in the search path
901 // /apex/com.android.runtime/${LIB}. This exclusion is required because
902 // those libs in the Runtime APEX are available via the legacy paths in
903 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
904 // to the legacy paths and thus will be loaded into the default linker
905 // namespace (aka "platform" namespace). If the libs are directly in
906 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
907 // into the runtime linker namespace, which will result in double loading of
908 // them, which isn't supported.
909 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900910 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900911
Martin Stjernholm279de572019-09-10 23:18:20 +0100912 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900913 return
914}
915
916func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900917 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700918 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200919 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900920 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900921 fileToCopy = cc.OutputFile().Path()
922 return
923}
924
Alex Light778127a2019-02-27 14:19:50 -0800925func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
926 dirInApex = "bin"
927 fileToCopy = py.HostToolPath().Path()
928 return
929}
930func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
931 dirInApex = "bin"
932 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
933 if err != nil {
934 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
935 return
936 }
937 fileToCopy = android.PathForOutput(ctx, s)
938 return
939}
940
Jiyong Park04480cf2019-02-06 00:16:29 +0900941func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
942 dirInApex = filepath.Join("bin", sh.SubDir())
943 fileToCopy = sh.OutputFile()
944 return
945}
946
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900947func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
948 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900949 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900950 return
951}
952
Jiyong Park9e6c2422019-08-09 20:39:45 +0900953func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
954 dirInApex = "javalib"
955 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
956 implJars := java.ImplementationJars()
957 if len(implJars) != 1 {
958 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
959 strings.Join(implJars.Strings(), ", ")))
960 }
961 fileToCopy = implJars[0]
962 return
963}
964
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
966 dirInApex = filepath.Join("etc", prebuilt.SubDir())
967 fileToCopy = prebuilt.OutputFile()
968 return
969}
970
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900971func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
972 dirInApex = filepath.Join("app", pkgName)
973 fileToCopy = app.OutputFile()
974 return
975}
976
Roland Levillain935639d2019-08-13 14:55:28 +0100977// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
978type flattenedApexContext struct {
979 android.ModuleContext
980}
981
982func (c *flattenedApexContext) InstallBypassMake() bool {
983 return true
984}
985
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900986func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900987 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900988
Alex Light5098a612018-11-29 17:12:15 -0800989 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
990 a.apexTypes = imageApex
991 } else if *a.properties.Payload_type == "zip" {
992 a.apexTypes = zipApex
993 } else if *a.properties.Payload_type == "both" {
994 a.apexTypes = both
995 } else {
996 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
997 return
998 }
999
Roland Levillain630846d2019-06-26 12:48:34 +01001000 if len(a.properties.Tests) > 0 && !a.testApex {
1001 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1002 return
1003 }
1004
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001005 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1006
Jooyung Hane1633032019-08-01 17:41:43 +09001007 // native lib dependencies
1008 var provideNativeLibs []string
1009 var requireNativeLibs []string
1010
Jooyung Han5c998b92019-06-27 11:30:33 +09001011 // Check if "uses" requirements are met with dependent apexBundles
1012 var providedNativeSharedLibs []string
1013 useVendor := proptools.Bool(a.properties.Use_vendor)
1014 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1015 if ctx.OtherModuleDependencyTag(m) != usesTag {
1016 return
1017 }
1018 otherName := ctx.OtherModuleName(m)
1019 other, ok := m.(*apexBundle)
1020 if !ok {
1021 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1022 return
1023 }
1024 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1025 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1026 return
1027 }
1028 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1029 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1030 return
1031 }
1032 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1033 })
1034
Alex Light778127a2019-02-27 14:19:50 -08001035 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001036 depTag := ctx.OtherModuleDependencyTag(child)
1037 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001038 if _, ok := parent.(*apexBundle); ok {
1039 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001040 switch depTag {
1041 case sharedLibTag:
1042 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001043 if cc.HasStubsVariants() {
1044 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1045 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001046 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001047 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001048 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001049 } else {
1050 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001051 }
1052 case executableTag:
1053 if cc, ok := child.(*cc.Module); ok {
1054 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001055 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001057 } else if sh, ok := child.(*android.ShBinary); ok {
1058 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -07001059 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
Alex Light778127a2019-02-27 14:19:50 -08001060 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1061 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1062 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1063 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1064 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1065 // NB: Since go binaries are static we don't need the module for anything here, which is
1066 // good since the go tool is a blueprint.Module not an android.Module like we would
1067 // normally use.
1068 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001069 } else {
Alex Light778127a2019-02-27 14:19:50 -08001070 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 +09001071 }
1072 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001073 if javaLib, ok := child.(*java.Library); ok {
1074 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001075 if fileToCopy == nil {
1076 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1077 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001078 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1079 }
1080 return true
1081 } else if javaLib, ok := child.(*java.Import); ok {
1082 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1083 if fileToCopy == nil {
1084 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1085 } else {
1086 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001087 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001088 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001089 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001090 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001091 }
1092 case prebuiltTag:
1093 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1094 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001095 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001096 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001097 } else {
1098 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1099 }
Roland Levillain630846d2019-06-26 12:48:34 +01001100 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001101 if ccTest, ok := child.(*cc.Module); ok {
1102 if ccTest.IsTestPerSrcAllTestsVariation() {
1103 // Multiple-output test module (where `test_per_src: true`).
1104 //
1105 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1106 // We do not add this variation to `filesInfo`, as it has no output;
1107 // however, we do add the other variations of this module as indirect
1108 // dependencies (see below).
1109 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001110 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001111 // Single-output test module (where `test_per_src: false`).
1112 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1113 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001114 }
Roland Levillain630846d2019-06-26 12:48:34 +01001115 return true
1116 } else {
1117 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1118 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001119 case keyTag:
1120 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001121 a.private_key_file = key.private_key_file
1122 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001123 return false
1124 } else {
1125 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001126 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001127 case certificateTag:
1128 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001129 a.container_certificate_file = dep.Certificate.Pem
1130 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001131 return false
1132 } else {
1133 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1134 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001135 case android.PrebuiltDepTag:
1136 // If the prebuilt is force disabled, remember to delete the prebuilt file
1137 // that might have been installed in the previous builds
1138 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1139 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1140 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001141 case androidAppTag:
1142 if ap, ok := child.(*java.AndroidApp); ok {
1143 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1144 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1145 return true
1146 } else {
1147 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1148 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001149 }
1150 } else {
1151 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001152 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001153 // We cannot use a switch statement on `depTag` here as the checked
1154 // tags used below are private (e.g. `cc.sharedDepTag`).
1155 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1156 if cc, ok := child.(*cc.Module); ok {
1157 if android.InList(cc.Name(), providedNativeSharedLibs) {
1158 // If we're using a shared library which is provided from other APEX,
1159 // don't include it in this APEX
1160 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001161 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001162 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1163 // If the dependency is a stubs lib, don't include it in this APEX,
1164 // but make sure that the lib is installed on the device.
1165 // In case no APEX is having the lib, the lib is installed to the system
1166 // partition.
1167 //
1168 // Always include if we are a host-apex however since those won't have any
1169 // system libraries.
1170 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1171 a.externalDeps = append(a.externalDeps, cc.Name())
1172 }
Jooyung Hane1633032019-08-01 17:41:43 +09001173 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001174 // Don't track further
1175 return false
1176 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001177 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001178 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1179 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001180 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001181 } else if cc.IsTestPerSrcDepTag(depTag) {
1182 if cc, ok := child.(*cc.Module); ok {
1183 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1184 // Handle modules created as `test_per_src` variations of a single test module:
1185 // use the name of the generated test binary (`fileToCopy`) instead of the name
1186 // of the original test module (`depName`, shared by all `test_per_src`
1187 // variations of that module).
1188 moduleName := filepath.Base(fileToCopy.String())
1189 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1190 return true
1191 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001192 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001193 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001194 }
1195 }
1196 }
1197 return false
1198 })
1199
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001200 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001201 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1202 return
1203 }
1204
Jiyong Park8fd61922018-11-08 02:50:25 +09001205 // remove duplicates in filesInfo
1206 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001207 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001208 result := []apexFile{}
1209 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001210 dest := filepath.Join(f.installDir, f.builtFile.Base())
1211 if !encountered[dest] {
1212 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001213 result = append(result, f)
1214 }
1215 }
1216 return result
1217 }
1218 filesInfo = removeDup(filesInfo)
1219
1220 // to have consistent build rules
1221 sort.Slice(filesInfo, func(i, j int) bool {
1222 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1223 })
1224
Jiyong Park127b40b2019-09-30 16:04:35 +09001225 // check apex_available requirements
Jiyong Park583a2262019-10-08 20:55:38 +09001226 if !ctx.Host() {
1227 for _, fi := range filesInfo {
1228 if am, ok := fi.module.(android.ApexModule); ok {
1229 if !am.AvailableFor(ctx.ModuleName()) {
1230 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
1231 return
1232 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001233 }
1234 }
1235 }
1236
Jiyong Park8fd61922018-11-08 02:50:25 +09001237 // prepend the name of this APEX to the module names. These names will be the names of
1238 // modules that will be defined if the APEX is flattened.
1239 for i := range filesInfo {
Jooyung Han48dd4b52019-10-16 22:43:42 +00001240 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
Jiyong Park8fd61922018-11-08 02:50:25 +09001241 }
1242
Jiyong Park8fd61922018-11-08 02:50:25 +09001243 a.installDir = android.PathForModuleInstall(ctx, "apex")
1244 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001245
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001246 // prepare apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001247 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
Jooyung Hane1633032019-08-01 17:41:43 +09001248 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001249
1250 // put dependency({provide|require}NativeLibs) in apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001251 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1252 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001253
1254 // apex name can be overridden
1255 optCommands := []string{}
1256 if a.properties.Apex_name != nil {
1257 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
1258 }
1259
Jooyung Hane1633032019-08-01 17:41:43 +09001260 ctx.Build(pctx, android.BuildParams{
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001261 Rule: apexManifestRule,
Jooyung Hane1633032019-08-01 17:41:43 +09001262 Input: manifestSrc,
1263 Output: a.manifestOut,
1264 Args: map[string]string{
1265 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1266 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001267 "opt": strings.Join(optCommands, " "),
Jooyung Hane1633032019-08-01 17:41:43 +09001268 },
1269 })
1270
Roland Levillain935639d2019-08-13 14:55:28 +01001271 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1272 // reply true to `InstallBypassMake()` (thus making the call
1273 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1274 // instead of `android.PathForOutput`) to return the correct path to the flattened
1275 // APEX (as its contents is installed by Make, not Soong).
1276 factx := flattenedApexContext{ctx}
Jooyung Han7a78a922019-10-08 21:59:58 +09001277 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
1278 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", apexName)
Roland Levillain935639d2019-08-13 14:55:28 +01001279
Alex Light5098a612018-11-29 17:12:15 -08001280 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001281 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001282 }
1283 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001284 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001285 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001286 // in other modules. It is in AndroidMk where the selection of flattened
1287 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001288 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001289 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001290 }
1291}
1292
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001293func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001294 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001295 for _, f := range a.filesInfo {
1296 if f.module != nil {
1297 notice := f.module.NoticeFile()
1298 if notice.Valid() {
1299 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001300 }
1301 }
1302 }
1303 // append the notice file specified in the apex module itself
1304 if a.NoticeFile().Valid() {
1305 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001306 }
1307
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001308 if len(noticeFiles) == 0 {
1309 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001310 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001311
Jaewoong Jung98772792019-07-01 17:15:13 -07001312 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001313}
1314
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001315func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001316 cert := String(a.properties.Certificate)
1317 if cert != "" && android.SrcIsModule(cert) == "" {
1318 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001319 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1320 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001321 } else if cert == "" {
1322 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001323 a.container_certificate_file = pem
1324 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001325 }
1326
Alex Light5098a612018-11-29 17:12:15 -08001327 var abis []string
1328 for _, target := range ctx.MultiTargets() {
1329 if len(target.Arch.Abi) > 0 {
1330 abis = append(abis, target.Arch.Abi[0])
1331 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001332 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001333
Alex Light5098a612018-11-29 17:12:15 -08001334 abis = android.FirstUniqueStrings(abis)
1335
1336 suffix := apexType.suffix()
1337 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001338
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001339 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001340 for _, f := range a.filesInfo {
1341 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001342 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001343
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001344 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001345 emitCommands := []string{}
1346 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1347 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001348 for i, src := range filesToCopy {
1349 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001350 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001351 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001352 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1353 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001354 for _, sym := range a.filesInfo[i].symlinks {
1355 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1356 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1357 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001358 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001359 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001360 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001361
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001362 if a.properties.Whitelisted_files != nil {
1363 ctx.Build(pctx, android.BuildParams{
1364 Rule: emitApexContentRule,
1365 Implicits: implicitInputs,
1366 Output: imageContentFile,
1367 Description: "emit apex image content",
1368 Args: map[string]string{
1369 "emit_commands": strings.Join(emitCommands, " && "),
1370 },
1371 })
1372 implicitInputs = append(implicitInputs, imageContentFile)
1373 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1374
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001375 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001376 ctx.Build(pctx, android.BuildParams{
1377 Rule: diffApexContentRule,
1378 Implicits: implicitInputs,
1379 Output: phonyOutput,
1380 Description: "diff apex image content",
1381 Args: map[string]string{
1382 "whitelisted_files_file": whitelistedFilesFile.String(),
1383 "image_content_file": imageContentFile.String(),
1384 "apex_module_name": ctx.ModuleName(),
1385 },
1386 })
1387
1388 implicitInputs = append(implicitInputs, phonyOutput)
1389 }
1390
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001391 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1392 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001393
Alex Light5098a612018-11-29 17:12:15 -08001394 if apexType.image() {
1395 // files and dirs that will be created in APEX
1396 var readOnlyPaths []string
1397 var executablePaths []string // this also includes dirs
1398 for _, f := range a.filesInfo {
1399 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001400 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001401 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001402 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001403 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001404 }
Alex Light5098a612018-11-29 17:12:15 -08001405 } else {
1406 readOnlyPaths = append(readOnlyPaths, pathInApex)
1407 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001408 dir := f.installDir
1409 for !android.InList(dir, executablePaths) && dir != "" {
1410 executablePaths = append(executablePaths, dir)
1411 dir, _ = filepath.Split(dir) // move up to the parent
1412 if len(dir) > 0 {
1413 // remove trailing slash
1414 dir = dir[:len(dir)-1]
1415 }
Alex Light5098a612018-11-29 17:12:15 -08001416 }
1417 }
1418 sort.Strings(readOnlyPaths)
1419 sort.Strings(executablePaths)
1420 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1421 ctx.Build(pctx, android.BuildParams{
1422 Rule: generateFsConfig,
1423 Output: cannedFsConfig,
1424 Description: "generate fs config",
1425 Args: map[string]string{
1426 "ro_paths": strings.Join(readOnlyPaths, " "),
1427 "exec_paths": strings.Join(executablePaths, " "),
1428 },
1429 })
1430
1431 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1432 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1433 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1434 if !fileContextsOptionalPath.Valid() {
1435 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1436 return
1437 }
1438 fileContexts := fileContextsOptionalPath.Path()
1439
Jiyong Park835d82b2018-12-27 16:04:18 +09001440 optFlags := []string{}
1441
Alex Light5098a612018-11-29 17:12:15 -08001442 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001443 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1444 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001445
Jiyong Park7f67f482019-01-05 12:57:48 +09001446 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1447 if overridden {
1448 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1449 }
1450
Jiyong Park40e26a22019-02-08 02:53:06 +09001451 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001452 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001453 implicitInputs = append(implicitInputs, androidManifestFile)
1454 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1455 }
1456
Jiyong Park71b519d2019-04-18 17:25:49 +09001457 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1458 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1459 ctx.Config().UnbundledBuild() &&
1460 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1461 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1462 apiFingerprint := java.ApiFingerprintPath(ctx)
1463 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1464 implicitInputs = append(implicitInputs, apiFingerprint)
1465 }
1466 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1467
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001468 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1469 if noticeFile.Valid() {
1470 // If there's a NOTICE file, embed it as an asset file in the APEX.
1471 implicitInputs = append(implicitInputs, noticeFile.Path())
1472 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1473 }
1474
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001475 if !ctx.Config().UnbundledBuild() && a.installable() {
1476 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1477 // don't need hashtree for activation. Therefore, by removing hashtree from
1478 // apex bundle (filesystem image in it, to be specific), we can save storage.
1479 optFlags = append(optFlags, "--no_hashtree")
1480 }
1481
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001482 if a.properties.Apex_name != nil {
1483 // If apex_name is set, apexer can skip checking if key name matches with apex name.
1484 // Note that apex_manifest is also mended.
1485 optFlags = append(optFlags, "--do_not_check_keyname")
1486 }
1487
Alex Light5098a612018-11-29 17:12:15 -08001488 ctx.Build(pctx, android.BuildParams{
1489 Rule: apexRule,
1490 Implicits: implicitInputs,
1491 Output: unsignedOutputFile,
1492 Description: "apex (" + apexType.name() + ")",
1493 Args: map[string]string{
1494 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1495 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1496 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001497 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001498 "file_contexts": fileContexts.String(),
1499 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001500 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001501 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001502 },
1503 })
1504
1505 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1506 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1507 a.bundleModuleFile = bundleModuleFile
1508
1509 ctx.Build(pctx, android.BuildParams{
1510 Rule: apexProtoConvertRule,
1511 Input: unsignedOutputFile,
1512 Output: apexProtoFile,
1513 Description: "apex proto convert",
1514 })
1515
1516 ctx.Build(pctx, android.BuildParams{
1517 Rule: apexBundleRule,
1518 Input: apexProtoFile,
1519 Output: a.bundleModuleFile,
1520 Description: "apex bundle module",
1521 Args: map[string]string{
1522 "abi": strings.Join(abis, "."),
1523 },
1524 })
1525 } else {
1526 ctx.Build(pctx, android.BuildParams{
1527 Rule: zipApexRule,
1528 Implicits: implicitInputs,
1529 Output: unsignedOutputFile,
1530 Description: "apex (" + apexType.name() + ")",
1531 Args: map[string]string{
1532 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1533 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1534 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001535 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001536 },
1537 })
Colin Crossa4925902018-11-16 11:36:28 -08001538 }
Colin Crossa4925902018-11-16 11:36:28 -08001539
Alex Light5098a612018-11-29 17:12:15 -08001540 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001541 ctx.Build(pctx, android.BuildParams{
1542 Rule: java.Signapk,
1543 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001544 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001545 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001546 Implicits: []android.Path{
1547 a.container_certificate_file,
1548 a.container_private_key_file,
1549 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001550 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001551 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001552 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001553 },
1554 })
Alex Light5098a612018-11-29 17:12:15 -08001555
1556 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001557 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001558 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001559 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001560}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001561
Jiyong Park8fd61922018-11-08 02:50:25 +09001562func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001563 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001564 // 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 +09001565 // with other ordinary files.
Jooyung Han48dd4b52019-10-16 22:43:42 +00001566 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001567
Jiyong Park42cca6c2019-04-01 11:15:50 +09001568 // rename to apex_pubkey
1569 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1570 ctx.Build(pctx, android.BuildParams{
1571 Rule: android.Cp,
1572 Input: a.public_key_file,
1573 Output: copiedPubkey,
1574 })
Jooyung Han48dd4b52019-10-16 22:43:42 +00001575 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
Jiyong Park42cca6c2019-04-01 11:15:50 +09001576
Jiyong Park23c52b02019-02-02 13:13:47 +09001577 if ctx.Config().FlattenApex() {
Jooyung Han7a78a922019-10-08 21:59:58 +09001578 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
Jiyong Park23c52b02019-02-02 13:13:47 +09001579 for _, fi := range a.filesInfo {
Jooyung Han7a78a922019-10-08 21:59:58 +09001580 dir := filepath.Join("apex", apexName, fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001581 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1582 for _, sym := range fi.symlinks {
1583 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1584 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001585 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001586 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001587 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001588}
1589
1590func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001591 if a.properties.HideFromMake {
1592 return android.AndroidMkData{
1593 Disabled: true,
1594 }
1595 }
Alex Light5098a612018-11-29 17:12:15 -08001596 writers := []android.AndroidMkData{}
1597 if a.apexTypes.image() {
1598 writers = append(writers, a.androidMkForType(imageApex))
1599 }
1600 if a.apexTypes.zip() {
1601 writers = append(writers, a.androidMkForType(zipApex))
1602 }
1603 return android.AndroidMkData{
1604 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1605 for _, data := range writers {
1606 data.Custom(w, name, prefix, moduleDir, data)
1607 }
1608 }}
1609}
1610
Jooyung Han7a78a922019-10-08 21:59:58 +09001611func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001612 moduleNames := []string{}
1613
1614 for _, fi := range a.filesInfo {
1615 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1616 continue
1617 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001618 if a.properties.Flattened && !apexType.image() {
1619 continue
Jiyong Park94427262019-02-05 23:18:47 +09001620 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001621
1622 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001623 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001624 suffix = ".flattened"
1625 }
1626
1627 if !android.InList(fi.moduleName, moduleNames) {
1628 moduleNames = append(moduleNames, fi.moduleName+suffix)
1629 }
1630
Jiyong Park94427262019-02-05 23:18:47 +09001631 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1632 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001633 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001634 // /apex/<apex_name>/{lib|framework|...}
Jooyung Han7a78a922019-10-08 21:59:58 +09001635 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001636 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001637 // /system/apex/<name>/{lib|framework|...}
Colin Crossff6c33d2019-10-02 16:01:35 -07001638 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
Jooyung Han7a78a922019-10-08 21:59:58 +09001639 apexName, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001640 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001641 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1642 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001643 if len(fi.symlinks) > 0 {
1644 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1645 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001646
1647 if fi.module != nil && fi.module.NoticeFile().Valid() {
1648 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1649 }
Jiyong Park94427262019-02-05 23:18:47 +09001650 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001651 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001652 }
1653 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1654 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1655 if fi.module != nil {
1656 archStr := fi.module.Target().Arch.ArchType.String()
1657 host := false
1658 switch fi.module.Target().Os.Class {
1659 case android.Host:
1660 if archStr != "common" {
1661 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1662 }
1663 host = true
1664 case android.HostCross:
1665 if archStr != "common" {
1666 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1667 }
1668 host = true
1669 case android.Device:
1670 if archStr != "common" {
1671 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1672 }
1673 }
1674 if host {
1675 makeOs := fi.module.Target().Os.String()
1676 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1677 makeOs = "linux"
1678 }
1679 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1680 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1681 }
1682 }
1683 if fi.class == javaSharedLib {
1684 javaModule := fi.module.(*java.Library)
1685 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1686 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1687 // we will have foo.jar.jar
1688 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1689 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1690 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1691 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1692 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1693 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001694 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001695 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001696 if cc, ok := fi.module.(*cc.Module); ok {
1697 if cc.UnstrippedOutputFile() != nil {
1698 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1699 }
1700 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001701 if cc.CoverageOutputFile().Valid() {
1702 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1703 }
Jiyong Park94427262019-02-05 23:18:47 +09001704 }
1705 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1706 } else {
1707 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1708 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1709 }
1710 }
1711 return moduleNames
1712}
1713
Alex Light5098a612018-11-29 17:12:15 -08001714func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001715 return android.AndroidMkData{
1716 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1717 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001718 if a.installable() {
Jooyung Han7a78a922019-10-08 21:59:58 +09001719 apexName := proptools.StringDefault(a.properties.Apex_name, name)
1720 moduleNames = a.androidMkForFiles(w, apexName, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001721 }
1722
Sundong Ahne8fb7242019-09-17 13:50:45 +09001723 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001724 name = name + ".flattened"
1725 }
1726
1727 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001728 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001729 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1730 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1731 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001732 if len(moduleNames) > 0 {
1733 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1734 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001735 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001736 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1737
Sundong Ahne8fb7242019-09-17 13:50:45 +09001738 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001739 // zip-apex is the less common type so have the name refer to the image-apex
1740 // only and use {name}.zip if you want the zip-apex
1741 if apexType == zipApex && a.apexTypes == both {
1742 name = name + ".zip"
1743 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001744 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1745 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1746 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1747 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001748 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Colin Crossff6c33d2019-10-02 16:01:35 -07001749 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
Colin Cross189ff982019-01-02 22:32:27 -08001750 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001751 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001752 if len(moduleNames) > 0 {
1753 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1754 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001755 if len(a.externalDeps) > 0 {
1756 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1757 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001758 if a.prebuiltFileToDelete != "" {
1759 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
Colin Crossff6c33d2019-10-02 16:01:35 -07001760 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
Jiyong Park03b68dd2019-07-26 23:20:40 +09001761 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001762 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001763
Alex Light5098a612018-11-29 17:12:15 -08001764 if apexType == imageApex {
1765 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1766 }
Jiyong Park719b4462019-01-13 00:39:51 +09001767 }
1768 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001769}
1770
Jooyung Han344d5432019-08-23 11:17:39 +09001771func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001772 module := &apexBundle{
1773 outputFiles: map[apexPackaging]android.WritablePath{},
1774 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001775 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001776 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001777 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001778 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1779 })
Alex Light5098a612018-11-29 17:12:15 -08001780 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001781 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001782 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001783 return module
1784}
Jiyong Park30ca9372019-02-07 16:27:23 +09001785
Jooyung Han344d5432019-08-23 11:17:39 +09001786func ApexBundleFactory(testApex bool) android.Module {
1787 bundle := newApexBundle()
1788 bundle.testApex = testApex
1789 return bundle
1790}
1791
1792func testApexBundleFactory() android.Module {
1793 bundle := newApexBundle()
1794 bundle.testApex = true
1795 return bundle
1796}
1797
Jiyong Parkd1063c12019-07-17 20:08:41 +09001798func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001799 return newApexBundle()
1800}
1801
1802// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1803// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1804// If not specified, then the "current" versions are gathered.
1805func vndkApexBundleFactory() android.Module {
1806 bundle := newApexBundle()
1807 bundle.vndkApex = true
1808 bundle.AddProperties(&bundle.vndkProperties)
1809 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1810 ctx.AppendProperties(&struct {
1811 Compile_multilib *string
1812 }{
1813 proptools.StringPtr("both"),
1814 })
Jooyung Han48dd4b52019-10-16 22:43:42 +00001815
1816 vndkVersion := proptools.StringDefault(bundle.vndkProperties.Vndk_version, "current")
1817 if vndkVersion == "current" {
1818 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1819 bundle.vndkProperties.Vndk_version = proptools.StringPtr(vndkVersion)
1820 }
1821
1822 // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
1823 bundle.properties.Apex_name = proptools.StringPtr("com.android.vndk.v" + vndkVersion)
Jooyung Han344d5432019-08-23 11:17:39 +09001824 })
1825 return bundle
1826}
1827
Jiyong Park30ca9372019-02-07 16:27:23 +09001828//
1829// Defaults
1830//
1831type Defaults struct {
1832 android.ModuleBase
1833 android.DefaultsModuleBase
1834}
1835
Jiyong Park30ca9372019-02-07 16:27:23 +09001836func defaultsFactory() android.Module {
1837 return DefaultsFactory()
1838}
1839
1840func DefaultsFactory(props ...interface{}) android.Module {
1841 module := &Defaults{}
1842
1843 module.AddProperties(props...)
1844 module.AddProperties(
1845 &apexBundleProperties{},
1846 &apexTargetBundleProperties{},
1847 )
1848
1849 android.InitDefaultsModule(module)
1850 return module
1851}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001852
1853//
1854// Prebuilt APEX
1855//
1856type Prebuilt struct {
1857 android.ModuleBase
1858 prebuilt android.Prebuilt
1859
1860 properties PrebuiltProperties
1861
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001862 inputApex android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001863 installDir android.InstallPath
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001864 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001865 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001866}
1867
1868type PrebuiltProperties struct {
1869 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001870 Source string `blueprint:"mutated"`
1871 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001872
1873 Src *string
1874 Arch struct {
1875 Arm struct {
1876 Src *string
1877 }
1878 Arm64 struct {
1879 Src *string
1880 }
1881 X86 struct {
1882 Src *string
1883 }
1884 X86_64 struct {
1885 Src *string
1886 }
1887 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001888
1889 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001890 // Optional name for the installed apex. If unspecified, name of the
1891 // module is used as the file name
1892 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001893
1894 // Names of modules to be overridden. Listed modules can only be other binaries
1895 // (in Make or Soong).
1896 // This does not completely prevent installation of the overridden binaries, but if both
1897 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1898 // from PRODUCT_PACKAGES.
1899 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001900}
1901
1902func (p *Prebuilt) installable() bool {
1903 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001904}
1905
1906func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001907 // If the device is configured to use flattened APEX, force disable the prebuilt because
1908 // the prebuilt is a non-flattened one.
1909 forceDisable := ctx.Config().FlattenApex()
1910
1911 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1912 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001913 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001914
Kun Niu10c9f832019-07-29 16:28:57 -07001915 // Force disable the prebuilts when coverage is enabled.
1916 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1917 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1918
Jiyong Park50b81e52019-07-11 11:24:41 +09001919 // b/137216042 don't use prebuilts when address sanitizer is on
1920 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1921 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1922
1923 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001924 p.properties.ForceDisable = true
1925 return
1926 }
1927
Jiyong Parkc95714e2019-03-29 14:23:10 +09001928 // This is called before prebuilt_select and prebuilt_postdeps mutators
1929 // The mutators requires that src to be set correctly for each arch so that
1930 // arch variants are disabled when src is not provided for the arch.
1931 if len(ctx.MultiTargets()) != 1 {
1932 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1933 return
1934 }
1935 var src string
1936 switch ctx.MultiTargets()[0].Arch.ArchType {
1937 case android.Arm:
1938 src = String(p.properties.Arch.Arm.Src)
1939 case android.Arm64:
1940 src = String(p.properties.Arch.Arm64.Src)
1941 case android.X86:
1942 src = String(p.properties.Arch.X86.Src)
1943 case android.X86_64:
1944 src = String(p.properties.Arch.X86_64.Src)
1945 default:
1946 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1947 return
1948 }
1949 if src == "" {
1950 src = String(p.properties.Src)
1951 }
1952 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001953}
1954
Jiyong Park03b68dd2019-07-26 23:20:40 +09001955func (p *Prebuilt) isForceDisabled() bool {
1956 return p.properties.ForceDisable
1957}
1958
Colin Cross41955e82019-05-29 14:40:35 -07001959func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1960 switch tag {
1961 case "":
1962 return android.Paths{p.outputApex}, nil
1963 default:
1964 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1965 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001966}
1967
Jiyong Park4d277042019-04-23 18:00:10 +09001968func (p *Prebuilt) InstallFilename() string {
1969 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1970}
1971
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001972func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001973 if p.properties.ForceDisable {
1974 return
1975 }
1976
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001977 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001978 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001979 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001980 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001981 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1982 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1983 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001984 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1985 ctx.Build(pctx, android.BuildParams{
1986 Rule: android.Cp,
1987 Input: p.inputApex,
1988 Output: p.outputApex,
1989 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001990 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001991 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001992 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001993}
1994
1995func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1996 return &p.prebuilt
1997}
1998
1999func (p *Prebuilt) Name() string {
2000 return p.prebuilt.Name(p.ModuleBase.Name())
2001}
2002
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002003func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
2004 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002005 Class: "ETC",
2006 OutputFile: android.OptionalPathForPath(p.inputApex),
2007 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07002008 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
2009 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -07002010 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07002011 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
2012 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
2013 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
2014 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002015 },
2016 }
2017}
2018
2019// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
2020func PrebuiltFactory() android.Module {
2021 module := &Prebuilt{}
2022 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07002023 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09002024 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002025 return module
2026}