blob: 4e72d09a67fdb18bf2485d68e1c0240c35fab63d [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
19 "io"
20 "path/filepath"
21 "runtime"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
36var (
37 pctx = android.NewPackageContext("android/apex")
38
39 // Create a canned fs config file where all files and directories are
40 // by default set to (uid/gid/mode) = (1000/1000/0644)
41 // TODO(b/113082813) make this configurable using config.fs syntax
42 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Roland Levillain2b11f742018-11-02 11:50:42 +000043 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +000044 `echo '/apex_manifest.json 1000 1000 0644' >> ${out} && ` +
Jiyong Park92905d62018-10-11 13:23:09 +090045 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
Jiyong Park805cbc32019-01-08 14:04:17 +090046 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090047 Description: "fs_config ${out}",
Jiyong Park92905d62018-10-11 13:23:09 +090048 }, "ro_paths", "exec_paths")
Jiyong Park48ca7dc2018-10-10 14:01:00 +090049
Jooyung Hane1633032019-08-01 17:41:43 +090050 injectApexDependency = pctx.StaticRule("injectApexDependency", blueprint.RuleParams{
51 Command: `rm -f $out && ${jsonmodify} $in ` +
52 `-a provideNativeLibs ${provideNativeLibs} ` +
53 `-a requireNativeLibs ${requireNativeLibs} -o $out`,
54 CommandDeps: []string{"${jsonmodify}"},
55 Description: "Inject dependency into ${out}",
56 }, "provideNativeLibs", "requireNativeLibs")
57
Jiyong Park48ca7dc2018-10-10 14:01:00 +090058 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
59 // against the binary policy using sefcontext_compiler -p <policy>.
60
61 // TODO(b/114327326): automate the generation of file_contexts
62 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
63 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010064 `(. ${out}.copy_commands) && ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090065 `APEXER_TOOL_PATH=${tool_path} ` +
Jiyong Park25560152018-11-20 09:57:52 +090066 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067 `--file_contexts ${file_contexts} ` +
68 `--canned_fs_config ${canned_fs_config} ` +
Alex Light5098a612018-11-29 17:12:15 -080069 `--payload_type image ` +
Jiyong Park835d82b2018-12-27 16:04:18 +090070 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
Jiyong Park48ca7dc2018-10-10 14:01:00 +090071 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
72 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
Dan Willemsendd651fa2019-06-13 04:48:54 +000073 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
Roland Levillain96cf4d42019-07-30 19:56:56 +010074 Rspfile: "${out}.copy_commands",
75 RspfileContent: "${copy_commands}",
76 Description: "APEX ${image_dir} => ${out}",
Jiyong Park835d82b2018-12-27 16:04:18 +090077 }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
Colin Crossa4925902018-11-16 11:36:28 -080078
Alex Light5098a612018-11-29 17:12:15 -080079 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
80 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
Roland Levillain96cf4d42019-07-30 19:56:56 +010081 `(. ${out}.copy_commands) && ` +
Alex Light5098a612018-11-29 17:12:15 -080082 `APEXER_TOOL_PATH=${tool_path} ` +
83 `${apexer} --force --manifest ${manifest} ` +
84 `--payload_type zip ` +
85 `${image_dir} ${out} `,
Roland Levillain96cf4d42019-07-30 19:56:56 +010086 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
87 Rspfile: "${out}.copy_commands",
88 RspfileContent: "${copy_commands}",
89 Description: "ZipAPEX ${image_dir} => ${out}",
Alex Light5098a612018-11-29 17:12:15 -080090 }, "tool_path", "image_dir", "copy_commands", "manifest")
91
Colin Crossa4925902018-11-16 11:36:28 -080092 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
93 blueprint.RuleParams{
94 Command: `${aapt2} convert --output-format proto $in -o $out`,
95 CommandDeps: []string{"${aapt2}"},
96 })
97
98 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Park1ed0fc52018-11-23 13:22:21 +090099 Command: `${zip2zip} -i $in -o $out ` +
Dario Freni4abb1dc2018-11-20 18:04:58 +0000100 `apex_payload.img:apex/${abi}.img ` +
101 `apex_manifest.json:root/apex_manifest.json ` +
Jaewoong Jungb00c1fb2019-09-04 13:26:18 -0700102 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
103 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
Colin Crossa4925902018-11-16 11:36:28 -0800104 CommandDeps: []string{"${zip2zip}"},
105 Description: "app bundle",
106 }, "abi")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100107
108 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
109 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
110 Rspfile: "${out}.emit_commands",
111 RspfileContent: "${emit_commands}",
112 Description: "Emit APEX image content",
113 }, "emit_commands")
114
115 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
116 Command: `diff --unchanged-group-format='' \` +
117 `--changed-group-format='%<' \` +
118 `${image_content_file} ${whitelisted_files_file} || (` +
119 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
120 ` "To fix the build run following command:" && ` +
121 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
122 `exit 1)`,
123 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
124 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900125)
126
Alex Light5098a612018-11-29 17:12:15 -0800127var imageApexSuffix = ".apex"
128var zipApexSuffix = ".zipapex"
129
130var imageApexType = "image"
131var zipApexType = "zip"
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900132
133type dependencyTag struct {
134 blueprint.BaseDependencyTag
135 name string
136}
137
138var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900139 sharedLibTag = dependencyTag{name: "sharedLib"}
140 executableTag = dependencyTag{name: "executable"}
141 javaLibTag = dependencyTag{name: "javaLib"}
142 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +0100143 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900144 keyTag = dependencyTag{name: "key"}
145 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +0900146 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900147 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900148)
149
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900150var (
151 whitelistNoApex = map[string][]string{
152 "apex_test_build_features": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900153 "com.android.media": []string{"libbinder"},
154 "com.android.media.swcodec": []string{"libbinder"},
155 "test_com.android.media.swcodec": []string{"libbinder"},
Jooyung Han344d5432019-08-23 11:17:39 +0900156 "com.android.vndk": []string{"libbinder"},
Jiyong Park4f7dd9b2019-08-12 10:37:49 +0900157 }
158)
159
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900160func init() {
Colin Crosscc0ce802019-04-02 16:14:11 -0700161 pctx.Import("android/soong/android")
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900162 pctx.Import("android/soong/java")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900163 pctx.HostBinToolVariable("apexer", "apexer")
Roland Levillain54bdfda2018-10-05 19:34:32 +0100164 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
165 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
166 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
167 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
David Brazdil91b4e3e2019-01-23 21:04:05 +0000168 if !ctx.Config().FrameworksBaseDirExists(ctx) {
Roland Levillain54bdfda2018-10-05 19:34:32 +0100169 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
170 } else {
171 return pctx.HostBinToolPath(ctx, tool).String()
172 }
173 })
174 }
175 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900176 pctx.HostBinToolVariable("avbtool", "avbtool")
177 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
178 pctx.HostBinToolVariable("merge_zips", "merge_zips")
179 pctx.HostBinToolVariable("mke2fs", "mke2fs")
180 pctx.HostBinToolVariable("resize2fs", "resize2fs")
181 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
182 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Colin Crossa4925902018-11-16 11:36:28 -0800183 pctx.HostBinToolVariable("zip2zip", "zip2zip")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900184 pctx.HostBinToolVariable("zipalign", "zipalign")
Jooyung Hane1633032019-08-01 17:41:43 +0900185 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900186
Jiyong Parkd1063c12019-07-17 20:08:41 +0900187 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800188 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900189 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900190 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700191 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900192
Jooyung Han344d5432019-08-23 11:17:39 +0900193 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
194 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
195 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
196 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900197 android.PostDepsMutators(RegisterPostDepsMutators)
198}
199
200func 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
212func vndkApexList(config android.Config) map[string]*apexBundle {
213 return config.Once(vndkApexListKey, func() interface{} {
214 return map[string]*apexBundle{}
215 }).(map[string]*apexBundle)
216}
217
218// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
219func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
220 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
221 if ab.IsNativeBridgeSupported() {
222 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
223 }
224 vndkVersion := proptools.StringDefault(ab.vndkProperties.Vndk_version, mctx.DeviceConfig().PlatformVndkVersion())
225 vndkApexListMutex.Lock()
226 defer vndkApexListMutex.Unlock()
227 vndkApexList := vndkApexList(mctx.Config())
228 if other, ok := vndkApexList[vndkVersion]; ok {
229 mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.Name())
230 }
231 vndkApexList[vndkVersion] = ab
232 }
233}
234
235// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
236// It filters only libs with matching targets.
237func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
238 if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
239 vndkApexList := vndkApexList(mctx.Config())
240 if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
241 targetArch := cc.Target().String()
242 for _, target := range ab.MultiTargets() {
243 if target.String() == targetArch {
244 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
245 break
246 }
247 }
248 }
249 }
250}
251
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900252// Mark the direct and transitive dependencies of apex bundles so that they
253// can be built for the apex bundles.
254func apexDepsMutator(mctx android.TopDownMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -0800255 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -0800256 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900257 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900258 depName := mctx.OtherModuleName(child)
259 // If the parent is apexBundle, this child is directly depended.
260 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800261 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800262 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
263 // non-installable apex's cannot be installed and so should not prevent libraries from being
264 // installed to the system.
265 android.UpdateApexDependency(apexBundleName, depName, directDep)
266 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900267
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900268 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900269 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900270 return true
271 } else {
272 return false
273 }
274 })
275 }
276}
277
278// Create apex variations if a module is included in APEX(s).
279func apexMutator(mctx android.BottomUpMutatorContext) {
280 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900281 am.CreateApexVariations(mctx)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900282 } else if _, ok := mctx.Module().(*apexBundle); ok {
283 // apex bundle itself is mutated so that it and its modules have same
284 // apex variant.
285 apexBundleName := mctx.ModuleName()
286 mctx.CreateVariations(apexBundleName)
287 }
288}
Sundong Ahne9b55722019-09-06 17:37:42 +0900289
290func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900291 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahne9b55722019-09-06 17:37:42 +0900292 if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
293 modules := mctx.CreateLocalVariations("", "flattened")
294 modules[0].(*apexBundle).SetFlattened(false)
295 modules[1].(*apexBundle).SetFlattened(true)
Sundong Ahne8fb7242019-09-17 13:50:45 +0900296 } else {
297 ab.SetFlattened(true)
298 ab.SetFlattenedConfigValue()
Sundong Ahne9b55722019-09-06 17:37:42 +0900299 }
300 }
301}
302
Jooyung Han5c998b92019-06-27 11:30:33 +0900303func apexUsesMutator(mctx android.BottomUpMutatorContext) {
304 if ab, ok := mctx.Module().(*apexBundle); ok {
305 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
306 }
307}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900308
Alex Light9670d332019-01-29 18:07:33 -0800309type apexNativeDependencies struct {
310 // List of native libraries
311 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900312
Alex Light9670d332019-01-29 18:07:33 -0800313 // List of native executables
314 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900315
Roland Levillain630846d2019-06-26 12:48:34 +0100316 // List of native tests
317 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800318}
Jooyung Han344d5432019-08-23 11:17:39 +0900319
Alex Light9670d332019-01-29 18:07:33 -0800320type apexMultilibProperties struct {
321 // Native dependencies whose compile_multilib is "first"
322 First apexNativeDependencies
323
324 // Native dependencies whose compile_multilib is "both"
325 Both apexNativeDependencies
326
327 // Native dependencies whose compile_multilib is "prefer32"
328 Prefer32 apexNativeDependencies
329
330 // Native dependencies whose compile_multilib is "32"
331 Lib32 apexNativeDependencies
332
333 // Native dependencies whose compile_multilib is "64"
334 Lib64 apexNativeDependencies
335}
336
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900337type apexBundleProperties struct {
338 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000339 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800340 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900341
Jiyong Park40e26a22019-02-08 02:53:06 +0900342 // AndroidManifest.xml file used for the zip container of this APEX bundle.
343 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800344 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900345
Roland Levillain411c5842019-09-19 16:37:20 +0100346 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
347 // device (/apex/<apex_name>).
348 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900349 Apex_name *string
350
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900351 // Determines the file contexts file for setting security context to each file in this APEX bundle.
352 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
353 // used.
354 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900355 File_contexts *string
356
357 // List of native shared libs that are embedded inside this APEX bundle
358 Native_shared_libs []string
359
Roland Levillain630846d2019-06-26 12:48:34 +0100360 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900361 Binaries []string
362
363 // List of java libraries that are embedded inside this APEX bundle
364 Java_libs []string
365
366 // List of prebuilt files that are embedded inside this APEX bundle
367 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900368
Roland Levillain630846d2019-06-26 12:48:34 +0100369 // List of tests that are embedded inside this APEX bundle
370 Tests []string
371
Jiyong Parkff1458f2018-10-12 21:49:38 +0900372 // Name of the apex_key module that provides the private key to sign APEX
373 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900374
Alex Light5098a612018-11-29 17:12:15 -0800375 // The type of APEX to build. Controls what the APEX payload is. Either
376 // 'image', 'zip' or 'both'. Default: 'image'.
377 Payload_type *string
378
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900379 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
380 // or an android_app_certificate module name in the form ":module".
381 Certificate *string
382
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900383 // Whether this APEX is installable to one of the partitions. Default: true.
384 Installable *bool
385
Jiyong Parkda6eb592018-12-19 17:12:36 +0900386 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
387 // Default is false.
388 Use_vendor *bool
389
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800390 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
391 Ignore_system_library_special_case *bool
392
Alex Light9670d332019-01-29 18:07:33 -0800393 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900394
Jiyong Parkf97782b2019-02-13 20:28:58 +0900395 // List of sanitizer names that this APEX is enabled for
396 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900397
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900398 PreventInstall bool `blueprint:"mutated"`
399
400 HideFromMake bool `blueprint:"mutated"`
401
Jooyung Han5c998b92019-06-27 11:30:33 +0900402 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
403 Provide_cpp_shared_libs *bool
404
405 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
406 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100407
408 // A txt file containing list of files that are whitelisted to be included in this APEX.
409 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900410
411 // List of APKs to package inside APEX
412 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900413
Sundong Ahne8fb7242019-09-17 13:50:45 +0900414 // To distinguish between flattened and non-flattened apex.
415 // if set true, then output files are flattened.
Sundong Ahne9b55722019-09-06 17:37:42 +0900416 Flattened bool `blueprint:"mutated"`
Jiyong Parkd1063c12019-07-17 20:08:41 +0900417
Sundong Ahne8fb7242019-09-17 13:50:45 +0900418 // if true, it means that TARGET_FLATTEN_APEX is true and
419 // TARGET_BUILD_APPS is false
420 FlattenedConfigValue bool `blueprint:"mutated"`
421
Jiyong Parkd1063c12019-07-17 20:08:41 +0900422 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
423 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
424 // is implied. This value affects all modules included in this APEX. In other words, they are
425 // also built with the SDKs specified here.
426 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800427}
428
429type apexTargetBundleProperties struct {
430 Target struct {
431 // Multilib properties only for android.
432 Android struct {
433 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900434 }
Jooyung Han344d5432019-08-23 11:17:39 +0900435
Alex Light9670d332019-01-29 18:07:33 -0800436 // Multilib properties only for host.
437 Host struct {
438 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900439 }
Jooyung Han344d5432019-08-23 11:17:39 +0900440
Alex Light9670d332019-01-29 18:07:33 -0800441 // Multilib properties only for host linux_bionic.
442 Linux_bionic struct {
443 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900444 }
Jooyung Han344d5432019-08-23 11:17:39 +0900445
Alex Light9670d332019-01-29 18:07:33 -0800446 // Multilib properties only for host linux_glibc.
447 Linux_glibc struct {
448 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900449 }
450 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900451}
452
Jooyung Han344d5432019-08-23 11:17:39 +0900453type apexVndkProperties struct {
454 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
455 Vndk_version *string
456}
457
Jiyong Park8fd61922018-11-08 02:50:25 +0900458type apexFileClass int
459
460const (
461 etc apexFileClass = iota
462 nativeSharedLib
463 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900464 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800465 pyBinary
466 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900467 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100468 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900469 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900470)
471
Alex Light5098a612018-11-29 17:12:15 -0800472type apexPackaging int
473
474const (
475 imageApex apexPackaging = iota
476 zipApex
477 both
478)
479
480func (a apexPackaging) image() bool {
481 switch a {
482 case imageApex, both:
483 return true
484 }
485 return false
486}
487
488func (a apexPackaging) zip() bool {
489 switch a {
490 case zipApex, both:
491 return true
492 }
493 return false
494}
495
496func (a apexPackaging) suffix() string {
497 switch a {
498 case imageApex:
499 return imageApexSuffix
500 case zipApex:
501 return zipApexSuffix
502 case both:
503 panic(fmt.Errorf("must be either zip or image"))
504 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100505 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800506 }
507}
508
509func (a apexPackaging) name() string {
510 switch a {
511 case imageApex:
512 return imageApexType
513 case zipApex:
514 return zipApexType
515 case both:
516 panic(fmt.Errorf("must be either zip or image"))
517 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100518 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800519 }
520}
521
Jiyong Park8fd61922018-11-08 02:50:25 +0900522func (class apexFileClass) NameInMake() string {
523 switch class {
524 case etc:
525 return "ETC"
526 case nativeSharedLib:
527 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800528 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900529 return "EXECUTABLES"
530 case javaSharedLib:
531 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100532 case nativeTest:
533 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900534 case app:
535 return "APPS"
Jiyong Park8fd61922018-11-08 02:50:25 +0900536 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100537 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900538 }
539}
540
541type apexFile struct {
542 builtFile android.Path
543 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900544 installDir string
545 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900546 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800547 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900548}
549
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900550type apexBundle struct {
551 android.ModuleBase
552 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900553 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900554
Alex Light9670d332019-01-29 18:07:33 -0800555 properties apexBundleProperties
556 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900557 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900558
Alex Light5098a612018-11-29 17:12:15 -0800559 apexTypes apexPackaging
560
Colin Crossa4925902018-11-16 11:36:28 -0800561 bundleModuleFile android.WritablePath
Alex Light5098a612018-11-29 17:12:15 -0800562 outputFiles map[apexPackaging]android.WritablePath
Roland Levillain935639d2019-08-13 14:55:28 +0100563 flattenedOutput android.OutputPath
Colin Crossa4925902018-11-16 11:36:28 -0800564 installDir android.OutputPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900565
Jiyong Park03b68dd2019-07-26 23:20:40 +0900566 prebuiltFileToDelete string
567
Jiyong Park42cca6c2019-04-01 11:15:50 +0900568 public_key_file android.Path
569 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900570
571 container_certificate_file android.Path
572 container_private_key_file android.Path
573
Jiyong Park8fd61922018-11-08 02:50:25 +0900574 // list of files to be included in this apex
575 filesInfo []apexFile
576
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900577 // list of module names that this APEX is depending on
578 externalDeps []string
579
Alex Light0851b882019-02-07 13:20:53 -0800580 testApex bool
Jooyung Han344d5432019-08-23 11:17:39 +0900581 vndkApex bool
Jooyung Hane1633032019-08-01 17:41:43 +0900582
583 // intermediate path for apex_manifest.json
584 manifestOut android.WritablePath
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900585}
586
Jiyong Park397e55e2018-10-24 21:09:55 +0900587func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100588 native_shared_libs []string, binaries []string, tests []string,
589 arch string, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900590 // Use *FarVariation* to be able to depend on modules having
591 // conflicting variations with this module. This is required since
592 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
593 // for native shared libs.
594 ctx.AddFarVariationDependencies([]blueprint.Variation{
595 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900596 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900597 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900598 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jiyong Park397e55e2018-10-24 21:09:55 +0900599 }, sharedLibTag, native_shared_libs...)
600
601 ctx.AddFarVariationDependencies([]blueprint.Variation{
602 {Mutator: "arch", Variation: arch},
Jiyong Parkda6eb592018-12-19 17:12:36 +0900603 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900604 }, executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100605
606 ctx.AddFarVariationDependencies([]blueprint.Variation{
607 {Mutator: "arch", Variation: arch},
608 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100609 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100610 }, testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900611}
612
Alex Light9670d332019-01-29 18:07:33 -0800613func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
614 if ctx.Os().Class == android.Device {
615 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
616 } else {
617 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
618 if ctx.Os().Bionic() {
619 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
620 } else {
621 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
622 }
623 }
624}
625
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900626func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Alex Light9670d332019-01-29 18:07:33 -0800627
Jiyong Park397e55e2018-10-24 21:09:55 +0900628 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900629 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800630
631 a.combineProperties(ctx)
632
Jiyong Park397e55e2018-10-24 21:09:55 +0900633 has32BitTarget := false
634 for _, target := range targets {
635 if target.Arch.ArchType.Multilib == "lib32" {
636 has32BitTarget = true
637 }
638 }
639 for i, target := range targets {
640 // When multilib.* is omitted for native_shared_libs, it implies
641 // multilib.both.
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900642 ctx.AddFarVariationDependencies([]blueprint.Variation{
Jiyong Park397e55e2018-10-24 21:09:55 +0900643 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900644 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900645 {Mutator: "link", Variation: "shared"},
646 }, sharedLibTag, a.properties.Native_shared_libs...)
647
Roland Levillain630846d2019-06-26 12:48:34 +0100648 // When multilib.* is omitted for tests, it implies
649 // multilib.both.
650 ctx.AddFarVariationDependencies([]blueprint.Variation{
651 {Mutator: "arch", Variation: target.String()},
652 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100653 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Roland Levillain630846d2019-06-26 12:48:34 +0100654 }, testTag, a.properties.Tests...)
655
Jiyong Park397e55e2018-10-24 21:09:55 +0900656 // Add native modules targetting both ABIs
657 addDependenciesForNativeModules(ctx,
658 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100659 a.properties.Multilib.Both.Binaries,
660 a.properties.Multilib.Both.Tests,
661 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900662 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900663
Alex Light3d673592019-01-18 14:37:31 -0800664 isPrimaryAbi := i == 0
665 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900666 // When multilib.* is omitted for binaries, it implies
667 // multilib.first.
668 ctx.AddFarVariationDependencies([]blueprint.Variation{
669 {Mutator: "arch", Variation: target.String()},
Jiyong Park7c1dc612019-01-05 11:15:24 +0900670 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park397e55e2018-10-24 21:09:55 +0900671 }, executableTag, a.properties.Binaries...)
672
673 // Add native modules targetting the first ABI
674 addDependenciesForNativeModules(ctx,
675 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100676 a.properties.Multilib.First.Binaries,
677 a.properties.Multilib.First.Tests,
678 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900679 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800680
681 // When multilib.* is omitted for prebuilts, it implies multilib.first.
682 ctx.AddFarVariationDependencies([]blueprint.Variation{
683 {Mutator: "arch", Variation: target.String()},
684 }, prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900685 }
686
687 switch target.Arch.ArchType.Multilib {
688 case "lib32":
689 // Add native modules targetting 32-bit ABI
690 addDependenciesForNativeModules(ctx,
691 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100692 a.properties.Multilib.Lib32.Binaries,
693 a.properties.Multilib.Lib32.Tests,
694 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900695 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900696
697 addDependenciesForNativeModules(ctx,
698 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100699 a.properties.Multilib.Prefer32.Binaries,
700 a.properties.Multilib.Prefer32.Tests,
701 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900702 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900703 case "lib64":
704 // Add native modules targetting 64-bit ABI
705 addDependenciesForNativeModules(ctx,
706 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100707 a.properties.Multilib.Lib64.Binaries,
708 a.properties.Multilib.Lib64.Tests,
709 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900710 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900711
712 if !has32BitTarget {
713 addDependenciesForNativeModules(ctx,
714 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100715 a.properties.Multilib.Prefer32.Binaries,
716 a.properties.Multilib.Prefer32.Tests,
717 target.String(),
Jiyong Park7c1dc612019-01-05 11:15:24 +0900718 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900719 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700720
721 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
722 for _, sanitizer := range ctx.Config().SanitizeDevice() {
723 if sanitizer == "hwaddress" {
724 addDependenciesForNativeModules(ctx,
725 []string{"libclang_rt.hwasan-aarch64-android"},
Roland Levillain630846d2019-06-26 12:48:34 +0100726 nil, nil, target.String(), a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700727 break
728 }
729 }
730 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900731 }
732
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900733 }
734
Jiyong Parkff1458f2018-10-12 21:49:38 +0900735 ctx.AddFarVariationDependencies([]blueprint.Variation{
736 {Mutator: "arch", Variation: "android_common"},
737 }, javaLibTag, a.properties.Java_libs...)
738
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900739 ctx.AddFarVariationDependencies([]blueprint.Variation{
740 {Mutator: "arch", Variation: "android_common"},
741 }, androidAppTag, a.properties.Apps...)
742
Jiyong Park23c52b02019-02-02 13:13:47 +0900743 if String(a.properties.Key) == "" {
744 ctx.ModuleErrorf("key is missing")
745 return
746 }
747 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900748
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900749 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900750 if cert != "" {
751 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900752 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900753
754 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
755 if len(a.properties.Uses_sdks) > 0 {
756 sdkRefs := []android.SdkRef{}
757 for _, str := range a.properties.Uses_sdks {
758 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
759 sdkRefs = append(sdkRefs, parsed)
760 }
761 a.BuildWithSdks(sdkRefs)
762 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900763}
764
Colin Cross0ea8ba82019-06-06 14:33:29 -0700765func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900766 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
767 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000768 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900769 }
770 return String(a.properties.Certificate)
771}
772
Colin Cross41955e82019-05-29 14:40:35 -0700773func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
774 switch tag {
775 case "":
776 if file, ok := a.outputFiles[imageApex]; ok {
777 return android.Paths{file}, nil
778 } else {
779 return nil, nil
780 }
Roland Levillain935639d2019-08-13 14:55:28 +0100781 case ".flattened":
Sundong Ahne9b55722019-09-06 17:37:42 +0900782 if a.properties.Flattened {
Roland Levillain935639d2019-08-13 14:55:28 +0100783 flattenedApexPath := a.flattenedOutput
784 return android.Paths{flattenedApexPath}, nil
785 } else {
786 return nil, nil
787 }
Colin Cross41955e82019-05-29 14:40:35 -0700788 default:
789 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900790 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900791}
792
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900793func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900794 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900795}
796
Jiyong Park7c1dc612019-01-05 11:15:24 +0900797func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
798 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900799 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900800 } else {
801 return "core"
802 }
803}
804
Jiyong Parkf97782b2019-02-13 20:28:58 +0900805func (a *apexBundle) EnableSanitizer(sanitizerName string) {
806 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
807 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
808 }
809}
810
Jiyong Park388ef3f2019-01-28 19:47:32 +0900811func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900812 if android.InList(sanitizerName, a.properties.SanitizerNames) {
813 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900814 }
815
816 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900817 globalSanitizerNames := []string{}
818 if a.Host() {
819 globalSanitizerNames = ctx.Config().SanitizeHost()
820 } else {
821 arches := ctx.Config().SanitizeDeviceArch()
822 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
823 globalSanitizerNames = ctx.Config().SanitizeDevice()
824 }
825 }
826 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900827}
828
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900829func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
830 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
831}
832
833func (a *apexBundle) PreventInstall() {
834 a.properties.PreventInstall = true
835}
836
837func (a *apexBundle) HideFromMake() {
838 a.properties.HideFromMake = true
839}
840
Sundong Ahne9b55722019-09-06 17:37:42 +0900841func (a *apexBundle) SetFlattened(flattened bool) {
842 a.properties.Flattened = flattened
843}
844
Sundong Ahne8fb7242019-09-17 13:50:45 +0900845func (a *apexBundle) SetFlattenedConfigValue() {
846 a.properties.FlattenedConfigValue = true
847}
848
849// isFlattenedVariant returns true when the current module is the flattened
850// variant of an apex that has both a flattened and an unflattened variant.
851// It returns false when the current module is flattened but there is no
852// unflattened variant, which occurs when ctx.Config().FlattenedApex() returns
853// true. It can be used to avoid collisions between the install paths of the
854// flattened and unflattened variants.
855func (a *apexBundle) isFlattenedVariant() bool {
856 return a.properties.Flattened && !a.properties.FlattenedConfigValue
857}
858
Martin Stjernholm279de572019-09-10 23:18:20 +0100859func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900860 // Decide the APEX-local directory by the multilib of the library
861 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100862 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863 case "lib32":
864 dirInApex = "lib"
865 case "lib64":
866 dirInApex = "lib64"
867 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100868 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
869 if !ccMod.Arch().Native {
870 dirInApex = filepath.Join(dirInApex, ccMod.Arch().ArchType.String())
871 } else if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
872 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900873 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100874 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
875 // Special case for Bionic libs and other libs installed with them. This is
876 // to prevent those libs from being included in the search path
877 // /apex/com.android.runtime/${LIB}. This exclusion is required because
878 // those libs in the Runtime APEX are available via the legacy paths in
879 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
880 // to the legacy paths and thus will be loaded into the default linker
881 // namespace (aka "platform" namespace). If the libs are directly in
882 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
883 // into the runtime linker namespace, which will result in double loading of
884 // them, which isn't supported.
885 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900886 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900887
Martin Stjernholm279de572019-09-10 23:18:20 +0100888 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900889 return
890}
891
892func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900893 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
dimitry8d6dde82019-07-11 10:23:53 +0200894 if !cc.Arch().Native {
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900895 dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +0200896 } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
897 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900898 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900899 fileToCopy = cc.OutputFile().Path()
900 return
901}
902
Alex Light778127a2019-02-27 14:19:50 -0800903func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
904 dirInApex = "bin"
905 fileToCopy = py.HostToolPath().Path()
906 return
907}
908func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
909 dirInApex = "bin"
910 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
911 if err != nil {
912 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
913 return
914 }
915 fileToCopy = android.PathForOutput(ctx, s)
916 return
917}
918
Jiyong Park04480cf2019-02-06 00:16:29 +0900919func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
920 dirInApex = filepath.Join("bin", sh.SubDir())
921 fileToCopy = sh.OutputFile()
922 return
923}
924
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900925func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
926 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900927 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900928 return
929}
930
Jiyong Park9e6c2422019-08-09 20:39:45 +0900931func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
932 dirInApex = "javalib"
933 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
934 implJars := java.ImplementationJars()
935 if len(implJars) != 1 {
936 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
937 strings.Join(implJars.Strings(), ", ")))
938 }
939 fileToCopy = implJars[0]
940 return
941}
942
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900943func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
944 dirInApex = filepath.Join("etc", prebuilt.SubDir())
945 fileToCopy = prebuilt.OutputFile()
946 return
947}
948
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900949func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
950 dirInApex = filepath.Join("app", pkgName)
951 fileToCopy = app.OutputFile()
952 return
953}
954
Roland Levillain935639d2019-08-13 14:55:28 +0100955// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
956type flattenedApexContext struct {
957 android.ModuleContext
958}
959
960func (c *flattenedApexContext) InstallBypassMake() bool {
961 return true
962}
963
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900964func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900965 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900966
Alex Light5098a612018-11-29 17:12:15 -0800967 if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
968 a.apexTypes = imageApex
969 } else if *a.properties.Payload_type == "zip" {
970 a.apexTypes = zipApex
971 } else if *a.properties.Payload_type == "both" {
972 a.apexTypes = both
973 } else {
974 ctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *a.properties.Payload_type)
975 return
976 }
977
Roland Levillain630846d2019-06-26 12:48:34 +0100978 if len(a.properties.Tests) > 0 && !a.testApex {
979 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
980 return
981 }
982
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800983 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
984
Jooyung Hane1633032019-08-01 17:41:43 +0900985 // native lib dependencies
986 var provideNativeLibs []string
987 var requireNativeLibs []string
988
Jooyung Han5c998b92019-06-27 11:30:33 +0900989 // Check if "uses" requirements are met with dependent apexBundles
990 var providedNativeSharedLibs []string
991 useVendor := proptools.Bool(a.properties.Use_vendor)
992 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
993 if ctx.OtherModuleDependencyTag(m) != usesTag {
994 return
995 }
996 otherName := ctx.OtherModuleName(m)
997 other, ok := m.(*apexBundle)
998 if !ok {
999 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1000 return
1001 }
1002 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1003 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1004 return
1005 }
1006 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1007 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1008 return
1009 }
1010 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1011 })
1012
Alex Light778127a2019-02-27 14:19:50 -08001013 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001014 depTag := ctx.OtherModuleDependencyTag(child)
1015 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016 if _, ok := parent.(*apexBundle); ok {
1017 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001018 switch depTag {
1019 case sharedLibTag:
1020 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001021 if cc.HasStubsVariants() {
1022 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1023 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001024 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +09001025 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001027 } else {
1028 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001029 }
1030 case executableTag:
1031 if cc, ok := child.(*cc.Module); ok {
1032 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +09001033 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001034 return true
Jiyong Park04480cf2019-02-06 00:16:29 +09001035 } else if sh, ok := child.(*android.ShBinary); ok {
1036 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
1037 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
Alex Light778127a2019-02-27 14:19:50 -08001038 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
1039 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
1040 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
1041 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
1042 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
1043 // NB: Since go binaries are static we don't need the module for anything here, which is
1044 // good since the go tool is a blueprint.Module not an android.Module like we would
1045 // normally use.
1046 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +09001047 } else {
Alex Light778127a2019-02-27 14:19:50 -08001048 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 +09001049 }
1050 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001051 if javaLib, ok := child.(*java.Library); ok {
1052 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +09001053 if fileToCopy == nil {
1054 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1055 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001056 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
1057 }
1058 return true
1059 } else if javaLib, ok := child.(*java.Import); ok {
1060 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
1061 if fileToCopy == nil {
1062 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
1063 } else {
1064 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001065 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001066 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001067 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001068 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001069 }
1070 case prebuiltTag:
1071 if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
1072 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +09001073 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001074 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +09001075 } else {
1076 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1077 }
Roland Levillain630846d2019-06-26 12:48:34 +01001078 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001079 if ccTest, ok := child.(*cc.Module); ok {
1080 if ccTest.IsTestPerSrcAllTestsVariation() {
1081 // Multiple-output test module (where `test_per_src: true`).
1082 //
1083 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1084 // We do not add this variation to `filesInfo`, as it has no output;
1085 // however, we do add the other variations of this module as indirect
1086 // dependencies (see below).
1087 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001088 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001089 // Single-output test module (where `test_per_src: false`).
1090 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1091 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001092 }
Roland Levillain630846d2019-06-26 12:48:34 +01001093 return true
1094 } else {
1095 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1096 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001097 case keyTag:
1098 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001099 a.private_key_file = key.private_key_file
1100 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001101 return false
1102 } else {
1103 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001104 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001105 case certificateTag:
1106 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001107 a.container_certificate_file = dep.Certificate.Pem
1108 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001109 return false
1110 } else {
1111 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1112 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001113 case android.PrebuiltDepTag:
1114 // If the prebuilt is force disabled, remember to delete the prebuilt file
1115 // that might have been installed in the previous builds
1116 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1117 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1118 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001119 case androidAppTag:
1120 if ap, ok := child.(*java.AndroidApp); ok {
1121 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1122 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1123 return true
1124 } else {
1125 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1126 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001127 }
1128 } else {
1129 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001130 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001131 // We cannot use a switch statement on `depTag` here as the checked
1132 // tags used below are private (e.g. `cc.sharedDepTag`).
1133 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
1134 if cc, ok := child.(*cc.Module); ok {
1135 if android.InList(cc.Name(), providedNativeSharedLibs) {
1136 // If we're using a shared library which is provided from other APEX,
1137 // don't include it in this APEX
1138 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001139 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001140 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1141 // If the dependency is a stubs lib, don't include it in this APEX,
1142 // but make sure that the lib is installed on the device.
1143 // In case no APEX is having the lib, the lib is installed to the system
1144 // partition.
1145 //
1146 // Always include if we are a host-apex however since those won't have any
1147 // system libraries.
1148 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1149 a.externalDeps = append(a.externalDeps, cc.Name())
1150 }
Jooyung Hane1633032019-08-01 17:41:43 +09001151 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001152 // Don't track further
1153 return false
1154 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001155 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001156 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1157 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001158 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001159 } else if cc.IsTestPerSrcDepTag(depTag) {
1160 if cc, ok := child.(*cc.Module); ok {
1161 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1162 // Handle modules created as `test_per_src` variations of a single test module:
1163 // use the name of the generated test binary (`fileToCopy`) instead of the name
1164 // of the original test module (`depName`, shared by all `test_per_src`
1165 // variations of that module).
1166 moduleName := filepath.Base(fileToCopy.String())
1167 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1168 return true
1169 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001170 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001171 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jooyung Hancc372c52019-09-25 15:18:44 +09001172 } else if depTag == android.DefaultsDepTag {
1173 return false
Sundong Ahn2db7f462019-08-27 18:53:12 +09001174 } else if am.NoApex() && !android.InList(depName, whitelistNoApex[ctx.ModuleName()]) {
1175 ctx.ModuleErrorf("tries to include no_apex module %s", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001176 }
1177 }
1178 }
1179 return false
1180 })
1181
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001182 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001183 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1184 return
1185 }
1186
Jiyong Park8fd61922018-11-08 02:50:25 +09001187 // remove duplicates in filesInfo
1188 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001189 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001190 result := []apexFile{}
1191 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001192 dest := filepath.Join(f.installDir, f.builtFile.Base())
1193 if !encountered[dest] {
1194 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001195 result = append(result, f)
1196 }
1197 }
1198 return result
1199 }
1200 filesInfo = removeDup(filesInfo)
1201
1202 // to have consistent build rules
1203 sort.Slice(filesInfo, func(i, j int) bool {
1204 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1205 })
1206
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09001207 // check no_apex modules
1208 whitelist := whitelistNoApex[ctx.ModuleName()]
1209 for i := range filesInfo {
1210 if am, ok := filesInfo[i].module.(android.ApexModule); ok {
1211 if am.NoApex() && !android.InList(filesInfo[i].moduleName, whitelist) {
1212 ctx.ModuleErrorf("tries to include no_apex module %s", filesInfo[i].moduleName)
1213 }
1214 }
1215 }
1216
Jiyong Park8fd61922018-11-08 02:50:25 +09001217 // prepend the name of this APEX to the module names. These names will be the names of
1218 // modules that will be defined if the APEX is flattened.
1219 for i := range filesInfo {
1220 filesInfo[i].moduleName = ctx.ModuleName() + "." + filesInfo[i].moduleName
1221 }
1222
Jiyong Park8fd61922018-11-08 02:50:25 +09001223 a.installDir = android.PathForModuleInstall(ctx, "apex")
1224 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001225
Jooyung Hane1633032019-08-01 17:41:43 +09001226 a.manifestOut = android.PathForModuleOut(ctx, "apex_manifest.json")
1227 // put dependency({provide|require}NativeLibs) in apex_manifest.json
1228 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
1229 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
1230 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
1231 ctx.Build(pctx, android.BuildParams{
1232 Rule: injectApexDependency,
1233 Input: manifestSrc,
1234 Output: a.manifestOut,
1235 Args: map[string]string{
1236 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
1237 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
1238 },
1239 })
1240
Roland Levillain935639d2019-08-13 14:55:28 +01001241 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
1242 // reply true to `InstallBypassMake()` (thus making the call
1243 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
1244 // instead of `android.PathForOutput`) to return the correct path to the flattened
1245 // APEX (as its contents is installed by Make, not Soong).
1246 factx := flattenedApexContext{ctx}
1247 a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
1248
Alex Light5098a612018-11-29 17:12:15 -08001249 if a.apexTypes.zip() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001250 a.buildUnflattenedApex(ctx, zipApex)
Alex Light5098a612018-11-29 17:12:15 -08001251 }
1252 if a.apexTypes.image() {
Jiyong Park23c52b02019-02-02 13:13:47 +09001253 // Build rule for unflattened APEX is created even when ctx.Config().FlattenApex()
Roland Levillaindfe75b32019-07-23 16:53:32 +01001254 // is true. This is to support referencing APEX via ":<module_name>" syntax
Jiyong Park23c52b02019-02-02 13:13:47 +09001255 // in other modules. It is in AndroidMk where the selection of flattened
1256 // or unflattened APEX is made.
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001257 a.buildUnflattenedApex(ctx, imageApex)
Jiyong Park23c52b02019-02-02 13:13:47 +09001258 a.buildFlattenedApex(ctx)
Jiyong Park8fd61922018-11-08 02:50:25 +09001259 }
1260}
1261
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001262func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
Jiyong Park52818fc2019-03-18 12:01:38 +09001263 noticeFiles := []android.Path{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001264 for _, f := range a.filesInfo {
1265 if f.module != nil {
1266 notice := f.module.NoticeFile()
1267 if notice.Valid() {
1268 noticeFiles = append(noticeFiles, notice.Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001269 }
1270 }
1271 }
1272 // append the notice file specified in the apex module itself
1273 if a.NoticeFile().Valid() {
1274 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
Jiyong Park52818fc2019-03-18 12:01:38 +09001275 }
1276
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001277 if len(noticeFiles) == 0 {
1278 return android.OptionalPath{}
Jiyong Park52818fc2019-03-18 12:01:38 +09001279 }
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001280
Jaewoong Jung98772792019-07-01 17:15:13 -07001281 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
Jiyong Park52818fc2019-03-18 12:01:38 +09001282}
1283
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001284func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001285 cert := String(a.properties.Certificate)
1286 if cert != "" && android.SrcIsModule(cert) == "" {
1287 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001288 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
1289 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001290 } else if cert == "" {
1291 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001292 a.container_certificate_file = pem
1293 a.container_private_key_file = key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001294 }
1295
Alex Light5098a612018-11-29 17:12:15 -08001296 var abis []string
1297 for _, target := range ctx.MultiTargets() {
1298 if len(target.Arch.Abi) > 0 {
1299 abis = append(abis, target.Arch.Abi[0])
1300 }
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001301 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001302
Alex Light5098a612018-11-29 17:12:15 -08001303 abis = android.FirstUniqueStrings(abis)
1304
1305 suffix := apexType.suffix()
1306 unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001307
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001308 filesToCopy := []android.Path{}
Jiyong Park8fd61922018-11-08 02:50:25 +09001309 for _, f := range a.filesInfo {
1310 filesToCopy = append(filesToCopy, f.builtFile)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001311 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001312
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001313 copyCommands := []string{}
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001314 emitCommands := []string{}
1315 imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
1316 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001317 for i, src := range filesToCopy {
1318 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001319 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
Alex Light5098a612018-11-29 17:12:15 -08001320 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001321 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
1322 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
Alex Light3d673592019-01-18 14:37:31 -08001323 for _, sym := range a.filesInfo[i].symlinks {
1324 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
1325 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
1326 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001327 }
Jiyong Parkab3ceb32018-10-10 14:05:29 +09001328 implicitInputs := append(android.Paths(nil), filesToCopy...)
Jooyung Hane1633032019-08-01 17:41:43 +09001329 implicitInputs = append(implicitInputs, a.manifestOut)
Alex Light5098a612018-11-29 17:12:15 -08001330
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001331 if a.properties.Whitelisted_files != nil {
1332 ctx.Build(pctx, android.BuildParams{
1333 Rule: emitApexContentRule,
1334 Implicits: implicitInputs,
1335 Output: imageContentFile,
1336 Description: "emit apex image content",
1337 Args: map[string]string{
1338 "emit_commands": strings.Join(emitCommands, " && "),
1339 },
1340 })
1341 implicitInputs = append(implicitInputs, imageContentFile)
1342 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
1343
Nikita Ioffe1acf6f92019-09-04 11:53:14 +01001344 phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001345 ctx.Build(pctx, android.BuildParams{
1346 Rule: diffApexContentRule,
1347 Implicits: implicitInputs,
1348 Output: phonyOutput,
1349 Description: "diff apex image content",
1350 Args: map[string]string{
1351 "whitelisted_files_file": whitelistedFilesFile.String(),
1352 "image_content_file": imageContentFile.String(),
1353 "apex_module_name": ctx.ModuleName(),
1354 },
1355 })
1356
1357 implicitInputs = append(implicitInputs, phonyOutput)
1358 }
1359
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001360 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
1361 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001362
Alex Light5098a612018-11-29 17:12:15 -08001363 if apexType.image() {
1364 // files and dirs that will be created in APEX
1365 var readOnlyPaths []string
1366 var executablePaths []string // this also includes dirs
1367 for _, f := range a.filesInfo {
1368 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
Roland Levillain630846d2019-06-26 12:48:34 +01001369 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
Alex Light5098a612018-11-29 17:12:15 -08001370 executablePaths = append(executablePaths, pathInApex)
Alex Light3d673592019-01-18 14:37:31 -08001371 for _, s := range f.symlinks {
Jiyong Parkc80b5fa2019-07-20 14:24:33 +09001372 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
Alex Light3d673592019-01-18 14:37:31 -08001373 }
Alex Light5098a612018-11-29 17:12:15 -08001374 } else {
1375 readOnlyPaths = append(readOnlyPaths, pathInApex)
1376 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001377 dir := f.installDir
1378 for !android.InList(dir, executablePaths) && dir != "" {
1379 executablePaths = append(executablePaths, dir)
1380 dir, _ = filepath.Split(dir) // move up to the parent
1381 if len(dir) > 0 {
1382 // remove trailing slash
1383 dir = dir[:len(dir)-1]
1384 }
Alex Light5098a612018-11-29 17:12:15 -08001385 }
1386 }
1387 sort.Strings(readOnlyPaths)
1388 sort.Strings(executablePaths)
1389 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
1390 ctx.Build(pctx, android.BuildParams{
1391 Rule: generateFsConfig,
1392 Output: cannedFsConfig,
1393 Description: "generate fs config",
1394 Args: map[string]string{
1395 "ro_paths": strings.Join(readOnlyPaths, " "),
1396 "exec_paths": strings.Join(executablePaths, " "),
1397 },
1398 })
1399
1400 fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
1401 fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts"
1402 fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath)
1403 if !fileContextsOptionalPath.Valid() {
1404 ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath)
1405 return
1406 }
1407 fileContexts := fileContextsOptionalPath.Path()
1408
Jiyong Park835d82b2018-12-27 16:04:18 +09001409 optFlags := []string{}
1410
Alex Light5098a612018-11-29 17:12:15 -08001411 // Additional implicit inputs.
Jiyong Park42cca6c2019-04-01 11:15:50 +09001412 implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file)
1413 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
Alex Light5098a612018-11-29 17:12:15 -08001414
Jiyong Park7f67f482019-01-05 12:57:48 +09001415 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1416 if overridden {
1417 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
1418 }
1419
Jiyong Park40e26a22019-02-08 02:53:06 +09001420 if a.properties.AndroidManifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001421 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
Jiyong Park40e26a22019-02-08 02:53:06 +09001422 implicitInputs = append(implicitInputs, androidManifestFile)
1423 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
1424 }
1425
Jiyong Park71b519d2019-04-18 17:25:49 +09001426 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
1427 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
1428 ctx.Config().UnbundledBuild() &&
1429 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
1430 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
1431 apiFingerprint := java.ApiFingerprintPath(ctx)
1432 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
1433 implicitInputs = append(implicitInputs, apiFingerprint)
1434 }
1435 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
1436
Jaewoong Jung14f5ff62019-06-18 13:09:13 -07001437 noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix)
1438 if noticeFile.Valid() {
1439 // If there's a NOTICE file, embed it as an asset file in the APEX.
1440 implicitInputs = append(implicitInputs, noticeFile.Path())
1441 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
1442 }
1443
Jooyung Hane65ed7c2019-08-28 00:27:35 +09001444 if !ctx.Config().UnbundledBuild() && a.installable() {
1445 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
1446 // don't need hashtree for activation. Therefore, by removing hashtree from
1447 // apex bundle (filesystem image in it, to be specific), we can save storage.
1448 optFlags = append(optFlags, "--no_hashtree")
1449 }
1450
Alex Light5098a612018-11-29 17:12:15 -08001451 ctx.Build(pctx, android.BuildParams{
1452 Rule: apexRule,
1453 Implicits: implicitInputs,
1454 Output: unsignedOutputFile,
1455 Description: "apex (" + apexType.name() + ")",
1456 Args: map[string]string{
1457 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1458 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1459 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001460 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001461 "file_contexts": fileContexts.String(),
1462 "canned_fs_config": cannedFsConfig.String(),
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001463 "key": a.private_key_file.String(),
Jiyong Park835d82b2018-12-27 16:04:18 +09001464 "opt_flags": strings.Join(optFlags, " "),
Alex Light5098a612018-11-29 17:12:15 -08001465 },
1466 })
1467
1468 apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix)
1469 bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip")
1470 a.bundleModuleFile = bundleModuleFile
1471
1472 ctx.Build(pctx, android.BuildParams{
1473 Rule: apexProtoConvertRule,
1474 Input: unsignedOutputFile,
1475 Output: apexProtoFile,
1476 Description: "apex proto convert",
1477 })
1478
1479 ctx.Build(pctx, android.BuildParams{
1480 Rule: apexBundleRule,
1481 Input: apexProtoFile,
1482 Output: a.bundleModuleFile,
1483 Description: "apex bundle module",
1484 Args: map[string]string{
1485 "abi": strings.Join(abis, "."),
1486 },
1487 })
1488 } else {
1489 ctx.Build(pctx, android.BuildParams{
1490 Rule: zipApexRule,
1491 Implicits: implicitInputs,
1492 Output: unsignedOutputFile,
1493 Description: "apex (" + apexType.name() + ")",
1494 Args: map[string]string{
1495 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
1496 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
1497 "copy_commands": strings.Join(copyCommands, " && "),
Jooyung Hane1633032019-08-01 17:41:43 +09001498 "manifest": a.manifestOut.String(),
Alex Light5098a612018-11-29 17:12:15 -08001499 },
1500 })
Colin Crossa4925902018-11-16 11:36:28 -08001501 }
Colin Crossa4925902018-11-16 11:36:28 -08001502
Alex Light5098a612018-11-29 17:12:15 -08001503 a.outputFiles[apexType] = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001504 ctx.Build(pctx, android.BuildParams{
1505 Rule: java.Signapk,
1506 Description: "signapk",
Alex Light5098a612018-11-29 17:12:15 -08001507 Output: a.outputFiles[apexType],
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001508 Input: unsignedOutputFile,
Dan Willemsendd651fa2019-06-13 04:48:54 +00001509 Implicits: []android.Path{
1510 a.container_certificate_file,
1511 a.container_private_key_file,
1512 },
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001513 Args: map[string]string{
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001514 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
Jiyong Parkbfe64a12018-11-22 02:51:54 +09001515 "flags": "-a 4096", //alignment
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001516 },
1517 })
Alex Light5098a612018-11-29 17:12:15 -08001518
1519 // Install to $OUT/soong/{target,host}/.../apex
Sundong Ahne8fb7242019-09-17 13:50:45 +09001520 if a.installable() && (!ctx.Config().FlattenApex() || apexType.zip()) && !a.isFlattenedVariant() {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001521 ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFiles[apexType])
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001522 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001523}
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001524
Jiyong Park8fd61922018-11-08 02:50:25 +09001525func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001526 if a.installable() {
Jiyong Park42cca6c2019-04-01 11:15:50 +09001527 // 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 +09001528 // with other ordinary files.
Jooyung Hane1633032019-08-01 17:41:43 +09001529 a.filesInfo = append(a.filesInfo, apexFile{a.manifestOut, ctx.ModuleName() + ".apex_manifest.json", ".", etc, nil, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +09001530
Jiyong Park42cca6c2019-04-01 11:15:50 +09001531 // rename to apex_pubkey
1532 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
1533 ctx.Build(pctx, android.BuildParams{
1534 Rule: android.Cp,
1535 Input: a.public_key_file,
1536 Output: copiedPubkey,
1537 })
1538 a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
1539
Jiyong Park23c52b02019-02-02 13:13:47 +09001540 if ctx.Config().FlattenApex() {
1541 for _, fi := range a.filesInfo {
1542 dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
Alex Lightf4857cf2019-02-22 13:00:04 -08001543 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
1544 for _, sym := range fi.symlinks {
1545 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
1546 }
Jiyong Park23c52b02019-02-02 13:13:47 +09001547 }
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001548 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001549 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001550}
1551
1552func (a *apexBundle) AndroidMk() android.AndroidMkData {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001553 if a.properties.HideFromMake {
1554 return android.AndroidMkData{
1555 Disabled: true,
1556 }
1557 }
Alex Light5098a612018-11-29 17:12:15 -08001558 writers := []android.AndroidMkData{}
1559 if a.apexTypes.image() {
1560 writers = append(writers, a.androidMkForType(imageApex))
1561 }
1562 if a.apexTypes.zip() {
1563 writers = append(writers, a.androidMkForType(zipApex))
1564 }
1565 return android.AndroidMkData{
1566 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1567 for _, data := range writers {
1568 data.Custom(w, name, prefix, moduleDir, data)
1569 }
1570 }}
1571}
1572
Alex Lightf1801bc2019-02-13 11:10:07 -08001573func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
Jiyong Park94427262019-02-05 23:18:47 +09001574 moduleNames := []string{}
1575
1576 for _, fi := range a.filesInfo {
1577 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
1578 continue
1579 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001580 if a.properties.Flattened && !apexType.image() {
1581 continue
Jiyong Park94427262019-02-05 23:18:47 +09001582 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001583
1584 var suffix string
Sundong Ahne8fb7242019-09-17 13:50:45 +09001585 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001586 suffix = ".flattened"
1587 }
1588
1589 if !android.InList(fi.moduleName, moduleNames) {
1590 moduleNames = append(moduleNames, fi.moduleName+suffix)
1591 }
1592
Jiyong Park94427262019-02-05 23:18:47 +09001593 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1594 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001595 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
Roland Levillain411c5842019-09-19 16:37:20 +01001596 // /apex/<apex_name>/{lib|framework|...}
Jiyong Park05e70dd2019-03-18 14:26:32 +09001597 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
1598 proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
Sundong Ahne9b55722019-09-06 17:37:42 +09001599 if a.properties.Flattened && apexType.image() {
Jiyong Park94427262019-02-05 23:18:47 +09001600 // /system/apex/<name>/{lib|framework|...}
1601 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
1602 a.installDir.RelPathString(), name, fi.installDir))
Sundong Ahne8fb7242019-09-17 13:50:45 +09001603 if !a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001604 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
1605 }
Alex Lightf4857cf2019-02-22 13:00:04 -08001606 if len(fi.symlinks) > 0 {
1607 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
1608 }
Jiyong Park52818fc2019-03-18 12:01:38 +09001609
1610 if fi.module != nil && fi.module.NoticeFile().Valid() {
1611 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
1612 }
Jiyong Park94427262019-02-05 23:18:47 +09001613 } else {
Jiyong Park05e70dd2019-03-18 14:26:32 +09001614 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park94427262019-02-05 23:18:47 +09001615 }
1616 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
1617 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
1618 if fi.module != nil {
1619 archStr := fi.module.Target().Arch.ArchType.String()
1620 host := false
1621 switch fi.module.Target().Os.Class {
1622 case android.Host:
1623 if archStr != "common" {
1624 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
1625 }
1626 host = true
1627 case android.HostCross:
1628 if archStr != "common" {
1629 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
1630 }
1631 host = true
1632 case android.Device:
1633 if archStr != "common" {
1634 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
1635 }
1636 }
1637 if host {
1638 makeOs := fi.module.Target().Os.String()
1639 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
1640 makeOs = "linux"
1641 }
1642 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
1643 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
1644 }
1645 }
1646 if fi.class == javaSharedLib {
1647 javaModule := fi.module.(*java.Library)
1648 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
1649 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
1650 // we will have foo.jar.jar
1651 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
1652 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
1653 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
1654 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
1655 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
1656 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Logan Chien0342c582019-09-10 09:08:24 -07001657 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
Jiyong Park94427262019-02-05 23:18:47 +09001658 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
Logan Chien41eabe62019-04-10 13:33:58 +08001659 if cc, ok := fi.module.(*cc.Module); ok {
1660 if cc.UnstrippedOutputFile() != nil {
1661 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
1662 }
1663 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001664 if cc.CoverageOutputFile().Valid() {
1665 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
1666 }
Jiyong Park94427262019-02-05 23:18:47 +09001667 }
1668 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
1669 } else {
1670 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
1671 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
1672 }
1673 }
1674 return moduleNames
1675}
1676
Alex Light5098a612018-11-29 17:12:15 -08001677func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkData {
Jiyong Park719b4462019-01-13 00:39:51 +09001678 return android.AndroidMkData{
1679 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
1680 moduleNames := []string{}
Jiyong Park94427262019-02-05 23:18:47 +09001681 if a.installable() {
Alex Lightf1801bc2019-02-13 11:10:07 -08001682 moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
Jiyong Park719b4462019-01-13 00:39:51 +09001683 }
1684
Sundong Ahne8fb7242019-09-17 13:50:45 +09001685 if a.isFlattenedVariant() {
Sundong Ahne9b55722019-09-06 17:37:42 +09001686 name = name + ".flattened"
1687 }
1688
1689 if a.properties.Flattened && apexType.image() {
Jiyong Park719b4462019-01-13 00:39:51 +09001690 // Only image APEXes can be flattened.
Jiyong Park8fd61922018-11-08 02:50:25 +09001691 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1692 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1693 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Jiyong Park94427262019-02-05 23:18:47 +09001694 if len(moduleNames) > 0 {
1695 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
1696 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001697 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Roland Levillain935639d2019-08-13 14:55:28 +01001698 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
1699
Sundong Ahne8fb7242019-09-17 13:50:45 +09001700 } else if !a.isFlattenedVariant() {
Alex Light5098a612018-11-29 17:12:15 -08001701 // zip-apex is the less common type so have the name refer to the image-apex
1702 // only and use {name}.zip if you want the zip-apex
1703 if apexType == zipApex && a.apexTypes == both {
1704 name = name + ".zip"
1705 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001706 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
1707 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
1708 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
1709 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
Alex Light5098a612018-11-29 17:12:15 -08001710 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
Jiyong Park8fd61922018-11-08 02:50:25 +09001711 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
Colin Cross189ff982019-01-02 22:32:27 -08001712 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001713 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jiyong Park94427262019-02-05 23:18:47 +09001714 if len(moduleNames) > 0 {
1715 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
1716 }
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001717 if len(a.externalDeps) > 0 {
1718 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
1719 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001720 if a.prebuiltFileToDelete != "" {
1721 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
1722 filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
1723 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001724 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Crossa4925902018-11-16 11:36:28 -08001725
Alex Light5098a612018-11-29 17:12:15 -08001726 if apexType == imageApex {
1727 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
1728 }
Jiyong Park719b4462019-01-13 00:39:51 +09001729 }
1730 }}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001731}
1732
Jooyung Han344d5432019-08-23 11:17:39 +09001733func newApexBundle() *apexBundle {
Alex Light5098a612018-11-29 17:12:15 -08001734 module := &apexBundle{
1735 outputFiles: map[apexPackaging]android.WritablePath{},
1736 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001737 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001738 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001739 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001740 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1741 })
Alex Light5098a612018-11-29 17:12:15 -08001742 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001743 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001744 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001745 return module
1746}
Jiyong Park30ca9372019-02-07 16:27:23 +09001747
Jooyung Han344d5432019-08-23 11:17:39 +09001748func ApexBundleFactory(testApex bool) android.Module {
1749 bundle := newApexBundle()
1750 bundle.testApex = testApex
1751 return bundle
1752}
1753
1754func testApexBundleFactory() android.Module {
1755 bundle := newApexBundle()
1756 bundle.testApex = true
1757 return bundle
1758}
1759
Jiyong Parkd1063c12019-07-17 20:08:41 +09001760func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001761 return newApexBundle()
1762}
1763
1764// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
1765// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
1766// If not specified, then the "current" versions are gathered.
1767func vndkApexBundleFactory() android.Module {
1768 bundle := newApexBundle()
1769 bundle.vndkApex = true
1770 bundle.AddProperties(&bundle.vndkProperties)
1771 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
1772 ctx.AppendProperties(&struct {
1773 Compile_multilib *string
1774 }{
1775 proptools.StringPtr("both"),
1776 })
1777 })
1778 return bundle
1779}
1780
Jiyong Park30ca9372019-02-07 16:27:23 +09001781//
1782// Defaults
1783//
1784type Defaults struct {
1785 android.ModuleBase
1786 android.DefaultsModuleBase
1787}
1788
Jiyong Park30ca9372019-02-07 16:27:23 +09001789func defaultsFactory() android.Module {
1790 return DefaultsFactory()
1791}
1792
1793func DefaultsFactory(props ...interface{}) android.Module {
1794 module := &Defaults{}
1795
1796 module.AddProperties(props...)
1797 module.AddProperties(
1798 &apexBundleProperties{},
1799 &apexTargetBundleProperties{},
1800 )
1801
1802 android.InitDefaultsModule(module)
1803 return module
1804}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001805
1806//
1807// Prebuilt APEX
1808//
1809type Prebuilt struct {
1810 android.ModuleBase
1811 prebuilt android.Prebuilt
1812
1813 properties PrebuiltProperties
1814
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001815 inputApex android.Path
1816 installDir android.OutputPath
1817 installFilename string
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001818 outputApex android.WritablePath
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001819}
1820
1821type PrebuiltProperties struct {
1822 // the path to the prebuilt .apex file to import.
Jiyong Park2cb52882019-07-07 12:39:16 +09001823 Source string `blueprint:"mutated"`
1824 ForceDisable bool `blueprint:"mutated"`
Jiyong Parkc95714e2019-03-29 14:23:10 +09001825
1826 Src *string
1827 Arch struct {
1828 Arm struct {
1829 Src *string
1830 }
1831 Arm64 struct {
1832 Src *string
1833 }
1834 X86 struct {
1835 Src *string
1836 }
1837 X86_64 struct {
1838 Src *string
1839 }
1840 }
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001841
1842 Installable *bool
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001843 // Optional name for the installed apex. If unspecified, name of the
1844 // module is used as the file name
1845 Filename *string
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001846
1847 // Names of modules to be overridden. Listed modules can only be other binaries
1848 // (in Make or Soong).
1849 // This does not completely prevent installation of the overridden binaries, but if both
1850 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1851 // from PRODUCT_PACKAGES.
1852 Overrides []string
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001853}
1854
1855func (p *Prebuilt) installable() bool {
1856 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001857}
1858
1859func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +09001860 // If the device is configured to use flattened APEX, force disable the prebuilt because
1861 // the prebuilt is a non-flattened one.
1862 forceDisable := ctx.Config().FlattenApex()
1863
1864 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
1865 // to build the prebuilts themselves.
Jiyong Parkca8992e2019-07-17 08:21:36 +09001866 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
Jiyong Park50b81e52019-07-11 11:24:41 +09001867
Kun Niu10c9f832019-07-29 16:28:57 -07001868 // Force disable the prebuilts when coverage is enabled.
1869 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
1870 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
1871
Jiyong Park50b81e52019-07-11 11:24:41 +09001872 // b/137216042 don't use prebuilts when address sanitizer is on
1873 forceDisable = forceDisable || android.InList("address", ctx.Config().SanitizeDevice()) ||
1874 android.InList("hwaddress", ctx.Config().SanitizeDevice())
1875
1876 if forceDisable && p.prebuilt.SourceExists() {
Jiyong Park2cb52882019-07-07 12:39:16 +09001877 p.properties.ForceDisable = true
1878 return
1879 }
1880
Jiyong Parkc95714e2019-03-29 14:23:10 +09001881 // This is called before prebuilt_select and prebuilt_postdeps mutators
1882 // The mutators requires that src to be set correctly for each arch so that
1883 // arch variants are disabled when src is not provided for the arch.
1884 if len(ctx.MultiTargets()) != 1 {
1885 ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
1886 return
1887 }
1888 var src string
1889 switch ctx.MultiTargets()[0].Arch.ArchType {
1890 case android.Arm:
1891 src = String(p.properties.Arch.Arm.Src)
1892 case android.Arm64:
1893 src = String(p.properties.Arch.Arm64.Src)
1894 case android.X86:
1895 src = String(p.properties.Arch.X86.Src)
1896 case android.X86_64:
1897 src = String(p.properties.Arch.X86_64.Src)
1898 default:
1899 ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
1900 return
1901 }
1902 if src == "" {
1903 src = String(p.properties.Src)
1904 }
1905 p.properties.Source = src
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001906}
1907
Jiyong Park03b68dd2019-07-26 23:20:40 +09001908func (p *Prebuilt) isForceDisabled() bool {
1909 return p.properties.ForceDisable
1910}
1911
Colin Cross41955e82019-05-29 14:40:35 -07001912func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
1913 switch tag {
1914 case "":
1915 return android.Paths{p.outputApex}, nil
1916 default:
1917 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1918 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001919}
1920
Jiyong Park4d277042019-04-23 18:00:10 +09001921func (p *Prebuilt) InstallFilename() string {
1922 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
1923}
1924
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001925func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park2cb52882019-07-07 12:39:16 +09001926 if p.properties.ForceDisable {
1927 return
1928 }
1929
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001930 // TODO(jungjw): Check the key validity.
Jiyong Parkc95714e2019-03-29 14:23:10 +09001931 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001932 p.installDir = android.PathForModuleInstall(ctx, "apex")
Jiyong Park4d277042019-04-23 18:00:10 +09001933 p.installFilename = p.InstallFilename()
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001934 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
1935 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
1936 }
Nikita Ioffe89ecd592019-04-05 02:10:45 +01001937 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
1938 ctx.Build(pctx, android.BuildParams{
1939 Rule: android.Cp,
1940 Input: p.inputApex,
1941 Output: p.outputApex,
1942 })
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001943 if p.installable() {
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001944 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
Nikita Ioffedd53e8b2019-04-04 13:42:00 +01001945 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001946}
1947
1948func (p *Prebuilt) Prebuilt() *android.Prebuilt {
1949 return &p.prebuilt
1950}
1951
1952func (p *Prebuilt) Name() string {
1953 return p.prebuilt.Name(p.ModuleBase.Name())
1954}
1955
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001956func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
1957 return android.AndroidMkEntries{
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001958 Class: "ETC",
1959 OutputFile: android.OptionalPathForPath(p.inputApex),
1960 Include: "$(BUILD_PREBUILT)",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -07001961 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
1962 func(entries *android.AndroidMkEntries) {
1963 entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
1964 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
1965 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
1966 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
1967 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001968 },
1969 }
1970}
1971
1972// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
1973func PrebuiltFactory() android.Module {
1974 module := &Prebuilt{}
1975 module.AddProperties(&module.properties)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001976 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
Jiyong Parkc95714e2019-03-29 14:23:10 +09001977 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001978 return module
1979}