blob: c5680ad2df8fc424cfb32a49ea09985e2fdc175c [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 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
Jiyong Park41f637d2020-09-09 13:18:02 +0900289 for _, fi := range a.filesInfo {
290 noticeFiles = append(noticeFiles, fi.noticeFiles...)
291 }
292
Jiyong Park09d77522019-11-18 11:16:27 +0900293 if len(noticeFiles) == 0 {
Jiyong Park19972c72020-01-28 20:05:29 +0900294 return android.NoticeOutputs{}
Jiyong Park09d77522019-11-18 11:16:27 +0900295 }
296
Jiyong Park33c77362020-05-29 22:00:16 +0900297 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles))
Jiyong Park09d77522019-11-18 11:16:27 +0900298}
299
Jiyong Park3a1602e2020-01-14 14:39:19 +0900300func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath {
301 output := android.PathForModuleOut(ctx, "installed-files.txt")
302 rule := android.NewRuleBuilder()
303 rule.Command().
304 Implicit(builtApex).
305 Text("(cd " + imageDir.String() + " ; ").
Jiyong Parkbd63a102020-02-08 12:40:05 +0900306 Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") ").
Jiyong Park3a1602e2020-01-14 14:39:19 +0900307 Text(" | sort -nr > ").
308 Output(output)
309 rule.Build(pctx, ctx, "installed-files."+a.Name(), "Installed files")
310 return output.OutputPath
311}
312
Jiyong Parkbd159612020-02-28 15:22:21 +0900313func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath {
314 output := android.PathForModuleOut(ctx, "bundle_config.json")
315
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900316 type ApkConfig struct {
317 Package_name string `json:"package_name"`
318 Apk_path string `json:"path"`
319 }
Jiyong Parkbd159612020-02-28 15:22:21 +0900320 config := struct {
321 Compression struct {
322 Uncompressed_glob []string `json:"uncompressed_glob"`
323 } `json:"compression"`
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900324 Apex_config struct {
325 Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"`
326 } `json:"apex_config,omitempty"`
Jiyong Parkbd159612020-02-28 15:22:21 +0900327 }{}
328
329 config.Compression.Uncompressed_glob = []string{
330 "apex_payload.img",
331 "apex_manifest.*",
332 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900333
334 // collect the manifest names and paths of android apps
335 // if their manifest names are overridden
336 for _, fi := range a.filesInfo {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700337 if fi.class != app && fi.class != appSet {
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900338 continue
339 }
340 packageName := fi.overriddenPackageName
341 if packageName != "" {
342 config.Apex_config.Apex_embedded_apk_config = append(
343 config.Apex_config.Apex_embedded_apk_config,
344 ApkConfig{
345 Package_name: packageName,
346 Apk_path: fi.Path(),
347 })
348 }
349 }
350
Jiyong Parkbd159612020-02-28 15:22:21 +0900351 j, err := json.Marshal(config)
352 if err != nil {
353 panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
354 }
355
356 ctx.Build(pctx, android.BuildParams{
357 Rule: android.WriteFile,
358 Output: output,
359 Description: "Bundle Config " + output.String(),
360 Args: map[string]string{
361 "content": string(j),
362 },
363 })
364
365 return output.OutputPath
366}
367
Jiyong Park09d77522019-11-18 11:16:27 +0900368func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
369 var abis []string
370 for _, target := range ctx.MultiTargets() {
371 if len(target.Arch.Abi) > 0 {
372 abis = append(abis, target.Arch.Abi[0])
373 }
374 }
375
376 abis = android.FirstUniqueStrings(abis)
377
378 apexType := a.properties.ApexType
379 suffix := apexType.suffix()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900380 var implicitInputs []android.Path
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800381 unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
Jiyong Park09d77522019-11-18 11:16:27 +0900382
Jiyong Park7cd10e32020-01-14 09:22:18 +0900383 // TODO(jiyong): construct the copy rules using RuleBuilder
384 var copyCommands []string
385 for _, fi := range a.filesInfo {
386 destPath := android.PathForModuleOut(ctx, "image"+suffix, fi.Path()).String()
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700387 destPathDir := filepath.Dir(destPath)
388 if fi.class == appSet {
389 copyCommands = append(copyCommands, "rm -rf "+destPathDir)
390 }
391 copyCommands = append(copyCommands, "mkdir -p "+destPathDir)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900392 if a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() {
393 // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
394 pathOnDevice := filepath.Join("/system", fi.Path())
395 copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
396 } else {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700397 if fi.class == appSet {
398 copyCommands = append(copyCommands,
Colin Crossd783bbb2020-07-11 22:30:45 -0700399 fmt.Sprintf("unzip -qDD -d %s %s", destPathDir, fi.builtFile.String()))
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700400 } else {
401 copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
402 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900403 implicitInputs = append(implicitInputs, fi.builtFile)
404 }
405 // create additional symlinks pointing the file inside the APEX
406 for _, symlinkPath := range fi.SymlinkPaths() {
407 symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000408 copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900409 }
Liz Kammer1c14a212020-05-12 15:26:55 -0700410 for _, d := range fi.dataPaths {
411 // 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 -0400412 relPath := d.SrcPath.Rel()
413 dataPath := d.SrcPath.String()
Liz Kammer1c14a212020-05-12 15:26:55 -0700414 if !strings.HasSuffix(dataPath, relPath) {
415 panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
416 }
417
Liz Kammer0a51aa22020-07-21 11:13:17 -0700418 dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath), d.RelativeInstallPath).String()
Liz Kammer1c14a212020-05-12 15:26:55 -0700419
Chris Parsons216e10a2020-07-09 17:12:52 -0400420 copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest)
421 implicitInputs = append(implicitInputs, d.SrcPath)
Liz Kammer1c14a212020-05-12 15:26:55 -0700422 }
Jiyong Park09d77522019-11-18 11:16:27 +0900423 }
424
Jiyong Park7cd10e32020-01-14 09:22:18 +0900425 // TODO(jiyong): use RuleBuilder
426 var emitCommands []string
427 imageContentFile := android.PathForModuleOut(ctx, "content.txt")
Jooyung Han214bf372019-11-12 13:03:50 +0900428 emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
Jooyung Han5417f772020-03-12 18:37:20 +0900429 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900430 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
431 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900432 for _, fi := range a.filesInfo {
433 emitCommands = append(emitCommands, "echo './"+fi.Path()+"' >> "+imageContentFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900434 }
435 emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
Jooyung Han214bf372019-11-12 13:03:50 +0900436 implicitInputs = append(implicitInputs, a.manifestPbOut)
Jiyong Park09d77522019-11-18 11:16:27 +0900437
Jooyung Han938b5932020-06-20 12:47:47 +0900438 if a.overridableProperties.Allowed_files != nil {
Jiyong Park09d77522019-11-18 11:16:27 +0900439 ctx.Build(pctx, android.BuildParams{
440 Rule: emitApexContentRule,
441 Implicits: implicitInputs,
442 Output: imageContentFile,
443 Description: "emit apex image content",
444 Args: map[string]string{
445 "emit_commands": strings.Join(emitCommands, " && "),
446 },
447 })
448 implicitInputs = append(implicitInputs, imageContentFile)
Jooyung Han938b5932020-06-20 12:47:47 +0900449 allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))
Jiyong Park09d77522019-11-18 11:16:27 +0900450
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800451 phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
Jiyong Park09d77522019-11-18 11:16:27 +0900452 ctx.Build(pctx, android.BuildParams{
453 Rule: diffApexContentRule,
454 Implicits: implicitInputs,
455 Output: phonyOutput,
456 Description: "diff apex image content",
457 Args: map[string]string{
Colin Cross440e0d02020-06-11 11:32:11 -0700458 "allowed_files_file": allowedFilesFile.String(),
459 "image_content_file": imageContentFile.String(),
460 "apex_module_name": a.Name(),
Jiyong Park09d77522019-11-18 11:16:27 +0900461 },
462 })
463
464 implicitInputs = append(implicitInputs, phonyOutput)
465 }
466
467 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
468 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
469
Jiyong Park3a1602e2020-01-14 14:39:19 +0900470 imageDir := android.PathForModuleOut(ctx, "image"+suffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900471 if apexType == imageApex {
472 // files and dirs that will be created in APEX
473 var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
474 var executablePaths []string // this also includes dirs
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700475 var extractedAppSetPaths android.Paths
476 var extractedAppSetDirs []string
Jiyong Park09d77522019-11-18 11:16:27 +0900477 for _, f := range a.filesInfo {
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900478 pathInApex := f.Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900479 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
480 executablePaths = append(executablePaths, pathInApex)
Liz Kammer1c14a212020-05-12 15:26:55 -0700481 for _, d := range f.dataPaths {
Liz Kammer0a51aa22020-07-21 11:13:17 -0700482 readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel()))
Liz Kammer1c14a212020-05-12 15:26:55 -0700483 }
Jiyong Park09d77522019-11-18 11:16:27 +0900484 for _, s := range f.symlinks {
485 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
486 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700487 } else if f.class == appSet {
488 extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile)
489 extractedAppSetDirs = append(extractedAppSetDirs, f.installDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900490 } else {
491 readOnlyPaths = append(readOnlyPaths, pathInApex)
492 }
493 dir := f.installDir
494 for !android.InList(dir, executablePaths) && dir != "" {
495 executablePaths = append(executablePaths, dir)
496 dir, _ = filepath.Split(dir) // move up to the parent
497 if len(dir) > 0 {
498 // remove trailing slash
499 dir = dir[:len(dir)-1]
500 }
501 }
502 }
503 sort.Strings(readOnlyPaths)
504 sort.Strings(executablePaths)
505 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
506 ctx.Build(pctx, android.BuildParams{
507 Rule: generateFsConfig,
508 Output: cannedFsConfig,
509 Description: "generate fs config",
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700510 Inputs: extractedAppSetPaths,
Jiyong Park09d77522019-11-18 11:16:27 +0900511 Args: map[string]string{
512 "ro_paths": strings.Join(readOnlyPaths, " "),
513 "exec_paths": strings.Join(executablePaths, " "),
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700514 "apk_paths": strings.Join(extractedAppSetDirs, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900515 },
516 })
517
Jiyong Park09d77522019-11-18 11:16:27 +0900518 optFlags := []string{}
519
520 // Additional implicit inputs.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900521 implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file)
Jiyong Park09d77522019-11-18 11:16:27 +0900522 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
523
Jooyung Han27151d92019-12-16 17:45:32 +0900524 manifestPackageName := a.getOverrideManifestPackageName(ctx)
525 if manifestPackageName != "" {
Jiyong Park09d77522019-11-18 11:16:27 +0900526 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
527 }
528
529 if a.properties.AndroidManifest != nil {
530 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
531 implicitInputs = append(implicitInputs, androidManifestFile)
532 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
533 }
534
535 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe644009a2020-05-20 00:16:27 +0100536 // TODO(b/157078772): propagate min_sdk_version to apexer.
Baligh Uddinf6201372020-01-24 23:15:44 +0000537 minSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000538
Jooyung Han5417f772020-03-12 18:37:20 +0900539 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
540 minSdkVersion = strconv.Itoa(a.minSdkVersion(ctx))
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000541 }
542
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000543 if java.UseApiFingerprint(ctx) {
544 targetSdkVersion = 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))
546 }
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000547 if java.UseApiFingerprint(ctx) {
548 minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000549 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
Jiyong Park09d77522019-11-18 11:16:27 +0900550 }
551 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
Baligh Uddinf6201372020-01-24 23:15:44 +0000552 optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +0900553
Baligh Uddin004d7172020-02-19 21:29:28 -0800554 if a.overridableProperties.Logging_parent != "" {
555 optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent)
556 }
557
Jiyong Park19972c72020-01-28 20:05:29 +0900558 a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix)
559 if a.mergedNotices.HtmlGzOutput.Valid() {
Jiyong Park09d77522019-11-18 11:16:27 +0900560 // If there's a NOTICE file, embed it as an asset file in the APEX.
Jiyong Park19972c72020-01-28 20:05:29 +0900561 implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path())
562 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String()))
Jiyong Park09d77522019-11-18 11:16:27 +0900563 }
564
Nikita Ioffeb4b44c02020-01-02 23:01:39 +0000565 if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && ctx.ModuleDir() != "system/apex/shim/build" && a.testOnlyShouldSkipHashtreeGeneration() {
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000566 ctx.PropertyErrorf("test_only_no_hashtree", "not available")
567 return
568 }
Jooyung Han5417f772020-03-12 18:37:20 +0900569 if a.minSdkVersion(ctx) > android.SdkVersion_Android10 || a.testOnlyShouldSkipHashtreeGeneration() {
Jiyong Park09d77522019-11-18 11:16:27 +0900570 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
571 // don't need hashtree for activation. Therefore, by removing hashtree from
572 // apex bundle (filesystem image in it, to be specific), we can save storage.
573 optFlags = append(optFlags, "--no_hashtree")
574 }
575
Dario Frenica913392020-04-27 18:21:11 +0100576 if a.testOnlyShouldSkipPayloadSign() {
577 optFlags = append(optFlags, "--unsigned_payload")
578 }
579
Jiyong Park09d77522019-11-18 11:16:27 +0900580 if a.properties.Apex_name != nil {
581 // If apex_name is set, apexer can skip checking if key name matches with apex name.
582 // Note that apex_manifest is also mended.
583 optFlags = append(optFlags, "--do_not_check_keyname")
584 }
585
Jooyung Han5417f772020-03-12 18:37:20 +0900586 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900587 implicitInputs = append(implicitInputs, a.manifestJsonOut)
588 optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String())
589 }
590
Theotime Combes4ba38c12020-06-12 12:46:59 +0000591 optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string())
592
Jiyong Park09d77522019-11-18 11:16:27 +0900593 ctx.Build(pctx, android.BuildParams{
594 Rule: apexRule,
595 Implicits: implicitInputs,
596 Output: unsignedOutputFile,
597 Description: "apex (" + apexType.name() + ")",
598 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900599 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900600 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900601 "copy_commands": strings.Join(copyCommands, " && "),
602 "manifest": a.manifestPbOut.String(),
603 "file_contexts": a.fileContexts.String(),
604 "canned_fs_config": cannedFsConfig.String(),
605 "key": a.private_key_file.String(),
606 "opt_flags": strings.Join(optFlags, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900607 },
608 })
609
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800610 apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix)
611 bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip")
Jiyong Park09d77522019-11-18 11:16:27 +0900612 a.bundleModuleFile = bundleModuleFile
613
614 ctx.Build(pctx, android.BuildParams{
615 Rule: apexProtoConvertRule,
616 Input: unsignedOutputFile,
617 Output: apexProtoFile,
618 Description: "apex proto convert",
619 })
620
Jiyong Parkbd159612020-02-28 15:22:21 +0900621 bundleConfig := a.buildBundleConfig(ctx)
622
Jiyong Park09d77522019-11-18 11:16:27 +0900623 ctx.Build(pctx, android.BuildParams{
624 Rule: apexBundleRule,
625 Input: apexProtoFile,
Jiyong Parkbd159612020-02-28 15:22:21 +0900626 Implicit: bundleConfig,
Jiyong Park09d77522019-11-18 11:16:27 +0900627 Output: a.bundleModuleFile,
628 Description: "apex bundle module",
629 Args: map[string]string{
Jiyong Parkbd159612020-02-28 15:22:21 +0900630 "abi": strings.Join(abis, "."),
631 "config": bundleConfig.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900632 },
633 })
634 } else {
635 ctx.Build(pctx, android.BuildParams{
636 Rule: zipApexRule,
637 Implicits: implicitInputs,
638 Output: unsignedOutputFile,
639 Description: "apex (" + apexType.name() + ")",
640 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900641 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900642 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900643 "copy_commands": strings.Join(copyCommands, " && "),
644 "manifest": a.manifestPbOut.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900645 },
646 })
647 }
648
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800649 a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix)
Kousik Kumar309b1c02020-05-28 06:13:33 -0700650 rule := java.Signapk
651 args := map[string]string{
652 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
653 "flags": "-a 4096", //alignment
654 }
655 implicits := android.Paths{
656 a.container_certificate_file,
657 a.container_private_key_file,
658 }
Ramy Medhat16f23a42020-09-03 01:29:49 -0400659 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
Kousik Kumar309b1c02020-05-28 06:13:33 -0700660 rule = java.SignapkRE
661 args["implicits"] = strings.Join(implicits.Strings(), ",")
662 args["outCommaList"] = a.outputFile.String()
663 }
Jiyong Park09d77522019-11-18 11:16:27 +0900664 ctx.Build(pctx, android.BuildParams{
Kousik Kumar309b1c02020-05-28 06:13:33 -0700665 Rule: rule,
Jiyong Park09d77522019-11-18 11:16:27 +0900666 Description: "signapk",
667 Output: a.outputFile,
668 Input: unsignedOutputFile,
Kousik Kumar309b1c02020-05-28 06:13:33 -0700669 Implicits: implicits,
670 Args: args,
Jiyong Park09d77522019-11-18 11:16:27 +0900671 })
672
673 // Install to $OUT/soong/{target,host}/.../apex
674 if a.installable() {
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800675 ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900676 }
677 a.buildFilesInfo(ctx)
Jiyong Park3a1602e2020-01-14 14:39:19 +0900678
679 // installed-files.txt is dist'ed
680 a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900681}
682
683func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
684 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
685 // reply true to `InstallBypassMake()` (thus making the call
686 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
687 // instead of `android.PathForOutput`) to return the correct path to the flattened
688 // APEX (as its contents is installed by Make, not Soong).
689 factx := flattenedApexContext{ctx}
Jiyong Parka5948012020-02-07 10:15:14 +0900690 apexBundleName := a.Name()
691 a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName)
Jiyong Park09d77522019-11-18 11:16:27 +0900692
Jooyung Han6bfc0432020-04-27 22:18:19 +0900693 if a.installable() {
Jiyong Parka5948012020-02-07 10:15:14 +0900694 installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName)
Jooyung Han54aca7b2019-11-20 02:26:02 +0900695 devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
Jiyong Parka5948012020-02-07 10:15:14 +0900696 addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900697 }
Jiyong Park09d77522019-11-18 11:16:27 +0900698 a.buildFilesInfo(ctx)
699}
700
701func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) {
Jooyung Hanf121a652019-12-17 14:30:11 +0900702 if a.container_certificate_file == nil {
703 cert := String(a.properties.Certificate)
704 if cert == "" {
705 pem, key := ctx.Config().DefaultAppCertificate(ctx)
706 a.container_certificate_file = pem
707 a.container_private_key_file = key
708 } else {
709 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
710 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
711 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
712 }
Jiyong Park09d77522019-11-18 11:16:27 +0900713 }
714}
715
716func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) {
717 if a.installable() {
Jooyung Han214bf372019-11-12 13:03:50 +0900718 // 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 +0900719 // with other ordinary files.
Jiyong Park7cd10e32020-01-14 09:22:18 +0900720 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900721
722 // rename to apex_pubkey
723 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
724 ctx.Build(pctx, android.BuildParams{
725 Rule: android.Cp,
726 Input: a.public_key_file,
727 Output: copiedPubkey,
728 })
Jiyong Park7cd10e32020-01-14 09:22:18 +0900729 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900730
731 if a.properties.ApexType == flattenedApex {
Jiyong Parka5948012020-02-07 10:15:14 +0900732 apexBundleName := a.Name()
Jiyong Park09d77522019-11-18 11:16:27 +0900733 for _, fi := range a.filesInfo {
Jiyong Parka5948012020-02-07 10:15:14 +0900734 dir := filepath.Join("apex", apexBundleName, fi.installDir)
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900735 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.Stem(), fi.builtFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900736 for _, sym := range fi.symlinks {
737 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
738 }
739 }
740 }
741 }
742}
Jooyung Han27151d92019-12-16 17:45:32 +0900743
744func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string {
745 // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
746 // to see if it should be overridden because their <apex name> is dynamically generated
747 // according to its VNDK version.
748 if a.vndkApex {
749 overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName)
750 if overridden {
751 return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1)
752 }
753 return ""
754 }
Baligh Uddin5b57dba2020-03-15 13:01:05 -0700755 if a.overridableProperties.Package_name != "" {
756 return a.overridableProperties.Package_name
757 }
Jiyong Park20bacab2020-03-03 11:45:41 +0900758 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jooyung Han27151d92019-12-16 17:45:32 +0900759 if overridden {
760 return manifestPackageName
761 }
762 return ""
763}
Jiyong Park83dc74b2020-01-14 18:38:44 +0900764
765func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
766 if !a.primaryApexType {
767 return
768 }
769
770 if a.properties.IsCoverageVariant {
771 // Otherwise, we will have duplicated rules for coverage and
772 // non-coverage variants of the same APEX
773 return
774 }
775
776 if ctx.Host() {
777 // No need to generate dependency info for host variant
778 return
779 }
780
Artur Satayev872a1442020-04-27 17:08:37 +0100781 depInfos := android.DepNameToDepInfoMap{}
Jooyung Han749dc692020-04-15 11:03:39 +0900782 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Artur Satayev872a1442020-04-27 17:08:37 +0100783 if from.Name() == to.Name() {
784 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
785 // As soon as the dependency graph crosses the APEX boundary, don't go further.
786 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +0900787 }
Jiyong Park83dc74b2020-01-14 18:38:44 +0900788
Artur Satayev872a1442020-04-27 17:08:37 +0100789 if info, exists := depInfos[to.Name()]; exists {
790 if !android.InList(from.Name(), info.From) {
791 info.From = append(info.From, from.Name())
792 }
793 info.IsExternal = info.IsExternal && externalDep
794 depInfos[to.Name()] = info
795 } else {
Artur Satayev480e25b2020-04-27 18:53:18 +0100796 toMinSdkVersion := "(no version)"
797 if m, ok := to.(interface{ MinSdkVersion() string }); ok {
798 if v := m.MinSdkVersion(); v != "" {
799 toMinSdkVersion = v
800 }
801 }
802
Artur Satayev872a1442020-04-27 17:08:37 +0100803 depInfos[to.Name()] = android.ApexModuleDepInfo{
Artur Satayev480e25b2020-04-27 18:53:18 +0100804 To: to.Name(),
805 From: []string{from.Name()},
806 IsExternal: externalDep,
807 MinSdkVersion: toMinSdkVersion,
Artur Satayev872a1442020-04-27 17:08:37 +0100808 }
809 }
810
811 // As soon as the dependency graph crosses the APEX boundary, don't go further.
812 return !externalDep
Jiyong Park83dc74b2020-01-14 18:38:44 +0900813 })
814
Artur Satayev480e25b2020-04-27 18:53:18 +0100815 a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos)
Artur Satayev872a1442020-04-27 17:08:37 +0100816
Jiyong Park83dc74b2020-01-14 18:38:44 +0900817 ctx.Build(pctx, android.BuildParams{
818 Rule: android.Phony,
819 Output: android.PathForPhony(ctx, a.Name()+"-deps-info"),
Artur Satayeva8bd1132020-04-27 18:07:06 +0100820 Inputs: []android.Path{
821 a.ApexBundleDepsInfo.FullListPath(),
822 a.ApexBundleDepsInfo.FlatListPath(),
823 },
Jiyong Park83dc74b2020-01-14 18:38:44 +0900824 })
825}
Colin Cross08dca382020-07-21 20:31:17 -0700826
827func (a *apexBundle) buildLintReports(ctx android.ModuleContext) {
828 depSetsBuilder := java.NewLintDepSetBuilder()
829 for _, fi := range a.filesInfo {
830 depSetsBuilder.Transitive(fi.lintDepSets)
831 }
832
833 a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build())
834}