blob: 3a148c4a850eb91b65bc83d9e98af691b5599f66 [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 {
198 if fi.isJniLib {
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 Han2dfd54d2020-06-29 14:54:22 +0900260 // remove old file
Jooyung Han580eb4f2020-06-24 19:33:06 +0900261 rule.Command().Text("rm").FlagWithOutput("-f ", output)
Jooyung Han2dfd54d2020-06-29 14:54:22 +0900262 // copy file_contexts
Jooyung Han580eb4f2020-06-24 19:33:06 +0900263 rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output)
Jooyung Han2dfd54d2020-06-29 14:54:22 +0900264 // new line
Jooyung Han580eb4f2020-06-24 19:33:06 +0900265 rule.Command().Text("echo").Text(">>").Output(output)
Jooyung Han2dfd54d2020-06-29 14:54:22 +0900266 // force-label /apex_manifest.pb and / as system_file so that apexd can read them
Jooyung Han580eb4f2020-06-24 19:33:06 +0900267 rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output)
Jooyung Han2dfd54d2020-06-29 14:54:22 +0900268 rule.Command().Text("echo").Flag("/ u:object_r:system_file:s0").Text(">>").Output(output)
Jooyung Han580eb4f2020-06-24 19:33:06 +0900269 rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts")
270
271 a.fileContexts = output.OutputPath
272}
273
Jiyong Park19972c72020-01-28 20:05:29 +0900274func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs {
Jiyong Park9918e1a2020-03-17 19:16:40 +0900275 var noticeFiles android.Paths
276
Jooyung Han749dc692020-04-15 11:03:39 +0900277 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park9918e1a2020-03-17 19:16:40 +0900278 if externalDep {
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100279 // As soon as the dependency graph crosses the APEX boundary, don't go further.
280 return false
Jiyong Park09d77522019-11-18 11:16:27 +0900281 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100282
Jiyong Park9918e1a2020-03-17 19:16:40 +0900283 notices := to.NoticeFiles()
284 noticeFiles = append(noticeFiles, notices...)
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100285
286 return true
Jiyong Park9918e1a2020-03-17 19:16:40 +0900287 })
Jiyong Park09d77522019-11-18 11:16:27 +0900288
289 if len(noticeFiles) == 0 {
Jiyong Park19972c72020-01-28 20:05:29 +0900290 return android.NoticeOutputs{}
Jiyong Park09d77522019-11-18 11:16:27 +0900291 }
292
Jiyong Park33c77362020-05-29 22:00:16 +0900293 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles))
Jiyong Park09d77522019-11-18 11:16:27 +0900294}
295
Jiyong Park3a1602e2020-01-14 14:39:19 +0900296func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath {
297 output := android.PathForModuleOut(ctx, "installed-files.txt")
298 rule := android.NewRuleBuilder()
299 rule.Command().
300 Implicit(builtApex).
301 Text("(cd " + imageDir.String() + " ; ").
Jiyong Parkbd63a102020-02-08 12:40:05 +0900302 Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") ").
Jiyong Park3a1602e2020-01-14 14:39:19 +0900303 Text(" | sort -nr > ").
304 Output(output)
305 rule.Build(pctx, ctx, "installed-files."+a.Name(), "Installed files")
306 return output.OutputPath
307}
308
Jiyong Parkbd159612020-02-28 15:22:21 +0900309func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath {
310 output := android.PathForModuleOut(ctx, "bundle_config.json")
311
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900312 type ApkConfig struct {
313 Package_name string `json:"package_name"`
314 Apk_path string `json:"path"`
315 }
Jiyong Parkbd159612020-02-28 15:22:21 +0900316 config := struct {
317 Compression struct {
318 Uncompressed_glob []string `json:"uncompressed_glob"`
319 } `json:"compression"`
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900320 Apex_config struct {
321 Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"`
322 } `json:"apex_config,omitempty"`
Jiyong Parkbd159612020-02-28 15:22:21 +0900323 }{}
324
325 config.Compression.Uncompressed_glob = []string{
326 "apex_payload.img",
327 "apex_manifest.*",
328 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900329
330 // collect the manifest names and paths of android apps
331 // if their manifest names are overridden
332 for _, fi := range a.filesInfo {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700333 if fi.class != app && fi.class != appSet {
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900334 continue
335 }
336 packageName := fi.overriddenPackageName
337 if packageName != "" {
338 config.Apex_config.Apex_embedded_apk_config = append(
339 config.Apex_config.Apex_embedded_apk_config,
340 ApkConfig{
341 Package_name: packageName,
342 Apk_path: fi.Path(),
343 })
344 }
345 }
346
Jiyong Parkbd159612020-02-28 15:22:21 +0900347 j, err := json.Marshal(config)
348 if err != nil {
349 panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
350 }
351
352 ctx.Build(pctx, android.BuildParams{
353 Rule: android.WriteFile,
354 Output: output,
355 Description: "Bundle Config " + output.String(),
356 Args: map[string]string{
357 "content": string(j),
358 },
359 })
360
361 return output.OutputPath
362}
363
Jiyong Park09d77522019-11-18 11:16:27 +0900364func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
365 var abis []string
366 for _, target := range ctx.MultiTargets() {
367 if len(target.Arch.Abi) > 0 {
368 abis = append(abis, target.Arch.Abi[0])
369 }
370 }
371
372 abis = android.FirstUniqueStrings(abis)
373
374 apexType := a.properties.ApexType
375 suffix := apexType.suffix()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900376 var implicitInputs []android.Path
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800377 unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
Jiyong Park09d77522019-11-18 11:16:27 +0900378
Jiyong Park7cd10e32020-01-14 09:22:18 +0900379 // TODO(jiyong): construct the copy rules using RuleBuilder
380 var copyCommands []string
381 for _, fi := range a.filesInfo {
382 destPath := android.PathForModuleOut(ctx, "image"+suffix, fi.Path()).String()
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700383 destPathDir := filepath.Dir(destPath)
384 if fi.class == appSet {
385 copyCommands = append(copyCommands, "rm -rf "+destPathDir)
386 }
387 copyCommands = append(copyCommands, "mkdir -p "+destPathDir)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900388 if a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() {
389 // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
390 pathOnDevice := filepath.Join("/system", fi.Path())
391 copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
392 } else {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700393 if fi.class == appSet {
394 copyCommands = append(copyCommands,
Colin Crossd783bbb2020-07-11 22:30:45 -0700395 fmt.Sprintf("unzip -qDD -d %s %s", destPathDir, fi.builtFile.String()))
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700396 } else {
397 copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
398 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900399 implicitInputs = append(implicitInputs, fi.builtFile)
400 }
401 // create additional symlinks pointing the file inside the APEX
402 for _, symlinkPath := range fi.SymlinkPaths() {
403 symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000404 copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900405 }
Liz Kammer1c14a212020-05-12 15:26:55 -0700406 for _, d := range fi.dataPaths {
407 // 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 -0400408 relPath := d.SrcPath.Rel()
409 dataPath := d.SrcPath.String()
Liz Kammer1c14a212020-05-12 15:26:55 -0700410 if !strings.HasSuffix(dataPath, relPath) {
411 panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
412 }
413
Liz Kammer0a51aa22020-07-21 11:13:17 -0700414 dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath), d.RelativeInstallPath).String()
Liz Kammer1c14a212020-05-12 15:26:55 -0700415
Chris Parsons216e10a2020-07-09 17:12:52 -0400416 copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
417 implicitInputs = append(implicitInputs, d.SrcPath)
Liz Kammer1c14a212020-05-12 15:26:55 -0700418 }
Jiyong Park09d77522019-11-18 11:16:27 +0900419 }
420
Jiyong Park7cd10e32020-01-14 09:22:18 +0900421 // TODO(jiyong): use RuleBuilder
422 var emitCommands []string
423 imageContentFile := android.PathForModuleOut(ctx, "content.txt")
Jooyung Han214bf372019-11-12 13:03:50 +0900424 emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
Jooyung Han5417f772020-03-12 18:37:20 +0900425 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900426 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
427 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900428 for _, fi := range a.filesInfo {
429 emitCommands = append(emitCommands, "echo './"+fi.Path()+"' >> "+imageContentFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900430 }
431 emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
Jooyung Han214bf372019-11-12 13:03:50 +0900432 implicitInputs = append(implicitInputs, a.manifestPbOut)
Jiyong Park09d77522019-11-18 11:16:27 +0900433
Jooyung Han938b5932020-06-20 12:47:47 +0900434 if a.overridableProperties.Allowed_files != nil {
Jiyong Park09d77522019-11-18 11:16:27 +0900435 ctx.Build(pctx, android.BuildParams{
436 Rule: emitApexContentRule,
437 Implicits: implicitInputs,
438 Output: imageContentFile,
439 Description: "emit apex image content",
440 Args: map[string]string{
441 "emit_commands": strings.Join(emitCommands, " && "),
442 },
443 })
444 implicitInputs = append(implicitInputs, imageContentFile)
Jooyung Han938b5932020-06-20 12:47:47 +0900445 allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))
Jiyong Park09d77522019-11-18 11:16:27 +0900446
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800447 phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
Jiyong Park09d77522019-11-18 11:16:27 +0900448 ctx.Build(pctx, android.BuildParams{
449 Rule: diffApexContentRule,
450 Implicits: implicitInputs,
451 Output: phonyOutput,
452 Description: "diff apex image content",
453 Args: map[string]string{
Colin Cross440e0d02020-06-11 11:32:11 -0700454 "allowed_files_file": allowedFilesFile.String(),
455 "image_content_file": imageContentFile.String(),
456 "apex_module_name": a.Name(),
Jiyong Park09d77522019-11-18 11:16:27 +0900457 },
458 })
459
460 implicitInputs = append(implicitInputs, phonyOutput)
461 }
462
463 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
464 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
465
Jiyong Park3a1602e2020-01-14 14:39:19 +0900466 imageDir := android.PathForModuleOut(ctx, "image"+suffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900467 if apexType == imageApex {
468 // files and dirs that will be created in APEX
469 var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
470 var executablePaths []string // this also includes dirs
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700471 var extractedAppSetPaths android.Paths
472 var extractedAppSetDirs []string
Jiyong Park09d77522019-11-18 11:16:27 +0900473 for _, f := range a.filesInfo {
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900474 pathInApex := f.Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900475 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
476 executablePaths = append(executablePaths, pathInApex)
Liz Kammer1c14a212020-05-12 15:26:55 -0700477 for _, d := range f.dataPaths {
Liz Kammer0a51aa22020-07-21 11:13:17 -0700478 readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
Liz Kammer1c14a212020-05-12 15:26:55 -0700479 }
Jiyong Park09d77522019-11-18 11:16:27 +0900480 for _, s := range f.symlinks {
481 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
482 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700483 } else if f.class == appSet {
484 extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile)
485 extractedAppSetDirs = append(extractedAppSetDirs, f.installDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900486 } else {
487 readOnlyPaths = append(readOnlyPaths, pathInApex)
488 }
489 dir := f.installDir
490 for !android.InList(dir, executablePaths) && dir != "" {
491 executablePaths = append(executablePaths, dir)
492 dir, _ = filepath.Split(dir) // move up to the parent
493 if len(dir) > 0 {
494 // remove trailing slash
495 dir = dir[:len(dir)-1]
496 }
497 }
498 }
499 sort.Strings(readOnlyPaths)
500 sort.Strings(executablePaths)
501 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
502 ctx.Build(pctx, android.BuildParams{
503 Rule: generateFsConfig,
504 Output: cannedFsConfig,
505 Description: "generate fs config",
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700506 Inputs: extractedAppSetPaths,
Jiyong Park09d77522019-11-18 11:16:27 +0900507 Args: map[string]string{
508 "ro_paths": strings.Join(readOnlyPaths, " "),
509 "exec_paths": strings.Join(executablePaths, " "),
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700510 "apk_paths": strings.Join(extractedAppSetDirs, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900511 },
512 })
513
Jiyong Park09d77522019-11-18 11:16:27 +0900514 optFlags := []string{}
515
516 // Additional implicit inputs.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900517 implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file)
Jiyong Park09d77522019-11-18 11:16:27 +0900518 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
519
Jooyung Han27151d92019-12-16 17:45:32 +0900520 manifestPackageName := a.getOverrideManifestPackageName(ctx)
521 if manifestPackageName != "" {
Jiyong Park09d77522019-11-18 11:16:27 +0900522 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
523 }
524
525 if a.properties.AndroidManifest != nil {
526 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
527 implicitInputs = append(implicitInputs, androidManifestFile)
528 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
529 }
530
531 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe644009a2020-05-20 00:16:27 +0100532 // TODO(b/157078772): propagate min_sdk_version to apexer.
Baligh Uddinf6201372020-01-24 23:15:44 +0000533 minSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000534
Jooyung Han5417f772020-03-12 18:37:20 +0900535 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
536 minSdkVersion = strconv.Itoa(a.minSdkVersion(ctx))
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000537 }
538
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000539 if java.UseApiFingerprint(ctx) {
540 targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000541 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
542 }
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000543 if java.UseApiFingerprint(ctx) {
544 minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000545 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
Jiyong Park09d77522019-11-18 11:16:27 +0900546 }
547 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
Baligh Uddinf6201372020-01-24 23:15:44 +0000548 optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +0900549
Baligh Uddin004d7172020-02-19 21:29:28 -0800550 if a.overridableProperties.Logging_parent != "" {
551 optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent)
552 }
553
Jiyong Park19972c72020-01-28 20:05:29 +0900554 a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix)
555 if a.mergedNotices.HtmlGzOutput.Valid() {
Jiyong Park09d77522019-11-18 11:16:27 +0900556 // If there's a NOTICE file, embed it as an asset file in the APEX.
Jiyong Park19972c72020-01-28 20:05:29 +0900557 implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path())
558 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String()))
Jiyong Park09d77522019-11-18 11:16:27 +0900559 }
560
Nikita Ioffeb4b44c02020-01-02 23:01:39 +0000561 if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && ctx.ModuleDir() != "system/apex/shim/build" && a.testOnlyShouldSkipHashtreeGeneration() {
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000562 ctx.PropertyErrorf("test_only_no_hashtree", "not available")
563 return
564 }
Jooyung Han5417f772020-03-12 18:37:20 +0900565 if a.minSdkVersion(ctx) > android.SdkVersion_Android10 || a.testOnlyShouldSkipHashtreeGeneration() {
Jiyong Park09d77522019-11-18 11:16:27 +0900566 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
567 // don't need hashtree for activation. Therefore, by removing hashtree from
568 // apex bundle (filesystem image in it, to be specific), we can save storage.
569 optFlags = append(optFlags, "--no_hashtree")
570 }
571
Dario Frenica913392020-04-27 18:21:11 +0100572 if a.testOnlyShouldSkipPayloadSign() {
573 optFlags = append(optFlags, "--unsigned_payload")
574 }
575
Jiyong Park09d77522019-11-18 11:16:27 +0900576 if a.properties.Apex_name != nil {
577 // If apex_name is set, apexer can skip checking if key name matches with apex name.
578 // Note that apex_manifest is also mended.
579 optFlags = append(optFlags, "--do_not_check_keyname")
580 }
581
Jooyung Han5417f772020-03-12 18:37:20 +0900582 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900583 implicitInputs = append(implicitInputs, a.manifestJsonOut)
584 optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String())
585 }
586
Theotime Combes4ba38c12020-06-12 12:46:59 +0000587 optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string())
588
Jiyong Park09d77522019-11-18 11:16:27 +0900589 ctx.Build(pctx, android.BuildParams{
590 Rule: apexRule,
591 Implicits: implicitInputs,
592 Output: unsignedOutputFile,
593 Description: "apex (" + apexType.name() + ")",
594 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900595 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900596 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900597 "copy_commands": strings.Join(copyCommands, " && "),
598 "manifest": a.manifestPbOut.String(),
599 "file_contexts": a.fileContexts.String(),
600 "canned_fs_config": cannedFsConfig.String(),
601 "key": a.private_key_file.String(),
602 "opt_flags": strings.Join(optFlags, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900603 },
604 })
605
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800606 apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix)
607 bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip")
Jiyong Park09d77522019-11-18 11:16:27 +0900608 a.bundleModuleFile = bundleModuleFile
609
610 ctx.Build(pctx, android.BuildParams{
611 Rule: apexProtoConvertRule,
612 Input: unsignedOutputFile,
613 Output: apexProtoFile,
614 Description: "apex proto convert",
615 })
616
Jiyong Parkbd159612020-02-28 15:22:21 +0900617 bundleConfig := a.buildBundleConfig(ctx)
618
Jiyong Park09d77522019-11-18 11:16:27 +0900619 ctx.Build(pctx, android.BuildParams{
620 Rule: apexBundleRule,
621 Input: apexProtoFile,
Jiyong Parkbd159612020-02-28 15:22:21 +0900622 Implicit: bundleConfig,
Jiyong Park09d77522019-11-18 11:16:27 +0900623 Output: a.bundleModuleFile,
624 Description: "apex bundle module",
625 Args: map[string]string{
Jiyong Parkbd159612020-02-28 15:22:21 +0900626 "abi": strings.Join(abis, "."),
627 "config": bundleConfig.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900628 },
629 })
630 } else {
631 ctx.Build(pctx, android.BuildParams{
632 Rule: zipApexRule,
633 Implicits: implicitInputs,
634 Output: unsignedOutputFile,
635 Description: "apex (" + apexType.name() + ")",
636 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900637 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900638 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900639 "copy_commands": strings.Join(copyCommands, " && "),
640 "manifest": a.manifestPbOut.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900641 },
642 })
643 }
644
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800645 a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix)
Kousik Kumar309b1c02020-05-28 06:13:33 -0700646 rule := java.Signapk
647 args := map[string]string{
648 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
649 "flags": "-a 4096", //alignment
650 }
651 implicits := android.Paths{
652 a.container_certificate_file,
653 a.container_private_key_file,
654 }
655 if ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
656 rule = java.SignapkRE
657 args["implicits"] = strings.Join(implicits.Strings(), ",")
658 args["outCommaList"] = a.outputFile.String()
659 }
Jiyong Park09d77522019-11-18 11:16:27 +0900660 ctx.Build(pctx, android.BuildParams{
Kousik Kumar309b1c02020-05-28 06:13:33 -0700661 Rule: rule,
Jiyong Park09d77522019-11-18 11:16:27 +0900662 Description: "signapk",
663 Output: a.outputFile,
664 Input: unsignedOutputFile,
Kousik Kumar309b1c02020-05-28 06:13:33 -0700665 Implicits: implicits,
666 Args: args,
Jiyong Park09d77522019-11-18 11:16:27 +0900667 })
668
669 // Install to $OUT/soong/{target,host}/.../apex
670 if a.installable() {
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800671 ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900672 }
673 a.buildFilesInfo(ctx)
Jiyong Park3a1602e2020-01-14 14:39:19 +0900674
675 // installed-files.txt is dist'ed
676 a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900677}
678
679func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
680 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
681 // reply true to `InstallBypassMake()` (thus making the call
682 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
683 // instead of `android.PathForOutput`) to return the correct path to the flattened
684 // APEX (as its contents is installed by Make, not Soong).
685 factx := flattenedApexContext{ctx}
Jiyong Parka5948012020-02-07 10:15:14 +0900686 apexBundleName := a.Name()
687 a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName)
Jiyong Park09d77522019-11-18 11:16:27 +0900688
Jiyong Park317645e2019-12-05 13:20:58 +0900689 if a.installable() && a.GetOverriddenBy() == "" {
Jiyong Parka5948012020-02-07 10:15:14 +0900690 installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName)
Jooyung Han54aca7b2019-11-20 02:26:02 +0900691 devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
Jiyong Parka5948012020-02-07 10:15:14 +0900692 addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900693 }
Jiyong Park09d77522019-11-18 11:16:27 +0900694 a.buildFilesInfo(ctx)
695}
696
697func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) {
Jooyung Hanf121a652019-12-17 14:30:11 +0900698 if a.container_certificate_file == nil {
699 cert := String(a.properties.Certificate)
700 if cert == "" {
701 pem, key := ctx.Config().DefaultAppCertificate(ctx)
702 a.container_certificate_file = pem
703 a.container_private_key_file = key
704 } else {
705 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
706 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
707 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
708 }
Jiyong Park09d77522019-11-18 11:16:27 +0900709 }
710}
711
712func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) {
713 if a.installable() {
Jooyung Han214bf372019-11-12 13:03:50 +0900714 // 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 +0900715 // with other ordinary files.
Jiyong Park7cd10e32020-01-14 09:22:18 +0900716 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900717
718 // rename to apex_pubkey
719 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
720 ctx.Build(pctx, android.BuildParams{
721 Rule: android.Cp,
722 Input: a.public_key_file,
723 Output: copiedPubkey,
724 })
Jiyong Park7cd10e32020-01-14 09:22:18 +0900725 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900726
727 if a.properties.ApexType == flattenedApex {
Jiyong Parka5948012020-02-07 10:15:14 +0900728 apexBundleName := a.Name()
Jiyong Park09d77522019-11-18 11:16:27 +0900729 for _, fi := range a.filesInfo {
Jiyong Parka5948012020-02-07 10:15:14 +0900730 dir := filepath.Join("apex", apexBundleName, fi.installDir)
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900731 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.Stem(), fi.builtFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900732 for _, sym := range fi.symlinks {
733 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
734 }
735 }
736 }
737 }
738}
Jooyung Han27151d92019-12-16 17:45:32 +0900739
740func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string {
741 // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
742 // to see if it should be overridden because their <apex name> is dynamically generated
743 // according to its VNDK version.
744 if a.vndkApex {
745 overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName)
746 if overridden {
747 return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1)
748 }
749 return ""
750 }
Baligh Uddin5b57dba2020-03-15 13:01:05 -0700751 if a.overridableProperties.Package_name != "" {
752 return a.overridableProperties.Package_name
753 }
Jiyong Park20bacab2020-03-03 11:45:41 +0900754 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jooyung Han27151d92019-12-16 17:45:32 +0900755 if overridden {
756 return manifestPackageName
757 }
758 return ""
759}
Jiyong Park83dc74b2020-01-14 18:38:44 +0900760
761func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
762 if !a.primaryApexType {
763 return
764 }
765
766 if a.properties.IsCoverageVariant {
767 // Otherwise, we will have duplicated rules for coverage and
768 // non-coverage variants of the same APEX
769 return
770 }
771
772 if ctx.Host() {
773 // No need to generate dependency info for host variant
774 return
775 }
776
Artur Satayev872a1442020-04-27 17:08:37 +0100777 depInfos := android.DepNameToDepInfoMap{}
Jooyung Han749dc692020-04-15 11:03:39 +0900778 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Artur Satayev872a1442020-04-27 17:08:37 +0100779 if from.Name() == to.Name() {
780 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
781 // As soon as the dependency graph crosses the APEX boundary, don't go further.
782 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +0900783 }
Jiyong Park83dc74b2020-01-14 18:38:44 +0900784
Artur Satayev872a1442020-04-27 17:08:37 +0100785 if info, exists := depInfos[to.Name()]; exists {
786 if !android.InList(from.Name(), info.From) {
787 info.From = append(info.From, from.Name())
788 }
789 info.IsExternal = info.IsExternal && externalDep
790 depInfos[to.Name()] = info
791 } else {
Artur Satayev480e25b2020-04-27 18:53:18 +0100792 toMinSdkVersion := "(no version)"
793 if m, ok := to.(interface{ MinSdkVersion() string }); ok {
794 if v := m.MinSdkVersion(); v != "" {
795 toMinSdkVersion = v
796 }
797 }
798
Artur Satayev872a1442020-04-27 17:08:37 +0100799 depInfos[to.Name()] = android.ApexModuleDepInfo{
Artur Satayev480e25b2020-04-27 18:53:18 +0100800 To: to.Name(),
801 From: []string{from.Name()},
802 IsExternal: externalDep,
803 MinSdkVersion: toMinSdkVersion,
Artur Satayev872a1442020-04-27 17:08:37 +0100804 }
805 }
806
807 // As soon as the dependency graph crosses the APEX boundary, don't go further.
808 return !externalDep
Jiyong Park83dc74b2020-01-14 18:38:44 +0900809 })
810
Artur Satayev480e25b2020-04-27 18:53:18 +0100811 a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos)
Artur Satayev872a1442020-04-27 17:08:37 +0100812
Jiyong Park83dc74b2020-01-14 18:38:44 +0900813 ctx.Build(pctx, android.BuildParams{
814 Rule: android.Phony,
815 Output: android.PathForPhony(ctx, a.Name()+"-deps-info"),
Artur Satayeva8bd1132020-04-27 18:07:06 +0100816 Inputs: []android.Path{
817 a.ApexBundleDepsInfo.FullListPath(),
818 a.ApexBundleDepsInfo.FlatListPath(),
819 },
Jiyong Park83dc74b2020-01-14 18:38:44 +0900820 })
821}
Colin Cross08dca382020-07-21 20:31:17 -0700822
823func (a *apexBundle) buildLintReports(ctx android.ModuleContext) {
824 depSetsBuilder := java.NewLintDepSetBuilder()
825 for _, fi := range a.filesInfo {
826 depSetsBuilder.Transitive(fi.lintDepSets)
827 }
828
829 a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
830}