blob: 3c32004ed54ebabdd2735ed469cb284e6615ec19 [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 Han394951d2019-10-07 15:34:50 +0900185 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900186 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900187
188 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
189 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
190 sort.Strings(*apexFileContextsInfos)
191 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
192 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900193}
194
Jooyung Han394951d2019-10-07 15:34:50 +0900195func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
196 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
197 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
198}
199
Jiyong Parkd1063c12019-07-17 20:08:41 +0900200func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
201 ctx.TopDown("apex_deps", apexDepsMutator)
202 ctx.BottomUp("apex", apexMutator).Parallel()
203 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
204 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900205}
206
Jooyung Han344d5432019-08-23 11:17:39 +0900207var (
208 vndkApexListKey = android.NewOnceKey("vndkApexList")
209 vndkApexListMutex sync.Mutex
210)
211
Jooyung Han394951d2019-10-07 15:34:50 +0900212func vndkApexList(config android.Config) map[string]string {
Jooyung Han344d5432019-08-23 11:17:39 +0900213 return config.Once(vndkApexListKey, func() interface{} {
Jooyung Han394951d2019-10-07 15:34:50 +0900214 return map[string]string{}
215 }).(map[string]string)
Jooyung Han344d5432019-08-23 11:17:39 +0900216}
217
Jooyung Han394951d2019-10-07 15:34:50 +0900218func apexVndkMutator(mctx android.TopDownMutatorContext) {
Jooyung Han344d5432019-08-23 11:17:39 +0900219 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
220 if ab.IsNativeBridgeSupported() {
221 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
222 }
Jooyung Han90eee022019-10-01 20:02:42 +0900223
Jooyung Han394951d2019-10-07 15:34:50 +0900224 vndkVersion := ab.vndkVersion(mctx.DeviceConfig())
225 // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
226 ab.properties.Apex_name = proptools.StringPtr("com.android.vndk.v" + vndkVersion)
Jooyung Han90eee022019-10-01 20:02:42 +0900227
Jooyung Han394951d2019-10-07 15:34:50 +0900228 // vndk_version should be unique
Jooyung Han344d5432019-08-23 11:17:39 +0900229 vndkApexListMutex.Lock()
230 defer vndkApexListMutex.Unlock()
231 vndkApexList := vndkApexList(mctx.Config())
232 if other, ok := vndkApexList[vndkVersion]; ok {
Jooyung Han394951d2019-10-07 15:34:50 +0900233 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other)
Jooyung Han344d5432019-08-23 11:17:39 +0900234 }
Jooyung Han394951d2019-10-07 15:34:50 +0900235 vndkApexList[vndkVersion] = mctx.ModuleName()
Jooyung Han344d5432019-08-23 11:17:39 +0900236 }
237}
238
Jooyung Han394951d2019-10-07 15:34:50 +0900239func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) {
240 if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) {
241 vndkVersion := m.VndkVersion()
Jooyung Han344d5432019-08-23 11:17:39 +0900242 vndkApexList := vndkApexList(mctx.Config())
Jooyung Han394951d2019-10-07 15:34:50 +0900243 if vndkApex, ok := vndkApexList[vndkVersion]; ok {
244 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApex)
Jooyung Han344d5432019-08-23 11:17:39 +0900245 }
246 }
247}
248
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900249// Mark the direct and transitive dependencies of apex bundles so that they
250// can be built for the apex bundles.
251func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800252 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800253 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900254 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900255 depName := mctx.OtherModuleName(child)
256 // If the parent is apexBundle, this child is directly depended.
257 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800258 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800259 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
260 // non-installable apex's cannot be installed and so should not prevent libraries from being
261 // installed to the system.
262 android.UpdateApexDependency(apexBundleName, depName, directDep)
263 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900264
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900265 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900266 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900267 return true
268 } else {
269 return false
270 }
271 })
272 }
273}
274
275// Create apex variations if a module is included in APEX(s).
276func apexMutator(mctx android.BottomUpMutatorContext) {
277 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900278 am.CreateApexVariations(mctx)
Jooyung Han7a78a922019-10-08 21:59:58 +0900279 } else if a, ok := mctx.Module().(*apexBundle); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900280 // apex bundle itself is mutated so that it and its modules have same
281 // apex variant.
282 apexBundleName := mctx.ModuleName()
283 mctx.CreateVariations(apexBundleName)
Jooyung Han7a78a922019-10-08 21:59:58 +0900284
285 // collects APEX list
286 if mctx.Device() && a.installable() {
287 addApexFileContextsInfos(mctx, a)
288 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900289 }
290}
Sundong Ahne9b55722019-09-06 17:37:42 +0900291
Jooyung Han7a78a922019-10-08 21:59:58 +0900292var (
293 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
294 apexFileContextsInfosMutex sync.Mutex
295)
296
297func apexFileContextsInfos(config android.Config) *[]string {
298 return config.Once(apexFileContextsInfosKey, func() interface{} {
299 return &[]string{}
300 }).(*[]string)
301}
302
303func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) {
304 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
305 fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
306
307 apexFileContextsInfosMutex.Lock()
308 defer apexFileContextsInfosMutex.Unlock()
309 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
310 *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName)
311}
312
Sundong Ahne9b55722019-09-06 17:37:42 +0900313func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900314 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900315 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
316 modules := mctx.CreateLocalVariations("", "flattened")
317 modules[0].(*apexBundle).SetFlattened(false)
318 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900319 } else {
320 ab.SetFlattened(true)
321 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900322 }
323 }
324}
325
Jooyung Han5c998b92019-06-27 11:30:33 +0900326func apexUsesMutator(mctx android.BottomUpMutatorContext) {
327 if ab, ok := mctx.Module().(*apexBundle); ok {
328 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
329 }
330}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900331
Alex Light9670d332019-01-29 18:07:33 -0800332type apexNativeDependencies struct {
333 // List of native libraries
334 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900335
Alex Light9670d332019-01-29 18:07:33 -0800336 // List of native executables
337 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900338
Roland Levillain630846d2019-06-26 12:48:34 +0100339 // List of native tests
340 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800341}
Jooyung Han344d5432019-08-23 11:17:39 +0900342
Alex Light9670d332019-01-29 18:07:33 -0800343type apexMultilibProperties struct {
344 // Native dependencies whose compile_multilib is "first"
345 First apexNativeDependencies
346
347 // Native dependencies whose compile_multilib is "both"
348 Both apexNativeDependencies
349
350 // Native dependencies whose compile_multilib is "prefer32"
351 Prefer32 apexNativeDependencies
352
353 // Native dependencies whose compile_multilib is "32"
354 Lib32 apexNativeDependencies
355
356 // Native dependencies whose compile_multilib is "64"
357 Lib64 apexNativeDependencies
358}
359
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900360type apexBundleProperties struct {
361 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000362 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800363 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900364
Jiyong Park40e26a22019-02-08 02:53:06 +0900365 // AndroidManifest.xml file used for the zip container of this APEX bundle.
366 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800367 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900368
Roland Levillain411c5842019-09-19 16:37:20 +0100369 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
370 // device (/apex/<apex_name>).
371 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900372 Apex_name *string
373
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900374 // Determines the file contexts file for setting security context to each file in this APEX bundle.
375 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
376 // used.
377 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900378 File_contexts *string
379
380 // List of native shared libs that are embedded inside this APEX bundle
381 Native_shared_libs []string
382
Roland Levillain630846d2019-06-26 12:48:34 +0100383 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900384 Binaries []string
385
386 // List of java libraries that are embedded inside this APEX bundle
387 Java_libs []string
388
389 // List of prebuilt files that are embedded inside this APEX bundle
390 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900391
Roland Levillain630846d2019-06-26 12:48:34 +0100392 // List of tests that are embedded inside this APEX bundle
393 Tests []string
394
Jiyong Parkff1458f2018-10-12 21:49:38 +0900395 // Name of the apex_key module that provides the private key to sign APEX
396 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900397
Alex Light5098a612018-11-29 17:12:15 -0800398 // The type of APEX to build. Controls what the APEX payload is. Either
399 // 'image', 'zip' or 'both'. Default: 'image'.
400 Payload_type *string
401
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900402 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
403 // or an android_app_certificate module name in the form ":module".
404 Certificate *string
405
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900406 // Whether this APEX is installable to one of the partitions. Default: true.
407 Installable *bool
408
Jiyong Parkda6eb592018-12-19 17:12:36 +0900409 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
410 // Default is false.
411 Use_vendor *bool
412
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800413 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
414 Ignore_system_library_special_case *bool
415
Alex Light9670d332019-01-29 18:07:33 -0800416 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900417
Jiyong Parkf97782b2019-02-13 20:28:58 +0900418 // List of sanitizer names that this APEX is enabled for
419 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900420
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900421 PreventInstall bool `blueprint:"mutated"`
422
423 HideFromMake bool `blueprint:"mutated"`
424
Jooyung Han5c998b92019-06-27 11:30:33 +0900425 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
426 Provide_cpp_shared_libs *bool
427
428 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
429 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100430
431 // A txt file containing list of files that are whitelisted to be included in this APEX.
432 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900433
434 // List of APKs to package inside APEX
435 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900436
Sundong Ahne8fb7242019-09-17 13:50:45 +0900437 // To distinguish between flattened and non-flattened apex.
438 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900439 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900440
Sundong Ahne8fb7242019-09-17 13:50:45 +0900441 // if true, it means that TARGET_FLATTEN_APEX is true and
442 // TARGET_BUILD_APPS is false
443 FlattenedConfigValue bool `blueprint:"mutated"`
444
Jiyong Parkd1063c12019-07-17 20:08:41 +0900445 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
446 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
447 // is implied. This value affects all modules included in this APEX. In other words, they are
448 // also built with the SDKs specified here.
449 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800450}
451
452type apexTargetBundleProperties struct {
453 Target struct {
454 // Multilib properties only for android.
455 Android struct {
456 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900457 }
Jooyung Han344d5432019-08-23 11:17:39 +0900458
Alex Light9670d332019-01-29 18:07:33 -0800459 // Multilib properties only for host.
460 Host struct {
461 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900462 }
Jooyung Han344d5432019-08-23 11:17:39 +0900463
Alex Light9670d332019-01-29 18:07:33 -0800464 // Multilib properties only for host linux_bionic.
465 Linux_bionic struct {
466 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900467 }
Jooyung Han344d5432019-08-23 11:17:39 +0900468
Alex Light9670d332019-01-29 18:07:33 -0800469 // Multilib properties only for host linux_glibc.
470 Linux_glibc struct {
471 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900472 }
473 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900474}
475
Jooyung Han344d5432019-08-23 11:17:39 +0900476type apexVndkProperties struct {
477 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
478 Vndk_version *string
479}
480
Jiyong Park8fd61922018-11-08 02:50:25 +0900481type apexFileClass int
482
483const (
484 etc apexFileClass = iota
485 nativeSharedLib
486 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900487 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800488 pyBinary
489 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900490 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100491 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900492 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900493)
494
Alex Light5098a612018-11-29 17:12:15 -0800495type apexPackaging int
496
497const (
498 imageApex apexPackaging = iota
499 zipApex
500 both
501)
502
503func (a apexPackaging) image() bool {
504 switch a {
505 case imageApex, both:
506 return true
507 }
508 return false
509}
510
511func (a apexPackaging) zip() bool {
512 switch a {
513 case zipApex, both:
514 return true
515 }
516 return false
517}
518
519func (a apexPackaging) suffix() string {
520 switch a {
521 case imageApex:
522 return imageApexSuffix
523 case zipApex:
524 return zipApexSuffix
525 case both:
526 panic(fmt.Errorf("must be either zip or image"))
527 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100528 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800529 }
530}
531
532func (a apexPackaging) name() string {
533 switch a {
534 case imageApex:
535 return imageApexType
536 case zipApex:
537 return zipApexType
538 case both:
539 panic(fmt.Errorf("must be either zip or image"))
540 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100541 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800542 }
543}
544
Jiyong Park8fd61922018-11-08 02:50:25 +0900545func (class apexFileClass) NameInMake() string {
546 switch class {
547 case etc:
548 return "ETC"
549 case nativeSharedLib:
550 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800551 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900552 return "EXECUTABLES"
553 case javaSharedLib:
554 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100555 case nativeTest:
556 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900557 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +0900558 // b/142537672 Why isn't this APP? We want to have full control over
559 // the paths and file names of the apk file under the flattend APEX.
560 // If this is set to APP, then the paths and file names are modified
561 // by the Make build system. For example, it is installed to
562 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
563 // /system/apex/<apexname>/app/<Appname> because the build system automatically
564 // appends module name (which is <apexname>.<Appname> to the path.
565 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +0900566 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100567 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900568 }
569}
570
571type apexFile struct {
572 builtFile android.Path
573 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900574 installDir string
575 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900576 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800577 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900578}
579
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900580type apexBundle struct {
581 android.ModuleBase
582 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900583 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900584
Alex Light9670d332019-01-29 18:07:33 -0800585 properties apexBundleProperties
586 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900587 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900588
Alex Light5098a612018-11-29 17:12:15 -0800589 apexTypes apexPackaging
590
Colin Crossa4925902018-11-16 11:36:28 -0800591 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800592 outputFiles map[apexPackaging]android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700593 flattenedOutput android.InstallPath
594 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900595
Jiyong Park03b68dd2019-07-26 23:20:40 +0900596 prebuiltFileToDelete string
597
Jiyong Park42cca6c2019-04-01 11:15:50 +0900598 public_key_file android.Path
599 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900600
601 container_certificate_file android.Path
602 container_private_key_file android.Path
603
Jiyong Park8fd61922018-11-08 02:50:25 +0900604 // list of files to be included in this apex
605 filesInfo []apexFile
606
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900607 // list of module names that this APEX is depending on
608 externalDeps []string
609
Alex Light0851b882019-02-07 13:20:53 -0800610 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900611 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900612
613 // intermediate path for apex_manifest.json
614 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900615}
616
Jiyong Park397e55e2018-10-24 21:09:55 +0900617func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100618 native_shared_libs []string, binaries []string, tests []string,
619 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900620 // Use *FarVariation* to be able to depend on modules having
621 // conflicting variations with this module. This is required since
622 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
623 // for native shared libs.
624 ctx.AddFarVariationDependencies([]blueprint.Variation{
625 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900626 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900627 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900628 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900629 }, sharedLibTag, native_shared_libs...)
630
631 ctx.AddFarVariationDependencies([]blueprint.Variation{
632 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900633 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900634 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100635
636 ctx.AddFarVariationDependencies([]blueprint.Variation{
637 {Mutator: "arch", Variation: arch},
638 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100639 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100640 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900641}
642
Alex Light9670d332019-01-29 18:07:33 -0800643func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
644 if ctx.Os().Class == android.Device {
645 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
646 } else {
647 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
648 if ctx.Os().Bionic() {
649 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
650 } else {
651 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
652 }
653 }
654}
655
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900656func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900657 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900658 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800659
660 a.combineProperties(ctx)
661
Jiyong Park397e55e2018-10-24 21:09:55 +0900662 has32BitTarget := false
663 for _, target := range targets {
664 if target.Arch.ArchType.Multilib == "lib32" {
665 has32BitTarget = true
666 }
667 }
668 for i, target := range targets {
669 // When multilib.* is omitted for native_shared_libs, it implies
670 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900671 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900672 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900673 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900674 {Mutator: "link", Variation: "shared"},
675 }, sharedLibTag, a.properties.Native_shared_libs...)
676
Roland Levillain630846d2019-06-26 12:48:34 +0100677 // When multilib.* is omitted for tests, it implies
678 // multilib.both.
679 ctx.AddFarVariationDependencies([]blueprint.Variation{
680 {Mutator: "arch", Variation: target.String()},
681 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100682 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100683 }, testTag, a.properties.Tests...)
684
Jiyong Park397e55e2018-10-24 21:09:55 +0900685 // Add native modules targetting both ABIs
686 addDependenciesForNativeModules(ctx,
687 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100688 a.properties.Multilib.Both.Binaries,
689 a.properties.Multilib.Both.Tests,
690 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900691 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900692
Alex Light3d673592019-01-18 14:37:31 -0800693 isPrimaryAbi := i == 0
694 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900695 // When multilib.* is omitted for binaries, it implies
696 // multilib.first.
697 ctx.AddFarVariationDependencies([]blueprint.Variation{
698 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900699 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900700 }, executableTag, a.properties.Binaries...)
701
702 // Add native modules targetting the first ABI
703 addDependenciesForNativeModules(ctx,
704 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100705 a.properties.Multilib.First.Binaries,
706 a.properties.Multilib.First.Tests,
707 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900708 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800709
710 // When multilib.* is omitted for prebuilts, it implies multilib.first.
711 ctx.AddFarVariationDependencies([]blueprint.Variation{
712 {Mutator: "arch", Variation: target.String()},
713 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900714 }
715
716 switch target.Arch.ArchType.Multilib {
717 case "lib32":
718 // Add native modules targetting 32-bit ABI
719 addDependenciesForNativeModules(ctx,
720 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100721 a.properties.Multilib.Lib32.Binaries,
722 a.properties.Multilib.Lib32.Tests,
723 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900724 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900725
726 addDependenciesForNativeModules(ctx,
727 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100728 a.properties.Multilib.Prefer32.Binaries,
729 a.properties.Multilib.Prefer32.Tests,
730 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900731 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900732 case "lib64":
733 // Add native modules targetting 64-bit ABI
734 addDependenciesForNativeModules(ctx,
735 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100736 a.properties.Multilib.Lib64.Binaries,
737 a.properties.Multilib.Lib64.Tests,
738 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900739 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900740
741 if !has32BitTarget {
742 addDependenciesForNativeModules(ctx,
743 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100744 a.properties.Multilib.Prefer32.Binaries,
745 a.properties.Multilib.Prefer32.Tests,
746 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900747 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900748 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700749
750 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
751 for _, sanitizer := range ctx.Config().SanitizeDevice() {
752 if sanitizer == "hwaddress" {
753 addDependenciesForNativeModules(ctx,
754 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100755 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700756 break
757 }
758 }
759 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900760 }
761
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900762 }
763
Jiyong Parkff1458f2018-10-12 21:49:38 +0900764 ctx.AddFarVariationDependencies([]blueprint.Variation{
765 {Mutator: "arch", Variation: "android_common"},
766 }, javaLibTag, a.properties.Java_libs...)
767
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900768 ctx.AddFarVariationDependencies([]blueprint.Variation{
769 {Mutator: "arch", Variation: "android_common"},
770 }, androidAppTag, a.properties.Apps...)
771
Jiyong Park23c52b02019-02-02 13:13:47 +0900772 if String(a.properties.Key) == "" {
773 ctx.ModuleErrorf("key is missing")
774 return
775 }
776 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900777
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900778 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900779 if cert != "" {
780 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900781 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900782
783 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
784 if len(a.properties.Uses_sdks) > 0 {
785 sdkRefs := []android.SdkRef{}
786 for _, str := range a.properties.Uses_sdks {
787 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
788 sdkRefs = append(sdkRefs, parsed)
789 }
790 a.BuildWithSdks(sdkRefs)
791 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900792}
793
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900794func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
795 // direct deps of an APEX bundle are all part of the APEX bundle
796 return true
797}
798
Colin Cross0ea8ba82019-06-06 14:33:29 -0700799func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900800 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
801 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000802 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900803 }
804 return String(a.properties.Certificate)
805}
806
Colin Cross41955e82019-05-29 14:40:35 -0700807func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
808 switch tag {
809 case "":
810 if file, ok := a.outputFiles[imageApex]; ok {
811 return android.Paths{file}, nil
812 } else {
813 return nil, nil
814 }
Roland Levillain935639d2019-08-13 14:55:28 +0100815 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900816 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100817 flattenedApexPath := a.flattenedOutput
818 return android.Paths{flattenedApexPath}, nil
819 } else {
820 return nil, nil
821 }
Colin Cross41955e82019-05-29 14:40:35 -0700822 default:
823 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900824 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900825}
826
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900827func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900828 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900829}
830
Jiyong Park7c1dc612019-01-05 11:15:24 +0900831func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han394951d2019-10-07 15:34:50 +0900832 if a.vndkApex {
833 return "vendor." + a.vndkVersion(config)
834 }
Jiyong Park7c1dc612019-01-05 11:15:24 +0900835 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900836 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900837 } else {
838 return "core"
839 }
840}
841
Jiyong Parkf97782b2019-02-13 20:28:58 +0900842func (a *apexBundle) EnableSanitizer(sanitizerName string) {
843 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
844 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
845 }
846}
847
Jiyong Park388ef3f2019-01-28 19:47:32 +0900848func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900849 if android.InList(sanitizerName, a.properties.SanitizerNames) {
850 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900851 }
852
853 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900854 globalSanitizerNames := []string{}
855 if a.Host() {
856 globalSanitizerNames = ctx.Config().SanitizeHost()
857 } else {
858 arches := ctx.Config().SanitizeDeviceArch()
859 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
860 globalSanitizerNames = ctx.Config().SanitizeDevice()
861 }
862 }
863 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900864}
865
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900866func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
867 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
868}
869
870func (a *apexBundle) PreventInstall() {
871 a.properties.PreventInstall = true
872}
873
874func (a *apexBundle) HideFromMake() {
875 a.properties.HideFromMake = true
876}
877
Sundong Ahne9b55722019-09-06 17:37:42 +0900878func (a *apexBundle) SetFlattened(flattened bool) {
879 a.properties.Flattened = flattened
880}
881
Sundong Ahne8fb7242019-09-17 13:50:45 +0900882func (a *apexBundle) SetFlattenedConfigValue() {
883 a.properties.FlattenedConfigValue = true
884}
885
886// isFlattenedVariant returns true when the current module is the flattened
887// variant of an apex that has both a flattened and an unflattened variant.
888// It returns false when the current module is flattened but there is no
889// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
890// true. It can be used to avoid collisions between the install paths of the
891// flattened and unflattened variants.
892func (a *apexBundle) isFlattenedVariant() bool {
893 return a.properties.Flattened && !a.properties.FlattenedConfigValue
894}
895
Martin Stjernholm279de572019-09-10 23:18:20 +0100896func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900897 // Decide the APEX-local directory by the multilib of the library
898 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100899 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900900 case "lib32":
901 dirInApex = "lib"
902 case "lib64":
903 dirInApex = "lib64"
904 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100905 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700906 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100907 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900908 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100909 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
910 // Special case for Bionic libs and other libs installed with them. This is
911 // to prevent those libs from being included in the search path
912 // /apex/com.android.runtime/${LIB}. This exclusion is required because
913 // those libs in the Runtime APEX are available via the legacy paths in
914 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
915 // to the legacy paths and thus will be loaded into the default linker
916 // namespace (aka "platform" namespace). If the libs are directly in
917 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
918 // into the runtime linker namespace, which will result in double loading of
919 // them, which isn't supported.
920 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900921 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900922
Martin Stjernholm279de572019-09-10 23:18:20 +0100923 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900924 return
925}
926
927func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900928 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700929 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200930 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900931 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900932 fileToCopy = cc.OutputFile().Path()
933 return
934}
935
Alex Light778127a2019-02-27 14:19:50 -0800936func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
937 dirInApex = "bin"
938 fileToCopy = py.HostToolPath().Path()
939 return
940}
941func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
942 dirInApex = "bin"
943 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
944 if err != nil {
945 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
946 return
947 }
948 fileToCopy = android.PathForOutput(ctx, s)
949 return
950}
951
Jiyong Park04480cf2019-02-06 00:16:29 +0900952func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
953 dirInApex = filepath.Join("bin", sh.SubDir())
954 fileToCopy = sh.OutputFile()
955 return
956}
957
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900958func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
959 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900960 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961 return
962}
963
Jiyong Park9e6c2422019-08-09 20:39:45 +0900964func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
965 dirInApex = "javalib"
966 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
967 implJars := java.ImplementationJars()
968 if len(implJars) != 1 {
969 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
970 strings.Join(implJars.Strings(), ", ")))
971 }
972 fileToCopy = implJars[0]
973 return
974}
975
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900976func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
977 dirInApex = filepath.Join("etc", prebuilt.SubDir())
978 fileToCopy = prebuilt.OutputFile()
979 return
980}
981
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900982func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
983 dirInApex = filepath.Join("app", pkgName)
984 fileToCopy = app.OutputFile()
985 return
986}
987
Roland Levillain935639d2019-08-13 14:55:28 +0100988// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
989type flattenedApexContext struct {
990 android.ModuleContext
991}
992
993func (c *flattenedApexContext) InstallBypassMake() bool {
994 return true
995}
996
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900997func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900998 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900999
Alex Light5098a612018-11-29 17:12:15 -08001000 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
1001 a.apexTypes = imageApex
1002 } else if *a.properties.Payload_type == "zip" {
1003 a.apexTypes = zipApex
1004 } else if *a.properties.Payload_type == "both" {
1005 a.apexTypes = both
1006 } else {
1007 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
1008 return
1009 }
1010
Roland Levillain630846d2019-06-26 12:48:34 +01001011 if len(a.properties.Tests) > 0 && !a.testApex {
1012 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1013 return
1014 }
1015
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001016 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1017
Jooyung Hane1633032019-08-01 17:41:43 +09001018 // native lib dependencies
1019 var provideNativeLibs []string
1020 var requireNativeLibs []string
1021
Jooyung Han5c998b92019-06-27 11:30:33 +09001022 // Check if "uses" requirements are met with dependent apexBundles
1023 var providedNativeSharedLibs []string
1024 useVendor := proptools.Bool(a.properties.Use_vendor)
1025 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1026 if ctx.OtherModuleDependencyTag(m) != usesTag {
1027 return
1028 }
1029 otherName := ctx.OtherModuleName(m)
1030 other, ok := m.(*apexBundle)
1031 if !ok {
1032 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1033 return
1034 }
1035 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1036 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1037 return
1038 }
1039 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1040 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1041 return
1042 }
1043 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1044 })
1045
Alex Light778127a2019-02-27 14:19:50 -08001046 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001047 depTag := ctx.OtherModuleDependencyTag(child)
1048 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049 if _, ok := parent.(*apexBundle); ok {
1050 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001051 switch depTag {
1052 case sharedLibTag:
1053 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001054 if cc.HasStubsVariants() {
1055 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1056 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001057 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001058 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001059 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001060 } else {
1061 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001062 }
1063 case executableTag:
1064 if cc, ok := child.(*cc.Module); ok {
1065 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001066 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001067 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001068 } else if sh, ok := child.(*android.ShBinary); ok {
1069 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -07001070 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
Alex Light778127a2019-02-27 14:19:50 -08001071 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1072 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1073 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1074 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1075 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1076 // NB: Since go binaries are static we don't need the module for anything here, which is
1077 // good since the go tool is a blueprint.Module not an android.Module like we would
1078 // normally use.
1079 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001080 } else {
Alex Light778127a2019-02-27 14:19:50 -08001081 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 +09001082 }
1083 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001084 if javaLib, ok := child.(*java.Library); ok {
1085 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001086 if fileToCopy == nil {
1087 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1088 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001089 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1090 }
1091 return true
1092 } else if javaLib, ok := child.(*java.Import); ok {
1093 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1094 if fileToCopy == nil {
1095 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1096 } else {
1097 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001098 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001099 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001100 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001101 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001102 }
1103 case prebuiltTag:
1104 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1105 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001106 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001107 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001108 } else {
1109 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1110 }
Roland Levillain630846d2019-06-26 12:48:34 +01001111 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001112 if ccTest, ok := child.(*cc.Module); ok {
1113 if ccTest.IsTestPerSrcAllTestsVariation() {
1114 // Multiple-output test module (where `test_per_src: true`).
1115 //
1116 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1117 // We do not add this variation to `filesInfo`, as it has no output;
1118 // however, we do add the other variations of this module as indirect
1119 // dependencies (see below).
1120 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001121 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001122 // Single-output test module (where `test_per_src: false`).
1123 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1124 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001125 }
Roland Levillain630846d2019-06-26 12:48:34 +01001126 return true
1127 } else {
1128 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1129 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001130 case keyTag:
1131 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001132 a.private_key_file = key.private_key_file
1133 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001134 return false
1135 } else {
1136 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001137 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001138 case certificateTag:
1139 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001140 a.container_certificate_file = dep.Certificate.Pem
1141 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001142 return false
1143 } else {
1144 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1145 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001146 case android.PrebuiltDepTag:
1147 // If the prebuilt is force disabled, remember to delete the prebuilt file
1148 // that might have been installed in the previous builds
1149 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1150 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1151 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001152 case androidAppTag:
1153 if ap, ok := child.(*java.AndroidApp); ok {
1154 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1155 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1156 return true
1157 } else {
1158 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1159 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001160 }
1161 } else {
1162 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001163 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001164 // We cannot use a switch statement on `depTag` here as the checked
1165 // tags used below are private (e.g. `cc.sharedDepTag`).
1166 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1167 if cc, ok := child.(*cc.Module); ok {
1168 if android.InList(cc.Name(), providedNativeSharedLibs) {
1169 // If we're using a shared library which is provided from other APEX,
1170 // don't include it in this APEX
1171 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001172 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001173 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1174 // If the dependency is a stubs lib, don't include it in this APEX,
1175 // but make sure that the lib is installed on the device.
1176 // In case no APEX is having the lib, the lib is installed to the system
1177 // partition.
1178 //
1179 // Always include if we are a host-apex however since those won't have any
1180 // system libraries.
1181 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1182 a.externalDeps = append(a.externalDeps, cc.Name())
1183 }
Jooyung Hane1633032019-08-01 17:41:43 +09001184 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001185 // Don't track further
1186 return false
1187 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001188 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001189 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1190 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001191 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001192 } else if cc.IsTestPerSrcDepTag(depTag) {
1193 if cc, ok := child.(*cc.Module); ok {
1194 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1195 // Handle modules created as `test_per_src` variations of a single test module:
1196 // use the name of the generated test binary (`fileToCopy`) instead of the name
1197 // of the original test module (`depName`, shared by all `test_per_src`
1198 // variations of that module).
1199 moduleName := filepath.Base(fileToCopy.String())
1200 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1201 return true
1202 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001203 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001204 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001205 }
1206 }
1207 }
1208 return false
1209 })
1210
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001211 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001212 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1213 return
1214 }
1215
Jiyong Park8fd61922018-11-08 02:50:25 +09001216 // remove duplicates in filesInfo
1217 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001218 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001219 result := []apexFile{}
1220 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001221 dest := filepath.Join(f.installDir, f.builtFile.Base())
1222 if !encountered[dest] {
1223 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001224 result = append(result, f)
1225 }
1226 }
1227 return result
1228 }
1229 filesInfo = removeDup(filesInfo)
1230
1231 // to have consistent build rules
1232 sort.Slice(filesInfo, func(i, j int) bool {
1233 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1234 })
1235
Jiyong Park127b40b2019-09-30 16:04:35 +09001236 // check apex_available requirements
Jiyong Park583a2262019-10-08 20:55:38 +09001237 if !ctx.Host() {
1238 for _, fi := range filesInfo {
1239 if am, ok := fi.module.(android.ApexModule); ok {
1240 if !am.AvailableFor(ctx.ModuleName()) {
1241 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
1242 return
1243 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001244 }
1245 }
1246 }
1247
Jiyong Park8fd61922018-11-08 02:50:25 +09001248 // prepend the name of this APEX to the module names. These names will be the names of
1249 // modules that will be defined if the APEX is flattened.
1250 for i := range filesInfo {
Jooyung Han394951d2019-10-07 15:34:50 +09001251 filesInfo[i].moduleName = filesInfo[i].moduleName + "." + ctx.ModuleName()
Jiyong Park8fd61922018-11-08 02:50:25 +09001252 }
1253
Jiyong Park8fd61922018-11-08 02:50:25 +09001254 a.installDir = android.PathForModuleInstall(ctx, "apex")
1255 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001256
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001257 // prepare apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001258 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
Jooyung Hane1633032019-08-01 17:41:43 +09001259 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001260
1261 // put dependency({provide|require}NativeLibs) in apex_manifest.json
Jooyung Hane1633032019-08-01 17:41:43 +09001262 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1263 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001264
1265 // apex name can be overridden
1266 optCommands := []string{}
1267 if a.properties.Apex_name != nil {
1268 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
1269 }
1270
Jooyung Hane1633032019-08-01 17:41:43 +09001271 ctx.Build(pctx, android.BuildParams{
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001272 Rule: apexManifestRule,
Jooyung Hane1633032019-08-01 17:41:43 +09001273 Input: manifestSrc,
1274 Output: a.manifestOut,
1275 Args: map[string]string{
1276 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1277 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001278 "opt": strings.Join(optCommands, " "),
Jooyung Hane1633032019-08-01 17:41:43 +09001279 },
1280 })
1281
Roland Levillain935639d2019-08-13 14:55:28 +01001282 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1283 // reply true to `InstallBypassMake()` (thus making the call
1284 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1285 // instead of `android.PathForOutput`) to return the correct path to the flattened
1286 // APEX (as its contents is installed by Make, not Soong).
1287 factx := flattenedApexContext{ctx}
Jooyung Han7a78a922019-10-08 21:59:58 +09001288 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
1289 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", apexName)
Roland Levillain935639d2019-08-13 14:55:28 +01001290
Alex Light5098a612018-11-29 17:12:15 -08001291 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001292 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001293 }
1294 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001295 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001296 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001297 // in other modules. It is in AndroidMk where the selection of flattened
1298 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001299 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001300 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001301 }
1302}
1303
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001304func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001305 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001306 for _, f := range a.filesInfo {
1307 if f.module != nil {
1308 notice := f.module.NoticeFile()
1309 if notice.Valid() {
1310 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001311 }
1312 }
1313 }
1314 // append the notice file specified in the apex module itself
1315 if a.NoticeFile().Valid() {
1316 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001317 }
1318
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001319 if len(noticeFiles) == 0 {
1320 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001321 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001322
Jaewoong Jung98772792019-07-01 17:15:13 -07001323 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001324}
1325
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001326func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001327 cert := String(a.properties.Certificate)
1328 if cert != "" && android.SrcIsModule(cert) == "" {
1329 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001330 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1331 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001332 } else if cert == "" {
1333 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001334 a.container_certificate_file = pem
1335 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001336 }
1337
Alex Light5098a612018-11-29 17:12:15 -08001338 var abis []string
1339 for _, target := range ctx.MultiTargets() {
1340 if len(target.Arch.Abi) > 0 {
1341 abis = append(abis, target.Arch.Abi[0])
1342 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001343 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001344
Alex Light5098a612018-11-29 17:12:15 -08001345 abis = android.FirstUniqueStrings(abis)
1346
1347 suffix := apexType.suffix()
1348 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001349
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001350 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001351 for _, f := range a.filesInfo {
1352 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001353 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001354
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001355 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001356 emitCommands := []string{}
1357 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1358 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001359 for i, src := range filesToCopy {
1360 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001361 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001362 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001363 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1364 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001365 for _, sym := range a.filesInfo[i].symlinks {
1366 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1367 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1368 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001369 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001370 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001371 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001372
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001373 if a.properties.Whitelisted_files != nil {
1374 ctx.Build(pctx, android.BuildParams{
1375 Rule: emitApexContentRule,
1376 Implicits: implicitInputs,
1377 Output: imageContentFile,
1378 Description: "emit apex image content",
1379 Args: map[string]string{
1380 "emit_commands": strings.Join(emitCommands, " && "),
1381 },
1382 })
1383 implicitInputs = append(implicitInputs, imageContentFile)
1384 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1385
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001386 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001387 ctx.Build(pctx, android.BuildParams{
1388 Rule: diffApexContentRule,
1389 Implicits: implicitInputs,
1390 Output: phonyOutput,
1391 Description: "diff apex image content",
1392 Args: map[string]string{
1393 "whitelisted_files_file": whitelistedFilesFile.String(),
1394 "image_content_file": imageContentFile.String(),
1395 "apex_module_name": ctx.ModuleName(),
1396 },
1397 })
1398
1399 implicitInputs = append(implicitInputs, phonyOutput)
1400 }
1401
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001402 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1403 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001404
Alex Light5098a612018-11-29 17:12:15 -08001405 if apexType.image() {
1406 // files and dirs that will be created in APEX
1407 var readOnlyPaths []string
1408 var executablePaths []string // this also includes dirs
1409 for _, f := range a.filesInfo {
1410 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001411 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001412 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001413 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001414 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001415 }
Alex Light5098a612018-11-29 17:12:15 -08001416 } else {
1417 readOnlyPaths = append(readOnlyPaths, pathInApex)
1418 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001419 dir := f.installDir
1420 for !android.InList(dir, executablePaths) && dir != "" {
1421 executablePaths = append(executablePaths, dir)
1422 dir, _ = filepath.Split(dir) // move up to the parent
1423 if len(dir) > 0 {
1424 // remove trailing slash
1425 dir = dir[:len(dir)-1]
1426 }
Alex Light5098a612018-11-29 17:12:15 -08001427 }
1428 }
1429 sort.Strings(readOnlyPaths)
1430 sort.Strings(executablePaths)
1431 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1432 ctx.Build(pctx, android.BuildParams{
1433 Rule: generateFsConfig,
1434 Output: cannedFsConfig,
1435 Description: "generate fs config",
1436 Args: map[string]string{
1437 "ro_paths": strings.Join(readOnlyPaths, " "),
1438 "exec_paths": strings.Join(executablePaths, " "),
1439 },
1440 })
1441
1442 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1443 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1444 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1445 if !fileContextsOptionalPath.Valid() {
1446 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1447 return
1448 }
1449 fileContexts := fileContextsOptionalPath.Path()
1450
Jiyong Park835d82b2018-12-27 16:04:18 +09001451 optFlags := []string{}
1452
Alex Light5098a612018-11-29 17:12:15 -08001453 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001454 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1455 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001456
Jiyong Park7f67f482019-01-05 12:57:48 +09001457 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1458 if overridden {
1459 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1460 }
1461
Jiyong Park40e26a22019-02-08 02:53:06 +09001462 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001463 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001464 implicitInputs = append(implicitInputs, androidManifestFile)
1465 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1466 }
1467
Jiyong Park71b519d2019-04-18 17:25:49 +09001468 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1469 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1470 ctx.Config().UnbundledBuild() &&
1471 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1472 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1473 apiFingerprint := java.ApiFingerprintPath(ctx)
1474 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1475 implicitInputs = append(implicitInputs, apiFingerprint)
1476 }
1477 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1478
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001479 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1480 if noticeFile.Valid() {
1481 // If there's a NOTICE file, embed it as an asset file in the APEX.
1482 implicitInputs = append(implicitInputs, noticeFile.Path())
1483 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1484 }
1485
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001486 if !ctx.Config().UnbundledBuild() && a.installable() {
1487 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1488 // don't need hashtree for activation. Therefore, by removing hashtree from
1489 // apex bundle (filesystem image in it, to be specific), we can save storage.
1490 optFlags = append(optFlags, "--no_hashtree")
1491 }
1492
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001493 if a.properties.Apex_name != nil {
1494 // If apex_name is set, apexer can skip checking if key name matches with apex name.
1495 // Note that apex_manifest is also mended.
1496 optFlags = append(optFlags, "--do_not_check_keyname")
1497 }
1498
Alex Light5098a612018-11-29 17:12:15 -08001499 ctx.Build(pctx, android.BuildParams{
1500 Rule: apexRule,
1501 Implicits: implicitInputs,
1502 Output: unsignedOutputFile,
1503 Description: "apex (" + apexType.name() + ")",
1504 Args: map[string]string{
1505 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1506 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1507 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001508 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001509 "file_contexts": fileContexts.String(),
1510 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001511 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001512 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001513 },
1514 })
1515
1516 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1517 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1518 a.bundleModuleFile = bundleModuleFile
1519
1520 ctx.Build(pctx, android.BuildParams{
1521 Rule: apexProtoConvertRule,
1522 Input: unsignedOutputFile,
1523 Output: apexProtoFile,
1524 Description: "apex proto convert",
1525 })
1526
1527 ctx.Build(pctx, android.BuildParams{
1528 Rule: apexBundleRule,
1529 Input: apexProtoFile,
1530 Output: a.bundleModuleFile,
1531 Description: "apex bundle module",
1532 Args: map[string]string{
1533 "abi": strings.Join(abis, "."),
1534 },
1535 })
1536 } else {
1537 ctx.Build(pctx, android.BuildParams{
1538 Rule: zipApexRule,
1539 Implicits: implicitInputs,
1540 Output: unsignedOutputFile,
1541 Description: "apex (" + apexType.name() + ")",
1542 Args: map[string]string{
1543 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1544 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1545 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001546 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001547 },
1548 })
Colin Crossa4925902018-11-16 11:36:28 -08001549 }
Colin Crossa4925902018-11-16 11:36:28 -08001550
Alex Light5098a612018-11-29 17:12:15 -08001551 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001552 ctx.Build(pctx, android.BuildParams{
1553 Rule: java.Signapk,
1554 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001555 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001556 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001557 Implicits: []android.Path{
1558 a.container_certificate_file,
1559 a.container_private_key_file,
1560 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001561 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001562 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001563 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001564 },
1565 })
Alex Light5098a612018-11-29 17:12:15 -08001566
1567 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001568 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001569 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001570 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001571}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001572
Jiyong Park8fd61922018-11-08 02:50:25 +09001573func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001574 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001575 // 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 +09001576 // with other ordinary files.
Jooyung Han394951d2019-10-07 15:34:50 +09001577 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, "apex_manifest.json." + ctx.ModuleName(), ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001578
Jiyong Park42cca6c2019-04-01 11:15:50 +09001579 // rename to apex_pubkey
1580 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1581 ctx.Build(pctx, android.BuildParams{
1582 Rule: android.Cp,
1583 Input: a.public_key_file,
1584 Output: copiedPubkey,
1585 })
Jooyung Han394951d2019-10-07 15:34:50 +09001586 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, "apex_pubkey." + ctx.ModuleName(), ".", etc, nil, nil})
Jiyong Park42cca6c2019-04-01 11:15:50 +09001587
Jiyong Park23c52b02019-02-02 13:13:47 +09001588 if ctx.Config().FlattenApex() {
Jooyung Han7a78a922019-10-08 21:59:58 +09001589 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
Jiyong Park23c52b02019-02-02 13:13:47 +09001590 for _, fi := range a.filesInfo {
Jooyung Han7a78a922019-10-08 21:59:58 +09001591 dir := filepath.Join("apex", apexName, fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001592 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1593 for _, sym := range fi.symlinks {
1594 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1595 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001596 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001597 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001598 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001599}
1600
1601func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001602 if a.properties.HideFromMake {
1603 return android.AndroidMkData{
1604 Disabled: true,
1605 }
1606 }
Alex Light5098a612018-11-29 17:12:15 -08001607 writers := []android.AndroidMkData{}
1608 if a.apexTypes.image() {
1609 writers = append(writers, a.androidMkForType(imageApex))
1610 }
1611 if a.apexTypes.zip() {
1612 writers = append(writers, a.androidMkForType(zipApex))
1613 }
1614 return android.AndroidMkData{
1615 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1616 for _, data := range writers {
1617 data.Custom(w, name, prefix, moduleDir, data)
1618 }
1619 }}
1620}
1621
Jooyung Han7a78a922019-10-08 21:59:58 +09001622func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001623 moduleNames := []string{}
1624
1625 for _, fi := range a.filesInfo {
1626 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1627 continue
1628 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001629 if a.properties.Flattened && !apexType.image() {
1630 continue
Jiyong Park94427262019-02-05 23:18:47 +09001631 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001632
1633 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001634 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001635 suffix = ".flattened"
1636 }
1637
1638 if !android.InList(fi.moduleName, moduleNames) {
1639 moduleNames = append(moduleNames, fi.moduleName+suffix)
1640 }
1641
Jiyong Park94427262019-02-05 23:18:47 +09001642 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1643 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001644 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001645 // /apex/<apex_name>/{lib|framework|...}
Jooyung Han7a78a922019-10-08 21:59:58 +09001646 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001647 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001648 // /system/apex/<name>/{lib|framework|...}
Colin Crossff6c33d2019-10-02 16:01:35 -07001649 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
Jooyung Han7a78a922019-10-08 21:59:58 +09001650 apexName, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001651 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001652 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1653 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001654 if len(fi.symlinks) > 0 {
1655 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1656 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001657
1658 if fi.module != nil && fi.module.NoticeFile().Valid() {
1659 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1660 }
Jiyong Park94427262019-02-05 23:18:47 +09001661 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001662 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001663 }
1664 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1665 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1666 if fi.module != nil {
1667 archStr := fi.module.Target().Arch.ArchType.String()
1668 host := false
1669 switch fi.module.Target().Os.Class {
1670 case android.Host:
1671 if archStr != "common" {
1672 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1673 }
1674 host = true
1675 case android.HostCross:
1676 if archStr != "common" {
1677 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1678 }
1679 host = true
1680 case android.Device:
1681 if archStr != "common" {
1682 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1683 }
1684 }
1685 if host {
1686 makeOs := fi.module.Target().Os.String()
1687 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1688 makeOs = "linux"
1689 }
1690 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1691 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1692 }
1693 }
1694 if fi.class == javaSharedLib {
1695 javaModule := fi.module.(*java.Library)
1696 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1697 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1698 // we will have foo.jar.jar
1699 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1700 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1701 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1702 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1703 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1704 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001705 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001706 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001707 if cc, ok := fi.module.(*cc.Module); ok {
1708 if cc.UnstrippedOutputFile() != nil {
1709 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1710 }
1711 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001712 if cc.CoverageOutputFile().Valid() {
1713 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1714 }
Jiyong Park94427262019-02-05 23:18:47 +09001715 }
1716 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1717 } else {
1718 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1719 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1720 }
1721 }
1722 return moduleNames
1723}
1724
Alex Light5098a612018-11-29 17:12:15 -08001725func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001726 return android.AndroidMkData{
1727 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1728 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001729 if a.installable() {
Jooyung Han7a78a922019-10-08 21:59:58 +09001730 apexName := proptools.StringDefault(a.properties.Apex_name, name)
1731 moduleNames = a.androidMkForFiles(w, apexName, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001732 }
1733
Sundong Ahne8fb7242019-09-17 13:50:45 +09001734 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001735 name = name + ".flattened"
1736 }
1737
1738 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001739 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001740 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1741 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1742 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001743 if len(moduleNames) > 0 {
1744 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1745 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001746 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001747 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1748
Sundong Ahne8fb7242019-09-17 13:50:45 +09001749 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001750 // zip-apex is the less common type so have the name refer to the image-apex
1751 // only and use {name}.zip if you want the zip-apex
1752 if apexType == zipApex && a.apexTypes == both {
1753 name = name + ".zip"
1754 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001755 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1756 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1757 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1758 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001759 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Colin Crossff6c33d2019-10-02 16:01:35 -07001760 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
Colin Cross189ff982019-01-02 22:32:27 -08001761 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001762 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001763 if len(moduleNames) > 0 {
1764 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1765 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001766 if len(a.externalDeps) > 0 {
1767 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1768 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001769 if a.prebuiltFileToDelete != "" {
1770 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
Colin Crossff6c33d2019-10-02 16:01:35 -07001771 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
Jiyong Park03b68dd2019-07-26 23:20:40 +09001772 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001773 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001774
Alex Light5098a612018-11-29 17:12:15 -08001775 if apexType == imageApex {
1776 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1777 }
Jiyong Park719b4462019-01-13 00:39:51 +09001778 }
1779 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001780}
1781
Jooyung Han344d5432019-08-23 11:17:39 +09001782func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001783 module := &apexBundle{
1784 outputFiles: map[apexPackaging]android.WritablePath{},
1785 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001786 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001787 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001788 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001789 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1790 })
Alex Light5098a612018-11-29 17:12:15 -08001791 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001792 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001793 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001794 return module
1795}
Jiyong Park30ca9372019-02-07 16:27:23 +09001796
Jooyung Han344d5432019-08-23 11:17:39 +09001797func ApexBundleFactory(testApex bool) android.Module {
1798 bundle := newApexBundle()
1799 bundle.testApex = testApex
1800 return bundle
1801}
1802
1803func testApexBundleFactory() android.Module {
1804 bundle := newApexBundle()
1805 bundle.testApex = true
1806 return bundle
1807}
1808
Jiyong Parkd1063c12019-07-17 20:08:41 +09001809func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001810 return newApexBundle()
1811}
1812
1813// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1814// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1815// If not specified, then the "current" versions are gathered.
1816func vndkApexBundleFactory() android.Module {
1817 bundle := newApexBundle()
1818 bundle.vndkApex = true
1819 bundle.AddProperties(&bundle.vndkProperties)
1820 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1821 ctx.AppendProperties(&struct {
1822 Compile_multilib *string
1823 }{
1824 proptools.StringPtr("both"),
1825 })
1826 })
1827 return bundle
1828}
1829
Jooyung Han394951d2019-10-07 15:34:50 +09001830func (a *apexBundle) vndkVersion(config android.DeviceConfig) string {
1831 vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current")
1832 if vndkVersion == "current" {
1833 vndkVersion = config.PlatformVndkVersion()
1834 }
1835 return vndkVersion
1836}
1837
Jiyong Park30ca9372019-02-07 16:27:23 +09001838//
1839// Defaults
1840//
1841type Defaults struct {
1842 android.ModuleBase
1843 android.DefaultsModuleBase
1844}
1845
Jiyong Park30ca9372019-02-07 16:27:23 +09001846func defaultsFactory() android.Module {
1847 return DefaultsFactory()
1848}
1849
1850func DefaultsFactory(props ...interface{}) android.Module {
1851 module := &Defaults{}
1852
1853 module.AddProperties(props...)
1854 module.AddProperties(
1855 &apexBundleProperties{},
1856 &apexTargetBundleProperties{},
1857 )
1858
1859 android.InitDefaultsModule(module)
1860 return module
1861}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001862
1863//
1864// Prebuilt APEX
1865//
1866type Prebuilt struct {
1867 android.ModuleBase
1868 prebuilt android.Prebuilt
1869
1870 properties PrebuiltProperties
1871
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001872 inputApex android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001873 installDir android.InstallPath
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001874 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001875 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001876}
1877
1878type PrebuiltProperties struct {
1879 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001880 Source string `blueprint:"mutated"`
1881 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001882
1883 Src *string
1884 Arch struct {
1885 Arm struct {
1886 Src *string
1887 }
1888 Arm64 struct {
1889 Src *string
1890 }
1891 X86 struct {
1892 Src *string
1893 }
1894 X86_64 struct {
1895 Src *string
1896 }
1897 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001898
1899 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001900 // Optional name for the installed apex. If unspecified, name of the
1901 // module is used as the file name
1902 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001903
1904 // Names of modules to be overridden. Listed modules can only be other binaries
1905 // (in Make or Soong).
1906 // This does not completely prevent installation of the overridden binaries, but if both
1907 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1908 // from PRODUCT_PACKAGES.
1909 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001910}
1911
1912func (p *Prebuilt) installable() bool {
1913 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001914}
1915
1916func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001917 // If the device is configured to use flattened APEX, force disable the prebuilt because
1918 // the prebuilt is a non-flattened one.
1919 forceDisable := ctx.Config().FlattenApex()
1920
1921 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1922 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001923 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001924
Kun Niu10c9f832019-07-29 16:28:57 -07001925 // Force disable the prebuilts when coverage is enabled.
1926 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1927 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1928
Jiyong Park50b81e52019-07-11 11:24:41 +09001929 // b/137216042 don't use prebuilts when address sanitizer is on
1930 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1931 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1932
1933 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001934 p.properties.ForceDisable = true
1935 return
1936 }
1937
Jiyong Parkc95714e2019-03-29 14:23:10 +09001938 // This is called before prebuilt_select and prebuilt_postdeps mutators
1939 // The mutators requires that src to be set correctly for each arch so that
1940 // arch variants are disabled when src is not provided for the arch.
1941 if len(ctx.MultiTargets()) != 1 {
1942 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1943 return
1944 }
1945 var src string
1946 switch ctx.MultiTargets()[0].Arch.ArchType {
1947 case android.Arm:
1948 src = String(p.properties.Arch.Arm.Src)
1949 case android.Arm64:
1950 src = String(p.properties.Arch.Arm64.Src)
1951 case android.X86:
1952 src = String(p.properties.Arch.X86.Src)
1953 case android.X86_64:
1954 src = String(p.properties.Arch.X86_64.Src)
1955 default:
1956 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1957 return
1958 }
1959 if src == "" {
1960 src = String(p.properties.Src)
1961 }
1962 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001963}
1964
Jiyong Park03b68dd2019-07-26 23:20:40 +09001965func (p *Prebuilt) isForceDisabled() bool {
1966 return p.properties.ForceDisable
1967}
1968
Colin Cross41955e82019-05-29 14:40:35 -07001969func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1970 switch tag {
1971 case "":
1972 return android.Paths{p.outputApex}, nil
1973 default:
1974 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1975 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001976}
1977
Jiyong Park4d277042019-04-23 18:00:10 +09001978func (p *Prebuilt) InstallFilename() string {
1979 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1980}
1981
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001982func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001983 if p.properties.ForceDisable {
1984 return
1985 }
1986
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001987 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001988 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001989 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001990 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001991 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1992 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1993 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001994 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1995 ctx.Build(pctx, android.BuildParams{
1996 Rule: android.Cp,
1997 Input: p.inputApex,
1998 Output: p.outputApex,
1999 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01002000 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002001 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01002002 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002003}
2004
2005func (p *Prebuilt) Prebuilt() *android.Prebuilt {
2006 return &p.prebuilt
2007}
2008
2009func (p *Prebuilt) Name() string {
2010 return p.prebuilt.Name(p.ModuleBase.Name())
2011}
2012
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002013func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
2014 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002015 Class: "ETC",
2016 OutputFile: android.OptionalPathForPath(p.inputApex),
2017 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07002018 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
2019 func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -07002020 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07002021 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
2022 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
2023 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
2024 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002025 },
2026 }
2027}
2028
2029// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
2030func PrebuiltFactory() android.Module {
2031 module := &Prebuilt{}
2032 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07002033 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09002034 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002035 return module
2036}