blob: b835379fbcda04588748d2dda0287b245846171a [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 (
Jiyong Parkbd159612020-02-28 15:22:21 +090018 "encoding/json"
Jiyong Park09d77522019-11-18 11:16:27 +090019 "fmt"
Jooyung Han580eb4f2020-06-24 19:33:06 +090020 "path"
Jiyong Park09d77522019-11-18 11:16:27 +090021 "path/filepath"
22 "runtime"
23 "sort"
Jooyung Han5417f772020-03-12 18:37:20 +090024 "strconv"
Jiyong Park09d77522019-11-18 11:16:27 +090025 "strings"
26
27 "android/soong/android"
28 "android/soong/java"
29
30 "github.com/google/blueprint"
31 "github.com/google/blueprint/proptools"
32)
33
34var (
35 pctx = android.NewPackageContext("android/apex")
36)
37
38func init() {
39 pctx.Import("android/soong/android")
40 pctx.Import("android/soong/java")
41 pctx.HostBinToolVariable("apexer", "apexer")
42 // ART minimal builds (using the master-art manifest) do not have the "frameworks/base"
43 // projects, and hence cannot built 'aapt2'. Use the SDK prebuilt instead.
44 hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
45 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
46 if !ctx.Config().FrameworksBaseDirExists(ctx) {
47 return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
48 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +000049 return ctx.Config().HostToolPath(ctx, tool).String()
Jiyong Park09d77522019-11-18 11:16:27 +090050 }
51 })
52 }
53 hostBinToolVariableWithPrebuilt("aapt2", "prebuilts/sdk/tools", "aapt2")
54 pctx.HostBinToolVariable("avbtool", "avbtool")
55 pctx.HostBinToolVariable("e2fsdroid", "e2fsdroid")
56 pctx.HostBinToolVariable("merge_zips", "merge_zips")
57 pctx.HostBinToolVariable("mke2fs", "mke2fs")
58 pctx.HostBinToolVariable("resize2fs", "resize2fs")
59 pctx.HostBinToolVariable("sefcontext_compile", "sefcontext_compile")
60 pctx.HostBinToolVariable("soong_zip", "soong_zip")
61 pctx.HostBinToolVariable("zip2zip", "zip2zip")
62 pctx.HostBinToolVariable("zipalign", "zipalign")
63 pctx.HostBinToolVariable("jsonmodify", "jsonmodify")
64 pctx.HostBinToolVariable("conv_apex_manifest", "conv_apex_manifest")
Jaewoong Jungfa00c062020-05-14 14:15:24 -070065 pctx.HostBinToolVariable("extract_apks", "extract_apks")
Theotime Combes4ba38c12020-06-12 12:46:59 +000066 pctx.HostBinToolVariable("make_f2fs", "make_f2fs")
67 pctx.HostBinToolVariable("sload_f2fs", "sload_f2fs")
Jiyong Park09d77522019-11-18 11:16:27 +090068}
69
70var (
71 // Create a canned fs config file where all files and directories are
72 // by default set to (uid/gid/mode) = (1000/1000/0644)
73 // TODO(b/113082813) make this configurable using config.fs syntax
74 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Sasha Smundak18d98bc2020-05-27 16:36:07 -070075 Command: `( echo '/ 1000 1000 0755' ` +
76 `&& for i in ${ro_paths}; do echo "/$$i 1000 1000 0644"; done ` +
77 `&& for i in ${exec_paths}; do echo "/$$i 0 2000 0755"; done ` +
78 `&& ( tr ' ' '\n' <${out}.apklist | for i in ${apk_paths}; do read apk; echo "/$$i 0 2000 0755"; zipinfo -1 $$apk | sed "s:\(.*\):/$$i/\1 1000 1000 0644:"; done ) ) > ${out}`,
79 Description: "fs_config ${out}",
80 Rspfile: "$out.apklist",
81 RspfileContent: "$in",
82 }, "ro_paths", "exec_paths", "apk_paths")
Jiyong Park09d77522019-11-18 11:16:27 +090083
84 apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
85 Command: `rm -f $out && ${jsonmodify} $in ` +
86 `-a provideNativeLibs ${provideNativeLibs} ` +
87 `-a requireNativeLibs ${requireNativeLibs} ` +
88 `${opt} ` +
89 `-o $out`,
90 CommandDeps: []string{"${jsonmodify}"},
91 Description: "prepare ${out}",
92 }, "provideNativeLibs", "requireNativeLibs", "opt")
93
94 stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{
95 Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`,
96 CommandDeps: []string{"${conv_apex_manifest}"},
97 Description: "strip ${in}=>${out}",
98 })
99
100 pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{
101 Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`,
102 CommandDeps: []string{"${conv_apex_manifest}"},
103 Description: "convert ${in}=>${out}",
104 })
105
106 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
107 // against the binary policy using sefcontext_compiler -p <policy>.
108
109 // TODO(b/114327326): automate the generation of file_contexts
110 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
111 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
112 `(. ${out}.copy_commands) && ` +
113 `APEXER_TOOL_PATH=${tool_path} ` +
114 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900115 `--file_contexts ${file_contexts} ` +
116 `--canned_fs_config ${canned_fs_config} ` +
Dario Freni0f4ae072020-01-02 15:24:12 +0000117 `--include_build_info ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900118 `--payload_type image ` +
119 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
120 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
Theotime Combes4ba38c12020-06-12 12:46:59 +0000121 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}",
Jiyong Park09d77522019-11-18 11:16:27 +0900122 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
123 Rspfile: "${out}.copy_commands",
124 RspfileContent: "${copy_commands}",
125 Description: "APEX ${image_dir} => ${out}",
Theotime Combes4ba38c12020-06-12 12:46:59 +0000126 }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type")
Jiyong Park09d77522019-11-18 11:16:27 +0900127
128 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
129 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
130 `(. ${out}.copy_commands) && ` +
131 `APEXER_TOOL_PATH=${tool_path} ` +
Jooyung Han214bf372019-11-12 13:03:50 +0900132 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900133 `--payload_type zip ` +
134 `${image_dir} ${out} `,
135 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
136 Rspfile: "${out}.copy_commands",
137 RspfileContent: "${copy_commands}",
138 Description: "ZipAPEX ${image_dir} => ${out}",
Jooyung Han214bf372019-11-12 13:03:50 +0900139 }, "tool_path", "image_dir", "copy_commands", "manifest")
Jiyong Park09d77522019-11-18 11:16:27 +0900140
141 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
142 blueprint.RuleParams{
143 Command: `${aapt2} convert --output-format proto $in -o $out`,
144 CommandDeps: []string{"${aapt2}"},
145 })
146
147 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Parkbd159612020-02-28 15:22:21 +0900148 Command: `${zip2zip} -i $in -o $out.base ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900149 `apex_payload.img:apex/${abi}.img ` +
Dario Frenida1aefe2020-03-02 21:47:09 +0000150 `apex_build_info.pb:apex/${abi}.build_info.pb ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900151 `apex_manifest.json:root/apex_manifest.json ` +
Jiyong Park53ae3342019-12-08 02:06:24 +0900152 `apex_manifest.pb:root/apex_manifest.pb ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900153 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
Jiyong Parkbd159612020-02-28 15:22:21 +0900154 `assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` +
155 `${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` +
156 `${merge_zips} $out $out.base $out.config`,
157 CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"},
Jiyong Park09d77522019-11-18 11:16:27 +0900158 Description: "app bundle",
Jiyong Parkbd159612020-02-28 15:22:21 +0900159 }, "abi", "config")
Jiyong Park09d77522019-11-18 11:16:27 +0900160
161 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
162 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
163 Rspfile: "${out}.emit_commands",
164 RspfileContent: "${emit_commands}",
165 Description: "Emit APEX image content",
166 }, "emit_commands")
167
168 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
169 Command: `diff --unchanged-group-format='' \` +
170 `--changed-group-format='%<' \` +
Colin Cross440e0d02020-06-11 11:32:11 -0700171 `${image_content_file} ${allowed_files_file} || (` +
Jiyong Park09d77522019-11-18 11:16:27 +0900172 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
173 ` "To fix the build run following command:" && ` +
Colin Cross440e0d02020-06-11 11:32:11 -0700174 `echo "system/apex/tools/update_allowed_list.sh ${allowed_files_file} ${image_content_file}" && ` +
Dan Willemsen81e43c52020-01-28 15:40:19 -0800175 `exit 1); touch ${out}`,
Colin Cross440e0d02020-06-11 11:32:11 -0700176 Description: "Diff ${image_content_file} and ${allowed_files_file}",
177 }, "image_content_file", "allowed_files_file", "apex_module_name")
Jiyong Park09d77522019-11-18 11:16:27 +0900178)
179
180func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) {
181 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
182
Jooyung Han214bf372019-11-12 13:03:50 +0900183 manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json")
Jiyong Park09d77522019-11-18 11:16:27 +0900184
185 // put dependency({provide|require}NativeLibs) in apex_manifest.json
186 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
187 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
188
189 // apex name can be overridden
190 optCommands := []string{}
191 if a.properties.Apex_name != nil {
192 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
193 }
194
Jooyung Han643adc42020-02-27 13:50:06 +0900195 // collect jniLibs. Notice that a.filesInfo is already sorted
196 var jniLibs []string
197 for _, fi := range a.filesInfo {
Jooyung Hanb9007602020-08-28 16:29:27 +0900198 if fi.isJniLib && !android.InList(fi.Stem(), jniLibs) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900199 jniLibs = append(jniLibs, fi.Stem())
Jooyung Han643adc42020-02-27 13:50:06 +0900200 }
201 }
202 if len(jniLibs) > 0 {
203 optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " "))
204 }
205
Jiyong Park09d77522019-11-18 11:16:27 +0900206 ctx.Build(pctx, android.BuildParams{
207 Rule: apexManifestRule,
208 Input: manifestSrc,
Jooyung Han214bf372019-11-12 13:03:50 +0900209 Output: manifestJsonFullOut,
Jiyong Park09d77522019-11-18 11:16:27 +0900210 Args: map[string]string{
211 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
212 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
213 "opt": strings.Join(optCommands, " "),
214 },
215 })
216
Jooyung Han5417f772020-03-12 18:37:20 +0900217 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900218 // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json
219 // prepare stripped-down version so that APEX modules built from R+ can be installed to Q
220 a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json")
221 ctx.Build(pctx, android.BuildParams{
222 Rule: stripApexManifestRule,
223 Input: manifestJsonFullOut,
224 Output: a.manifestJsonOut,
225 })
226 }
Jiyong Park09d77522019-11-18 11:16:27 +0900227
228 // from R+, protobuf binary format (.pb) is the standard format for apex_manifest
229 a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb")
230 ctx.Build(pctx, android.BuildParams{
231 Rule: pbApexManifestRule,
Jooyung Han214bf372019-11-12 13:03:50 +0900232 Input: manifestJsonFullOut,
Jiyong Park09d77522019-11-18 11:16:27 +0900233 Output: a.manifestPbOut,
234 })
235}
236
Jooyung Han580eb4f2020-06-24 19:33:06 +0900237func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) {
238 if a.properties.ApexType == zipApex {
239 return
240 }
241 var fileContexts android.Path
242 if a.properties.File_contexts == nil {
243 fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
244 } else {
245 fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
246 }
247 if a.Platform() {
248 if matched, err := path.Match("system/sepolicy/**/*", fileContexts.String()); err != nil || !matched {
249 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", fileContexts)
250 return
251 }
252 }
253 if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() {
254 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
255 return
256 }
257
258 output := android.PathForModuleOut(ctx, "file_contexts")
259 rule := android.NewRuleBuilder()
Jooyung Han7f146c02020-09-23 19:15:55 +0900260
261 if a.properties.ApexType == imageApex {
262 // remove old file
263 rule.Command().Text("rm").FlagWithOutput("-f ", output)
264 // copy file_contexts
265 rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output)
266 // new line
267 rule.Command().Text("echo").Text(">>").Output(output)
268 // force-label /apex_manifest.pb and / as system_file so that apexd can read them
269 rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output)
270 rule.Command().Text("echo").Flag("/ u:object_r:system_file:s0").Text(">>").Output(output)
271 } else {
272 // For flattened apexes, install path should be prepended.
273 // File_contexts file should be emiited to make via LOCAL_FILE_CONTEXTS
274 // so that it can be merged into file_contexts.bin
275 apexPath := android.InstallPathToOnDevicePath(ctx, a.installDir.Join(ctx, a.Name()))
276 apexPath = strings.ReplaceAll(apexPath, ".", `\\.`)
277 // remove old file
278 rule.Command().Text("rm").FlagWithOutput("-f ", output)
279 // copy file_contexts
280 rule.Command().Text("awk").Text(`'/object_r/{printf("` + apexPath + `%s\n", $0)}'`).Input(fileContexts).Text(">").Output(output)
281 // new line
282 rule.Command().Text("echo").Text(">>").Output(output)
283 // force-label /apex_manifest.pb and / as system_file so that apexd can read them
284 rule.Command().Text("echo").Flag(apexPath + `/apex_manifest\\.pb u:object_r:system_file:s0`).Text(">>").Output(output)
285 rule.Command().Text("echo").Flag(apexPath + "/ u:object_r:system_file:s0").Text(">>").Output(output)
286 }
287
Jooyung Han580eb4f2020-06-24 19:33:06 +0900288 rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts")
289
290 a.fileContexts = output.OutputPath
291}
292
Jiyong Park19972c72020-01-28 20:05:29 +0900293func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs {
Jiyong Park9918e1a2020-03-17 19:16:40 +0900294 var noticeFiles android.Paths
295
Jooyung Han749dc692020-04-15 11:03:39 +0900296 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park9918e1a2020-03-17 19:16:40 +0900297 if externalDep {
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100298 // As soon as the dependency graph crosses the APEX boundary, don't go further.
299 return false
Jiyong Park09d77522019-11-18 11:16:27 +0900300 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100301
Jiyong Park9918e1a2020-03-17 19:16:40 +0900302 notices := to.NoticeFiles()
303 noticeFiles = append(noticeFiles, notices...)
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100304
305 return true
Jiyong Park9918e1a2020-03-17 19:16:40 +0900306 })
Jiyong Park09d77522019-11-18 11:16:27 +0900307
Jiyong Park41f637d2020-09-09 13:18:02 +0900308 for _, fi := range a.filesInfo {
309 noticeFiles = append(noticeFiles, fi.noticeFiles...)
310 }
311
Jiyong Park09d77522019-11-18 11:16:27 +0900312 if len(noticeFiles) == 0 {
Jiyong Park19972c72020-01-28 20:05:29 +0900313 return android.NoticeOutputs{}
Jiyong Park09d77522019-11-18 11:16:27 +0900314 }
315
Jiyong Park33c77362020-05-29 22:00:16 +0900316 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles))
Jiyong Park09d77522019-11-18 11:16:27 +0900317}
318
Jiyong Park3a1602e2020-01-14 14:39:19 +0900319func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath {
320 output := android.PathForModuleOut(ctx, "installed-files.txt")
321 rule := android.NewRuleBuilder()
322 rule.Command().
323 Implicit(builtApex).
324 Text("(cd " + imageDir.String() + " ; ").
Jiyong Parkbd63a102020-02-08 12:40:05 +0900325 Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") ").
Jiyong Park3a1602e2020-01-14 14:39:19 +0900326 Text(" | sort -nr > ").
327 Output(output)
328 rule.Build(pctx, ctx, "installed-files."+a.Name(), "Installed files")
329 return output.OutputPath
330}
331
Jiyong Parkbd159612020-02-28 15:22:21 +0900332func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath {
333 output := android.PathForModuleOut(ctx, "bundle_config.json")
334
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900335 type ApkConfig struct {
336 Package_name string `json:"package_name"`
337 Apk_path string `json:"path"`
338 }
Jiyong Parkbd159612020-02-28 15:22:21 +0900339 config := struct {
340 Compression struct {
341 Uncompressed_glob []string `json:"uncompressed_glob"`
342 } `json:"compression"`
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900343 Apex_config struct {
344 Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"`
345 } `json:"apex_config,omitempty"`
Jiyong Parkbd159612020-02-28 15:22:21 +0900346 }{}
347
348 config.Compression.Uncompressed_glob = []string{
349 "apex_payload.img",
350 "apex_manifest.*",
351 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900352
353 // collect the manifest names and paths of android apps
354 // if their manifest names are overridden
355 for _, fi := range a.filesInfo {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700356 if fi.class != app && fi.class != appSet {
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900357 continue
358 }
359 packageName := fi.overriddenPackageName
360 if packageName != "" {
361 config.Apex_config.Apex_embedded_apk_config = append(
362 config.Apex_config.Apex_embedded_apk_config,
363 ApkConfig{
364 Package_name: packageName,
365 Apk_path: fi.Path(),
366 })
367 }
368 }
369
Jiyong Parkbd159612020-02-28 15:22:21 +0900370 j, err := json.Marshal(config)
371 if err != nil {
372 panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
373 }
374
375 ctx.Build(pctx, android.BuildParams{
376 Rule: android.WriteFile,
377 Output: output,
378 Description: "Bundle Config " + output.String(),
379 Args: map[string]string{
380 "content": string(j),
381 },
382 })
383
384 return output.OutputPath
385}
386
Jiyong Park09d77522019-11-18 11:16:27 +0900387func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
388 var abis []string
389 for _, target := range ctx.MultiTargets() {
390 if len(target.Arch.Abi) > 0 {
391 abis = append(abis, target.Arch.Abi[0])
392 }
393 }
394
395 abis = android.FirstUniqueStrings(abis)
396
397 apexType := a.properties.ApexType
398 suffix := apexType.suffix()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900399 var implicitInputs []android.Path
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800400 unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
Jiyong Park09d77522019-11-18 11:16:27 +0900401
Jiyong Park7cd10e32020-01-14 09:22:18 +0900402 // TODO(jiyong): construct the copy rules using RuleBuilder
403 var copyCommands []string
404 for _, fi := range a.filesInfo {
405 destPath := android.PathForModuleOut(ctx, "image"+suffix, fi.Path()).String()
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700406 destPathDir := filepath.Dir(destPath)
407 if fi.class == appSet {
408 copyCommands = append(copyCommands, "rm -rf "+destPathDir)
409 }
410 copyCommands = append(copyCommands, "mkdir -p "+destPathDir)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900411 if a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() {
412 // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
413 pathOnDevice := filepath.Join("/system", fi.Path())
414 copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
415 } else {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700416 if fi.class == appSet {
417 copyCommands = append(copyCommands,
Colin Crossd783bbb2020-07-11 22:30:45 -0700418 fmt.Sprintf("unzip -qDD -d %s %s", destPathDir, fi.builtFile.String()))
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700419 } else {
420 copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
421 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900422 implicitInputs = append(implicitInputs, fi.builtFile)
423 }
424 // create additional symlinks pointing the file inside the APEX
425 for _, symlinkPath := range fi.SymlinkPaths() {
426 symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000427 copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900428 }
Liz Kammer1c14a212020-05-12 15:26:55 -0700429 for _, d := range fi.dataPaths {
430 // TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
Chris Parsons216e10a2020-07-09 17:12:52 -0400431 relPath := d.SrcPath.Rel()
432 dataPath := d.SrcPath.String()
Liz Kammer1c14a212020-05-12 15:26:55 -0700433 if !strings.HasSuffix(dataPath, relPath) {
434 panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
435 }
436
Liz Kammer0a51aa22020-07-21 11:13:17 -0700437 dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath), d.RelativeInstallPath).String()
Liz Kammer1c14a212020-05-12 15:26:55 -0700438
Chris Parsons216e10a2020-07-09 17:12:52 -0400439 copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
440 implicitInputs = append(implicitInputs, d.SrcPath)
Liz Kammer1c14a212020-05-12 15:26:55 -0700441 }
Jiyong Park09d77522019-11-18 11:16:27 +0900442 }
443
Jiyong Park7cd10e32020-01-14 09:22:18 +0900444 // TODO(jiyong): use RuleBuilder
445 var emitCommands []string
446 imageContentFile := android.PathForModuleOut(ctx, "content.txt")
Jooyung Han214bf372019-11-12 13:03:50 +0900447 emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
Jooyung Han5417f772020-03-12 18:37:20 +0900448 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900449 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
450 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900451 for _, fi := range a.filesInfo {
452 emitCommands = append(emitCommands, "echo './"+fi.Path()+"' >> "+imageContentFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900453 }
454 emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
Jooyung Han214bf372019-11-12 13:03:50 +0900455 implicitInputs = append(implicitInputs, a.manifestPbOut)
Jiyong Park09d77522019-11-18 11:16:27 +0900456
Jooyung Han938b5932020-06-20 12:47:47 +0900457 if a.overridableProperties.Allowed_files != nil {
Jiyong Park09d77522019-11-18 11:16:27 +0900458 ctx.Build(pctx, android.BuildParams{
459 Rule: emitApexContentRule,
460 Implicits: implicitInputs,
461 Output: imageContentFile,
462 Description: "emit apex image content",
463 Args: map[string]string{
464 "emit_commands": strings.Join(emitCommands, " && "),
465 },
466 })
467 implicitInputs = append(implicitInputs, imageContentFile)
Jooyung Han938b5932020-06-20 12:47:47 +0900468 allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))
Jiyong Park09d77522019-11-18 11:16:27 +0900469
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800470 phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
Jiyong Park09d77522019-11-18 11:16:27 +0900471 ctx.Build(pctx, android.BuildParams{
472 Rule: diffApexContentRule,
473 Implicits: implicitInputs,
474 Output: phonyOutput,
475 Description: "diff apex image content",
476 Args: map[string]string{
Colin Cross440e0d02020-06-11 11:32:11 -0700477 "allowed_files_file": allowedFilesFile.String(),
478 "image_content_file": imageContentFile.String(),
479 "apex_module_name": a.Name(),
Jiyong Park09d77522019-11-18 11:16:27 +0900480 },
481 })
482
483 implicitInputs = append(implicitInputs, phonyOutput)
484 }
485
486 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
487 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
488
Jiyong Park3a1602e2020-01-14 14:39:19 +0900489 imageDir := android.PathForModuleOut(ctx, "image"+suffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900490 if apexType == imageApex {
491 // files and dirs that will be created in APEX
492 var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
493 var executablePaths []string // this also includes dirs
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700494 var extractedAppSetPaths android.Paths
495 var extractedAppSetDirs []string
Jiyong Park09d77522019-11-18 11:16:27 +0900496 for _, f := range a.filesInfo {
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900497 pathInApex := f.Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900498 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
499 executablePaths = append(executablePaths, pathInApex)
Liz Kammer1c14a212020-05-12 15:26:55 -0700500 for _, d := range f.dataPaths {
Liz Kammer0a51aa22020-07-21 11:13:17 -0700501 readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
Liz Kammer1c14a212020-05-12 15:26:55 -0700502 }
Jiyong Park09d77522019-11-18 11:16:27 +0900503 for _, s := range f.symlinks {
504 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
505 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700506 } else if f.class == appSet {
507 extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile)
508 extractedAppSetDirs = append(extractedAppSetDirs, f.installDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900509 } else {
510 readOnlyPaths = append(readOnlyPaths, pathInApex)
511 }
512 dir := f.installDir
513 for !android.InList(dir, executablePaths) && dir != "" {
514 executablePaths = append(executablePaths, dir)
515 dir, _ = filepath.Split(dir) // move up to the parent
516 if len(dir) > 0 {
517 // remove trailing slash
518 dir = dir[:len(dir)-1]
519 }
520 }
521 }
522 sort.Strings(readOnlyPaths)
523 sort.Strings(executablePaths)
524 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
525 ctx.Build(pctx, android.BuildParams{
526 Rule: generateFsConfig,
527 Output: cannedFsConfig,
528 Description: "generate fs config",
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700529 Inputs: extractedAppSetPaths,
Jiyong Park09d77522019-11-18 11:16:27 +0900530 Args: map[string]string{
531 "ro_paths": strings.Join(readOnlyPaths, " "),
532 "exec_paths": strings.Join(executablePaths, " "),
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700533 "apk_paths": strings.Join(extractedAppSetDirs, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900534 },
535 })
536
Jiyong Park09d77522019-11-18 11:16:27 +0900537 optFlags := []string{}
538
539 // Additional implicit inputs.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900540 implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file)
Jiyong Park09d77522019-11-18 11:16:27 +0900541 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
542
Jooyung Han27151d92019-12-16 17:45:32 +0900543 manifestPackageName := a.getOverrideManifestPackageName(ctx)
544 if manifestPackageName != "" {
Jiyong Park09d77522019-11-18 11:16:27 +0900545 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
546 }
547
548 if a.properties.AndroidManifest != nil {
549 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
550 implicitInputs = append(implicitInputs, androidManifestFile)
551 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
552 }
553
554 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe644009a2020-05-20 00:16:27 +0100555 // TODO(b/157078772): propagate min_sdk_version to apexer.
Baligh Uddinf6201372020-01-24 23:15:44 +0000556 minSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000557
Jooyung Han5417f772020-03-12 18:37:20 +0900558 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
559 minSdkVersion = strconv.Itoa(a.minSdkVersion(ctx))
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000560 }
561
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000562 if java.UseApiFingerprint(ctx) {
563 targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000564 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
565 }
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000566 if java.UseApiFingerprint(ctx) {
567 minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000568 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
Jiyong Park09d77522019-11-18 11:16:27 +0900569 }
570 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
Baligh Uddinf6201372020-01-24 23:15:44 +0000571 optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +0900572
Baligh Uddin004d7172020-02-19 21:29:28 -0800573 if a.overridableProperties.Logging_parent != "" {
574 optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent)
575 }
576
Jiyong Park19972c72020-01-28 20:05:29 +0900577 a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix)
578 if a.mergedNotices.HtmlGzOutput.Valid() {
Jiyong Park09d77522019-11-18 11:16:27 +0900579 // If there's a NOTICE file, embed it as an asset file in the APEX.
Jiyong Park19972c72020-01-28 20:05:29 +0900580 implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path())
581 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String()))
Jiyong Park09d77522019-11-18 11:16:27 +0900582 }
583
Nikita Ioffeb4b44c02020-01-02 23:01:39 +0000584 if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && ctx.ModuleDir() != "system/apex/shim/build" && a.testOnlyShouldSkipHashtreeGeneration() {
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000585 ctx.PropertyErrorf("test_only_no_hashtree", "not available")
586 return
587 }
Jooyung Han5417f772020-03-12 18:37:20 +0900588 if a.minSdkVersion(ctx) > android.SdkVersion_Android10 || a.testOnlyShouldSkipHashtreeGeneration() {
Jiyong Park09d77522019-11-18 11:16:27 +0900589 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
590 // don't need hashtree for activation. Therefore, by removing hashtree from
591 // apex bundle (filesystem image in it, to be specific), we can save storage.
592 optFlags = append(optFlags, "--no_hashtree")
593 }
594
Dario Frenica913392020-04-27 18:21:11 +0100595 if a.testOnlyShouldSkipPayloadSign() {
596 optFlags = append(optFlags, "--unsigned_payload")
597 }
598
Jiyong Park09d77522019-11-18 11:16:27 +0900599 if a.properties.Apex_name != nil {
600 // If apex_name is set, apexer can skip checking if key name matches with apex name.
601 // Note that apex_manifest is also mended.
602 optFlags = append(optFlags, "--do_not_check_keyname")
603 }
604
Jooyung Han5417f772020-03-12 18:37:20 +0900605 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900606 implicitInputs = append(implicitInputs, a.manifestJsonOut)
607 optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String())
608 }
609
Theotime Combes4ba38c12020-06-12 12:46:59 +0000610 optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string())
611
Jiyong Park09d77522019-11-18 11:16:27 +0900612 ctx.Build(pctx, android.BuildParams{
613 Rule: apexRule,
614 Implicits: implicitInputs,
615 Output: unsignedOutputFile,
616 Description: "apex (" + apexType.name() + ")",
617 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900618 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900619 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900620 "copy_commands": strings.Join(copyCommands, " && "),
621 "manifest": a.manifestPbOut.String(),
622 "file_contexts": a.fileContexts.String(),
623 "canned_fs_config": cannedFsConfig.String(),
624 "key": a.private_key_file.String(),
625 "opt_flags": strings.Join(optFlags, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900626 },
627 })
628
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800629 apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix)
630 bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip")
Jiyong Park09d77522019-11-18 11:16:27 +0900631 a.bundleModuleFile = bundleModuleFile
632
633 ctx.Build(pctx, android.BuildParams{
634 Rule: apexProtoConvertRule,
635 Input: unsignedOutputFile,
636 Output: apexProtoFile,
637 Description: "apex proto convert",
638 })
639
Jiyong Parkbd159612020-02-28 15:22:21 +0900640 bundleConfig := a.buildBundleConfig(ctx)
641
Jiyong Park09d77522019-11-18 11:16:27 +0900642 ctx.Build(pctx, android.BuildParams{
643 Rule: apexBundleRule,
644 Input: apexProtoFile,
Jiyong Parkbd159612020-02-28 15:22:21 +0900645 Implicit: bundleConfig,
Jiyong Park09d77522019-11-18 11:16:27 +0900646 Output: a.bundleModuleFile,
647 Description: "apex bundle module",
648 Args: map[string]string{
Jiyong Parkbd159612020-02-28 15:22:21 +0900649 "abi": strings.Join(abis, "."),
650 "config": bundleConfig.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900651 },
652 })
653 } else {
654 ctx.Build(pctx, android.BuildParams{
655 Rule: zipApexRule,
656 Implicits: implicitInputs,
657 Output: unsignedOutputFile,
658 Description: "apex (" + apexType.name() + ")",
659 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900660 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900661 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900662 "copy_commands": strings.Join(copyCommands, " && "),
663 "manifest": a.manifestPbOut.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900664 },
665 })
666 }
667
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800668 a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix)
Kousik Kumar309b1c02020-05-28 06:13:33 -0700669 rule := java.Signapk
670 args := map[string]string{
671 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
672 "flags": "-a 4096", //alignment
673 }
674 implicits := android.Paths{
675 a.container_certificate_file,
676 a.container_private_key_file,
677 }
Ramy Medhat16f23a42020-09-03 01:29:49 -0400678 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
Kousik Kumar309b1c02020-05-28 06:13:33 -0700679 rule = java.SignapkRE
680 args["implicits"] = strings.Join(implicits.Strings(), ",")
681 args["outCommaList"] = a.outputFile.String()
682 }
Jiyong Park09d77522019-11-18 11:16:27 +0900683 ctx.Build(pctx, android.BuildParams{
Kousik Kumar309b1c02020-05-28 06:13:33 -0700684 Rule: rule,
Jiyong Park09d77522019-11-18 11:16:27 +0900685 Description: "signapk",
686 Output: a.outputFile,
687 Input: unsignedOutputFile,
Kousik Kumar309b1c02020-05-28 06:13:33 -0700688 Implicits: implicits,
689 Args: args,
Jiyong Park09d77522019-11-18 11:16:27 +0900690 })
691
692 // Install to $OUT/soong/{target,host}/.../apex
693 if a.installable() {
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800694 ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900695 }
696 a.buildFilesInfo(ctx)
Jiyong Park3a1602e2020-01-14 14:39:19 +0900697
698 // installed-files.txt is dist'ed
699 a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900700}
701
702func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
703 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
704 // reply true to `InstallBypassMake()` (thus making the call
705 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
706 // instead of `android.PathForOutput`) to return the correct path to the flattened
707 // APEX (as its contents is installed by Make, not Soong).
708 factx := flattenedApexContext{ctx}
Jooyung Han7f146c02020-09-23 19:15:55 +0900709 a.outputFile = android.PathForModuleInstall(&factx, "apex", a.Name())
Jiyong Park09d77522019-11-18 11:16:27 +0900710 a.buildFilesInfo(ctx)
711}
712
713func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) {
Jooyung Hanf121a652019-12-17 14:30:11 +0900714 if a.container_certificate_file == nil {
715 cert := String(a.properties.Certificate)
716 if cert == "" {
717 pem, key := ctx.Config().DefaultAppCertificate(ctx)
718 a.container_certificate_file = pem
719 a.container_private_key_file = key
720 } else {
721 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
722 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
723 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
724 }
Jiyong Park09d77522019-11-18 11:16:27 +0900725 }
726}
727
728func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) {
729 if a.installable() {
Jooyung Han214bf372019-11-12 13:03:50 +0900730 // For flattened APEX, do nothing but make sure that APEX manifest and apex_pubkey are also copied along
Jiyong Park09d77522019-11-18 11:16:27 +0900731 // with other ordinary files.
Jiyong Park7cd10e32020-01-14 09:22:18 +0900732 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900733
734 // rename to apex_pubkey
735 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
736 ctx.Build(pctx, android.BuildParams{
737 Rule: android.Cp,
738 Input: a.public_key_file,
739 Output: copiedPubkey,
740 })
Jiyong Park7cd10e32020-01-14 09:22:18 +0900741 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900742
743 if a.properties.ApexType == flattenedApex {
Jiyong Parka5948012020-02-07 10:15:14 +0900744 apexBundleName := a.Name()
Jiyong Park09d77522019-11-18 11:16:27 +0900745 for _, fi := range a.filesInfo {
Jiyong Parka5948012020-02-07 10:15:14 +0900746 dir := filepath.Join("apex", apexBundleName, fi.installDir)
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900747 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.Stem(), fi.builtFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900748 for _, sym := range fi.symlinks {
749 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
750 }
751 }
752 }
753 }
754}
Jooyung Han27151d92019-12-16 17:45:32 +0900755
756func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string {
757 // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
758 // to see if it should be overridden because their <apex name> is dynamically generated
759 // according to its VNDK version.
760 if a.vndkApex {
761 overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName)
762 if overridden {
763 return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1)
764 }
765 return ""
766 }
Baligh Uddin5b57dba2020-03-15 13:01:05 -0700767 if a.overridableProperties.Package_name != "" {
768 return a.overridableProperties.Package_name
769 }
Jiyong Park20bacab2020-03-03 11:45:41 +0900770 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jooyung Han27151d92019-12-16 17:45:32 +0900771 if overridden {
772 return manifestPackageName
773 }
774 return ""
775}
Jiyong Park83dc74b2020-01-14 18:38:44 +0900776
777func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
778 if !a.primaryApexType {
779 return
780 }
781
782 if a.properties.IsCoverageVariant {
783 // Otherwise, we will have duplicated rules for coverage and
784 // non-coverage variants of the same APEX
785 return
786 }
787
788 if ctx.Host() {
789 // No need to generate dependency info for host variant
790 return
791 }
792
Artur Satayev872a1442020-04-27 17:08:37 +0100793 depInfos := android.DepNameToDepInfoMap{}
Jooyung Han749dc692020-04-15 11:03:39 +0900794 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Artur Satayev872a1442020-04-27 17:08:37 +0100795 if from.Name() == to.Name() {
796 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
797 // As soon as the dependency graph crosses the APEX boundary, don't go further.
798 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +0900799 }
Jiyong Park83dc74b2020-01-14 18:38:44 +0900800
Artur Satayev872a1442020-04-27 17:08:37 +0100801 if info, exists := depInfos[to.Name()]; exists {
802 if !android.InList(from.Name(), info.From) {
803 info.From = append(info.From, from.Name())
804 }
805 info.IsExternal = info.IsExternal && externalDep
806 depInfos[to.Name()] = info
807 } else {
Artur Satayev480e25b2020-04-27 18:53:18 +0100808 toMinSdkVersion := "(no version)"
809 if m, ok := to.(interface{ MinSdkVersion() string }); ok {
810 if v := m.MinSdkVersion(); v != "" {
811 toMinSdkVersion = v
812 }
813 }
814
Artur Satayev872a1442020-04-27 17:08:37 +0100815 depInfos[to.Name()] = android.ApexModuleDepInfo{
Artur Satayev480e25b2020-04-27 18:53:18 +0100816 To: to.Name(),
817 From: []string{from.Name()},
818 IsExternal: externalDep,
819 MinSdkVersion: toMinSdkVersion,
Artur Satayev872a1442020-04-27 17:08:37 +0100820 }
821 }
822
823 // As soon as the dependency graph crosses the APEX boundary, don't go further.
824 return !externalDep
Jiyong Park83dc74b2020-01-14 18:38:44 +0900825 })
826
Artur Satayev480e25b2020-04-27 18:53:18 +0100827 a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos)
Artur Satayev872a1442020-04-27 17:08:37 +0100828
Jiyong Park83dc74b2020-01-14 18:38:44 +0900829 ctx.Build(pctx, android.BuildParams{
830 Rule: android.Phony,
831 Output: android.PathForPhony(ctx, a.Name()+"-deps-info"),
Artur Satayeva8bd1132020-04-27 18:07:06 +0100832 Inputs: []android.Path{
833 a.ApexBundleDepsInfo.FullListPath(),
834 a.ApexBundleDepsInfo.FlatListPath(),
835 },
Jiyong Park83dc74b2020-01-14 18:38:44 +0900836 })
837}
Colin Cross08dca382020-07-21 20:31:17 -0700838
839func (a *apexBundle) buildLintReports(ctx android.ModuleContext) {
840 depSetsBuilder := java.NewLintDepSetBuilder()
841 for _, fi := range a.filesInfo {
842 depSetsBuilder.Transitive(fi.lintDepSets)
843 }
844
845 a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
846}