blob: aef76facbc277b581999c03164cbadad8db527d6 [file] [log] [blame]
Jiyong Park09d77522019-11-18 11:16:27 +09001// Copyright (C) 2019 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 "path/filepath"
20 "runtime"
21 "sort"
22 "strings"
23
24 "android/soong/android"
25 "android/soong/java"
26
27 "github.com/google/blueprint"
28 "github.com/google/blueprint/proptools"
29)
30
31var (
32 pctx = android.NewPackageContext("android/apex")
33)
34
35func init() {
36 pctx.Import("android/soong/android")
37 pctx.Import("android/soong/java")
38 pctx.HostBinToolVariable("apexer", "apexer")
39 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
40 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
41 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
42 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
43 if !ctx.Config().FrameworksBaseDirExists(ctx) {
44 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
45 } else {
46 return pctx.HostBinToolPath(ctx, tool).String()
47 }
48 })
49 }
50 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
51 pctx.HostBinToolVariable("avbtool", "avbtool")
52 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
53 pctx.HostBinToolVariable("merge_zips", "merge_zips")
54 pctx.HostBinToolVariable("mke2fs", "mke2fs")
55 pctx.HostBinToolVariable("resize2fs", "resize2fs")
56 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
57 pctx.HostBinToolVariable("soong_zip", "soong_zip")
58 pctx.HostBinToolVariable("zip2zip", "zip2zip")
59 pctx.HostBinToolVariable("zipalign", "zipalign")
60 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
61 pctx.HostBinToolVariable("conv_apex_manifest", "conv_apex_manifest")
62}
63
64var (
65 // Create a canned fs config file where all files and directories are
66 // by default set to (uid/gid/mode) = (1000/1000/0644)
67 // TODO(b/113082813) make this configurable using config.fs syntax
68 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
69 Command: `echo '/ 1000 1000 0755' > ${out} && ` +
70 `echo ${ro_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 1000 1000 0644"}' >> ${out} && ` +
71 `echo ${exec_paths} | tr ' ' '\n' | awk '{print "/"$$1 " 0 2000 0755"}' >> ${out}`,
72 Description: "fs_config ${out}",
73 }, "ro_paths", "exec_paths")
74
75 apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
76 Command: `rm -f $out && ${jsonmodify} $in ` +
77 `-a provideNativeLibs ${provideNativeLibs} ` +
78 `-a requireNativeLibs ${requireNativeLibs} ` +
79 `${opt} ` +
80 `-o $out`,
81 CommandDeps: []string{"${jsonmodify}"},
82 Description: "prepare ${out}",
83 }, "provideNativeLibs", "requireNativeLibs", "opt")
84
85 stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{
86 Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`,
87 CommandDeps: []string{"${conv_apex_manifest}"},
88 Description: "strip ${in}=>${out}",
89 })
90
91 pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{
92 Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`,
93 CommandDeps: []string{"${conv_apex_manifest}"},
94 Description: "convert ${in}=>${out}",
95 })
96
97 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
98 // against the binary policy using sefcontext_compiler -p <policy>.
99
100 // TODO(b/114327326): automate the generation of file_contexts
101 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
102 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
103 `(. ${out}.copy_commands) && ` +
104 `APEXER_TOOL_PATH=${tool_path} ` +
105 `${apexer} --force --manifest ${manifest} ` +
106 `--manifest_json ${manifest_json} --manifest_json_full ${manifest_json_full} ` +
107 `--file_contexts ${file_contexts} ` +
108 `--canned_fs_config ${canned_fs_config} ` +
109 `--payload_type image ` +
110 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
111 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
112 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
113 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
114 Rspfile: "${out}.copy_commands",
115 RspfileContent: "${copy_commands}",
116 Description: "APEX ${image_dir} => ${out}",
117 }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags",
118 "manifest", "manifest_json", "manifest_json_full",
119 )
120
121 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
122 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
123 `(. ${out}.copy_commands) && ` +
124 `APEXER_TOOL_PATH=${tool_path} ` +
125 `${apexer} --force --manifest ${manifest} --manifest_json_full ${manifest_json_full} ` +
126 `--payload_type zip ` +
127 `${image_dir} ${out} `,
128 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
129 Rspfile: "${out}.copy_commands",
130 RspfileContent: "${copy_commands}",
131 Description: "ZipAPEX ${image_dir} => ${out}",
132 }, "tool_path", "image_dir", "copy_commands", "manifest", "manifest_json_full")
133
134 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
135 blueprint.RuleParams{
136 Command: `${aapt2} convert --output-format proto $in -o $out`,
137 CommandDeps: []string{"${aapt2}"},
138 })
139
140 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
141 Command: `${zip2zip} -i $in -o $out ` +
142 `apex_payload.img:apex/${abi}.img ` +
143 `apex_manifest.json:root/apex_manifest.json ` +
Jiyong Park53ae3342019-12-08 02:06:24 +0900144 `apex_pubkey:root/apex_pubkey ` +
145 `apex_manifest.pb:root/apex_manifest.pb ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900146 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
147 `assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
148 CommandDeps: []string{"${zip2zip}"},
149 Description: "app bundle",
150 }, "abi")
151
152 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
153 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
154 Rspfile: "${out}.emit_commands",
155 RspfileContent: "${emit_commands}",
156 Description: "Emit APEX image content",
157 }, "emit_commands")
158
159 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
160 Command: `diff --unchanged-group-format='' \` +
161 `--changed-group-format='%<' \` +
162 `${image_content_file} ${whitelisted_files_file} || (` +
163 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
164 ` "To fix the build run following command:" && ` +
165 `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
166 `exit 1)`,
167 Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
168 }, "image_content_file", "whitelisted_files_file", "apex_module_name")
169)
170
171func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) {
172 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
173
174 a.manifestJsonFullOut = android.PathForModuleOut(ctx, "apex_manifest_full.json")
175
176 // put dependency({provide|require}NativeLibs) in apex_manifest.json
177 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
178 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
179
180 // apex name can be overridden
181 optCommands := []string{}
182 if a.properties.Apex_name != nil {
183 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
184 }
185
186 ctx.Build(pctx, android.BuildParams{
187 Rule: apexManifestRule,
188 Input: manifestSrc,
189 Output: a.manifestJsonFullOut,
190 Args: map[string]string{
191 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
192 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
193 "opt": strings.Join(optCommands, " "),
194 },
195 })
196
197 // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json
198 // prepare stripped-down version so that APEX modules built from R+ can be installed to Q
199 a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json")
200 ctx.Build(pctx, android.BuildParams{
201 Rule: stripApexManifestRule,
202 Input: a.manifestJsonFullOut,
203 Output: a.manifestJsonOut,
204 })
205
206 // from R+, protobuf binary format (.pb) is the standard format for apex_manifest
207 a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb")
208 ctx.Build(pctx, android.BuildParams{
209 Rule: pbApexManifestRule,
210 Input: a.manifestJsonFullOut,
211 Output: a.manifestPbOut,
212 })
213}
214
215func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName string) android.OptionalPath {
216 noticeFiles := []android.Path{}
217 for _, f := range a.filesInfo {
218 if f.module != nil {
219 notice := f.module.NoticeFile()
220 if notice.Valid() {
221 noticeFiles = append(noticeFiles, notice.Path())
222 }
223 }
224 }
225 // append the notice file specified in the apex module itself
226 if a.NoticeFile().Valid() {
227 noticeFiles = append(noticeFiles, a.NoticeFile().Path())
228 }
229
230 if len(noticeFiles) == 0 {
231 return android.OptionalPath{}
232 }
233
234 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput
235}
236
237func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
238 var abis []string
239 for _, target := range ctx.MultiTargets() {
240 if len(target.Arch.Abi) > 0 {
241 abis = append(abis, target.Arch.Abi[0])
242 }
243 }
244
245 abis = android.FirstUniqueStrings(abis)
246
247 apexType := a.properties.ApexType
248 suffix := apexType.suffix()
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800249 unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
Jiyong Park09d77522019-11-18 11:16:27 +0900250
251 filesToCopy := []android.Path{}
252 for _, f := range a.filesInfo {
253 filesToCopy = append(filesToCopy, f.builtFile)
254 }
255
256 copyCommands := []string{}
257 emitCommands := []string{}
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800258 imageContentFile := android.PathForModuleOut(ctx, a.Name()+"-content.txt")
Jiyong Park09d77522019-11-18 11:16:27 +0900259 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
260 for i, src := range filesToCopy {
261 dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
262 emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
263 dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
264 copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
265 copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
266 for _, sym := range a.filesInfo[i].symlinks {
267 symlinkDest := filepath.Join(filepath.Dir(dest_path), sym)
268 copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
269 }
270 }
271 emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
272
273 implicitInputs := append(android.Paths(nil), filesToCopy...)
274 implicitInputs = append(implicitInputs, a.manifestPbOut, a.manifestJsonFullOut, a.manifestJsonOut)
275
276 if a.properties.Whitelisted_files != nil {
277 ctx.Build(pctx, android.BuildParams{
278 Rule: emitApexContentRule,
279 Implicits: implicitInputs,
280 Output: imageContentFile,
281 Description: "emit apex image content",
282 Args: map[string]string{
283 "emit_commands": strings.Join(emitCommands, " && "),
284 },
285 })
286 implicitInputs = append(implicitInputs, imageContentFile)
287 whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
288
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800289 phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
Jiyong Park09d77522019-11-18 11:16:27 +0900290 ctx.Build(pctx, android.BuildParams{
291 Rule: diffApexContentRule,
292 Implicits: implicitInputs,
293 Output: phonyOutput,
294 Description: "diff apex image content",
295 Args: map[string]string{
296 "whitelisted_files_file": whitelistedFilesFile.String(),
297 "image_content_file": imageContentFile.String(),
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800298 "apex_module_name": a.Name(),
Jiyong Park09d77522019-11-18 11:16:27 +0900299 },
300 })
301
302 implicitInputs = append(implicitInputs, phonyOutput)
303 }
304
305 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
306 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
307
308 if apexType == imageApex {
309 // files and dirs that will be created in APEX
310 var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
311 var executablePaths []string // this also includes dirs
312 for _, f := range a.filesInfo {
313 pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
314 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
315 executablePaths = append(executablePaths, pathInApex)
316 for _, s := range f.symlinks {
317 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
318 }
319 } else {
320 readOnlyPaths = append(readOnlyPaths, pathInApex)
321 }
322 dir := f.installDir
323 for !android.InList(dir, executablePaths) && dir != "" {
324 executablePaths = append(executablePaths, dir)
325 dir, _ = filepath.Split(dir) // move up to the parent
326 if len(dir) > 0 {
327 // remove trailing slash
328 dir = dir[:len(dir)-1]
329 }
330 }
331 }
332 sort.Strings(readOnlyPaths)
333 sort.Strings(executablePaths)
334 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
335 ctx.Build(pctx, android.BuildParams{
336 Rule: generateFsConfig,
337 Output: cannedFsConfig,
338 Description: "generate fs config",
339 Args: map[string]string{
340 "ro_paths": strings.Join(readOnlyPaths, " "),
341 "exec_paths": strings.Join(executablePaths, " "),
342 },
343 })
344
Jiyong Park09d77522019-11-18 11:16:27 +0900345 optFlags := []string{}
346
347 // Additional implicit inputs.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900348 implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file)
Jiyong Park09d77522019-11-18 11:16:27 +0900349 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
350
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800351 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(a.Name())
Jiyong Park09d77522019-11-18 11:16:27 +0900352 if overridden {
353 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
354 }
355
356 if a.properties.AndroidManifest != nil {
357 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
358 implicitInputs = append(implicitInputs, androidManifestFile)
359 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
360 }
361
362 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
363 if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
364 ctx.Config().UnbundledBuild() &&
365 !ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
366 ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
367 apiFingerprint := java.ApiFingerprintPath(ctx)
368 targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
369 implicitInputs = append(implicitInputs, apiFingerprint)
370 }
371 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
372
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800373 noticeFile := a.buildNoticeFile(ctx, a.Name()+suffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900374 if noticeFile.Valid() {
375 // If there's a NOTICE file, embed it as an asset file in the APEX.
376 implicitInputs = append(implicitInputs, noticeFile.Path())
377 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
378 }
379
380 if !ctx.Config().UnbundledBuild() && a.installable() {
381 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
382 // don't need hashtree for activation. Therefore, by removing hashtree from
383 // apex bundle (filesystem image in it, to be specific), we can save storage.
384 optFlags = append(optFlags, "--no_hashtree")
385 }
386
387 if a.properties.Apex_name != nil {
388 // If apex_name is set, apexer can skip checking if key name matches with apex name.
389 // Note that apex_manifest is also mended.
390 optFlags = append(optFlags, "--do_not_check_keyname")
391 }
392
393 ctx.Build(pctx, android.BuildParams{
394 Rule: apexRule,
395 Implicits: implicitInputs,
396 Output: unsignedOutputFile,
397 Description: "apex (" + apexType.name() + ")",
398 Args: map[string]string{
399 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
400 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
401 "copy_commands": strings.Join(copyCommands, " && "),
402 "manifest_json_full": a.manifestJsonFullOut.String(),
403 "manifest_json": a.manifestJsonOut.String(),
404 "manifest": a.manifestPbOut.String(),
Jooyung Han54aca7b2019-11-20 02:26:02 +0900405 "file_contexts": a.fileContexts.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900406 "canned_fs_config": cannedFsConfig.String(),
407 "key": a.private_key_file.String(),
408 "opt_flags": strings.Join(optFlags, " "),
409 },
410 })
411
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800412 apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix)
413 bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip")
Jiyong Park09d77522019-11-18 11:16:27 +0900414 a.bundleModuleFile = bundleModuleFile
415
416 ctx.Build(pctx, android.BuildParams{
417 Rule: apexProtoConvertRule,
418 Input: unsignedOutputFile,
419 Output: apexProtoFile,
420 Description: "apex proto convert",
421 })
422
423 ctx.Build(pctx, android.BuildParams{
424 Rule: apexBundleRule,
425 Input: apexProtoFile,
426 Output: a.bundleModuleFile,
427 Description: "apex bundle module",
428 Args: map[string]string{
429 "abi": strings.Join(abis, "."),
430 },
431 })
432 } else {
433 ctx.Build(pctx, android.BuildParams{
434 Rule: zipApexRule,
435 Implicits: implicitInputs,
436 Output: unsignedOutputFile,
437 Description: "apex (" + apexType.name() + ")",
438 Args: map[string]string{
439 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
440 "image_dir": android.PathForModuleOut(ctx, "image"+suffix).String(),
441 "copy_commands": strings.Join(copyCommands, " && "),
442 "manifest": a.manifestPbOut.String(),
443 "manifest_json_full": a.manifestJsonFullOut.String(),
444 },
445 })
446 }
447
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800448 a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900449 ctx.Build(pctx, android.BuildParams{
450 Rule: java.Signapk,
451 Description: "signapk",
452 Output: a.outputFile,
453 Input: unsignedOutputFile,
454 Implicits: []android.Path{
455 a.container_certificate_file,
456 a.container_private_key_file,
457 },
458 Args: map[string]string{
459 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
460 "flags": "-a 4096", //alignment
461 },
462 })
463
464 // Install to $OUT/soong/{target,host}/.../apex
465 if a.installable() {
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800466 ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900467 }
468 a.buildFilesInfo(ctx)
469}
470
471func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
472 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
473 // reply true to `InstallBypassMake()` (thus making the call
474 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
475 // instead of `android.PathForOutput`) to return the correct path to the flattened
476 // APEX (as its contents is installed by Make, not Soong).
477 factx := flattenedApexContext{ctx}
478 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
479 a.outputFile = android.PathForModuleInstall(&factx, "apex", apexName)
480
Jiyong Park317645e2019-12-05 13:20:58 +0900481 if a.installable() && a.GetOverriddenBy() == "" {
Jooyung Han54aca7b2019-11-20 02:26:02 +0900482 installPath := android.PathForModuleInstall(ctx, "apex", apexName)
483 devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
484 addFlattenedFileContextsInfos(ctx, apexName+":"+devicePath+":"+a.fileContexts.String())
485 }
Jiyong Park09d77522019-11-18 11:16:27 +0900486 a.buildFilesInfo(ctx)
487}
488
489func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) {
490 cert := String(a.properties.Certificate)
491 if cert != "" && android.SrcIsModule(cert) == "" {
492 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
493 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
494 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
495 } else if cert == "" {
496 pem, key := ctx.Config().DefaultAppCertificate(ctx)
497 a.container_certificate_file = pem
498 a.container_private_key_file = key
499 }
500}
501
502func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) {
503 if a.installable() {
504 // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along
505 // with other ordinary files.
Jiyong Parkf653b052019-11-18 15:39:01 +0900506 a.filesInfo = append(a.filesInfo, newApexFile(a.manifestJsonOut, "apex_manifest.json."+a.Name()+a.suffix, ".", etc, nil))
507 a.filesInfo = append(a.filesInfo, newApexFile(a.manifestPbOut, "apex_manifest.pb."+a.Name()+a.suffix, ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900508
509 // rename to apex_pubkey
510 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
511 ctx.Build(pctx, android.BuildParams{
512 Rule: android.Cp,
513 Input: a.public_key_file,
514 Output: copiedPubkey,
515 })
Jiyong Parkf653b052019-11-18 15:39:01 +0900516 a.filesInfo = append(a.filesInfo, newApexFile(copiedPubkey, "apex_pubkey."+a.Name()+a.suffix, ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900517
518 if a.properties.ApexType == flattenedApex {
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800519 apexName := proptools.StringDefault(a.properties.Apex_name, a.Name())
Jiyong Park09d77522019-11-18 11:16:27 +0900520 for _, fi := range a.filesInfo {
521 dir := filepath.Join("apex", apexName, fi.installDir)
522 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
523 for _, sym := range fi.symlinks {
524 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
525 }
526 }
527 }
528 }
529}