blob: ac3e64015b041f9423e203f1aa064b1f223ef573 [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")
Jiyong Park09d77522019-11-18 11:16:27 +090066}
67
68var (
69 // Create a canned fs config file where all files and directories are
70 // by default set to (uid/gid/mode) = (1000/1000/0644)
71 // TODO(b/113082813) make this configurable using config.fs syntax
72 generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{
Sasha Smundak18d98bc2020-05-27 16:36:07 -070073 Command: `( echo '/ 1000 1000 0755' ` +
74 `&& for i in ${ro_paths}; do echo "/$$i 1000 1000 0644"; done ` +
75 `&& for i in ${exec_paths}; do echo "/$$i 0 2000 0755"; done ` +
76 `&& ( 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}`,
77 Description: "fs_config ${out}",
78 Rspfile: "$out.apklist",
79 RspfileContent: "$in",
80 }, "ro_paths", "exec_paths", "apk_paths")
Jiyong Park09d77522019-11-18 11:16:27 +090081
82 apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{
83 Command: `rm -f $out && ${jsonmodify} $in ` +
84 `-a provideNativeLibs ${provideNativeLibs} ` +
85 `-a requireNativeLibs ${requireNativeLibs} ` +
86 `${opt} ` +
87 `-o $out`,
88 CommandDeps: []string{"${jsonmodify}"},
89 Description: "prepare ${out}",
90 }, "provideNativeLibs", "requireNativeLibs", "opt")
91
92 stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{
93 Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`,
94 CommandDeps: []string{"${conv_apex_manifest}"},
95 Description: "strip ${in}=>${out}",
96 })
97
98 pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{
99 Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`,
100 CommandDeps: []string{"${conv_apex_manifest}"},
101 Description: "convert ${in}=>${out}",
102 })
103
104 // TODO(b/113233103): make sure that file_contexts is sane, i.e., validate
105 // against the binary policy using sefcontext_compiler -p <policy>.
106
107 // TODO(b/114327326): automate the generation of file_contexts
108 apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{
109 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
110 `(. ${out}.copy_commands) && ` +
111 `APEXER_TOOL_PATH=${tool_path} ` +
112 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900113 `--file_contexts ${file_contexts} ` +
114 `--canned_fs_config ${canned_fs_config} ` +
Dario Freni0f4ae072020-01-02 15:24:12 +0000115 `--include_build_info ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900116 `--payload_type image ` +
117 `--key ${key} ${opt_flags} ${image_dir} ${out} `,
118 CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
119 "${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
120 "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"},
121 Rspfile: "${out}.copy_commands",
122 RspfileContent: "${copy_commands}",
123 Description: "APEX ${image_dir} => ${out}",
Jooyung Han214bf372019-11-12 13:03:50 +0900124 }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest")
Jiyong Park09d77522019-11-18 11:16:27 +0900125
126 zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
127 Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
128 `(. ${out}.copy_commands) && ` +
129 `APEXER_TOOL_PATH=${tool_path} ` +
Jooyung Han214bf372019-11-12 13:03:50 +0900130 `${apexer} --force --manifest ${manifest} ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900131 `--payload_type zip ` +
132 `${image_dir} ${out} `,
133 CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"},
134 Rspfile: "${out}.copy_commands",
135 RspfileContent: "${copy_commands}",
136 Description: "ZipAPEX ${image_dir} => ${out}",
Jooyung Han214bf372019-11-12 13:03:50 +0900137 }, "tool_path", "image_dir", "copy_commands", "manifest")
Jiyong Park09d77522019-11-18 11:16:27 +0900138
139 apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule",
140 blueprint.RuleParams{
141 Command: `${aapt2} convert --output-format proto $in -o $out`,
142 CommandDeps: []string{"${aapt2}"},
143 })
144
145 apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
Jiyong Parkbd159612020-02-28 15:22:21 +0900146 Command: `${zip2zip} -i $in -o $out.base ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900147 `apex_payload.img:apex/${abi}.img ` +
Dario Frenida1aefe2020-03-02 21:47:09 +0000148 `apex_build_info.pb:apex/${abi}.build_info.pb ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900149 `apex_manifest.json:root/apex_manifest.json ` +
Jiyong Park53ae3342019-12-08 02:06:24 +0900150 `apex_manifest.pb:root/apex_manifest.pb ` +
Jiyong Park09d77522019-11-18 11:16:27 +0900151 `AndroidManifest.xml:manifest/AndroidManifest.xml ` +
Jiyong Parkbd159612020-02-28 15:22:21 +0900152 `assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` +
153 `${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` +
154 `${merge_zips} $out $out.base $out.config`,
155 CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"},
Jiyong Park09d77522019-11-18 11:16:27 +0900156 Description: "app bundle",
Jiyong Parkbd159612020-02-28 15:22:21 +0900157 }, "abi", "config")
Jiyong Park09d77522019-11-18 11:16:27 +0900158
159 emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
160 Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
161 Rspfile: "${out}.emit_commands",
162 RspfileContent: "${emit_commands}",
163 Description: "Emit APEX image content",
164 }, "emit_commands")
165
166 diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
167 Command: `diff --unchanged-group-format='' \` +
168 `--changed-group-format='%<' \` +
Colin Cross440e0d02020-06-11 11:32:11 -0700169 `${image_content_file} ${allowed_files_file} || (` +
Jiyong Park09d77522019-11-18 11:16:27 +0900170 `echo -e "New unexpected files were added to ${apex_module_name}." ` +
171 ` "To fix the build run following command:" && ` +
Colin Cross440e0d02020-06-11 11:32:11 -0700172 `echo "system/apex/tools/update_allowed_list.sh ${allowed_files_file} ${image_content_file}" && ` +
Dan Willemsen81e43c52020-01-28 15:40:19 -0800173 `exit 1); touch ${out}`,
Colin Cross440e0d02020-06-11 11:32:11 -0700174 Description: "Diff ${image_content_file} and ${allowed_files_file}",
175 }, "image_content_file", "allowed_files_file", "apex_module_name")
Jiyong Park09d77522019-11-18 11:16:27 +0900176)
177
178func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) {
179 manifestSrc := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json"))
180
Jooyung Han214bf372019-11-12 13:03:50 +0900181 manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json")
Jiyong Park09d77522019-11-18 11:16:27 +0900182
183 // put dependency({provide|require}NativeLibs) in apex_manifest.json
184 provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs)
185 requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs))
186
187 // apex name can be overridden
188 optCommands := []string{}
189 if a.properties.Apex_name != nil {
190 optCommands = append(optCommands, "-v name "+*a.properties.Apex_name)
191 }
192
Jooyung Han643adc42020-02-27 13:50:06 +0900193 // collect jniLibs. Notice that a.filesInfo is already sorted
194 var jniLibs []string
195 for _, fi := range a.filesInfo {
196 if fi.isJniLib {
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900197 jniLibs = append(jniLibs, fi.Stem())
Jooyung Han643adc42020-02-27 13:50:06 +0900198 }
199 }
200 if len(jniLibs) > 0 {
201 optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " "))
202 }
203
Jiyong Park09d77522019-11-18 11:16:27 +0900204 ctx.Build(pctx, android.BuildParams{
205 Rule: apexManifestRule,
206 Input: manifestSrc,
Jooyung Han214bf372019-11-12 13:03:50 +0900207 Output: manifestJsonFullOut,
Jiyong Park09d77522019-11-18 11:16:27 +0900208 Args: map[string]string{
209 "provideNativeLibs": strings.Join(provideNativeLibs, " "),
210 "requireNativeLibs": strings.Join(requireNativeLibs, " "),
211 "opt": strings.Join(optCommands, " "),
212 },
213 })
214
Jooyung Han5417f772020-03-12 18:37:20 +0900215 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900216 // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json
217 // prepare stripped-down version so that APEX modules built from R+ can be installed to Q
218 a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json")
219 ctx.Build(pctx, android.BuildParams{
220 Rule: stripApexManifestRule,
221 Input: manifestJsonFullOut,
222 Output: a.manifestJsonOut,
223 })
224 }
Jiyong Park09d77522019-11-18 11:16:27 +0900225
226 // from R+, protobuf binary format (.pb) is the standard format for apex_manifest
227 a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb")
228 ctx.Build(pctx, android.BuildParams{
229 Rule: pbApexManifestRule,
Jooyung Han214bf372019-11-12 13:03:50 +0900230 Input: manifestJsonFullOut,
Jiyong Park09d77522019-11-18 11:16:27 +0900231 Output: a.manifestPbOut,
232 })
233}
234
Jooyung Han580eb4f2020-06-24 19:33:06 +0900235func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) {
236 if a.properties.ApexType == zipApex {
237 return
238 }
239 var fileContexts android.Path
240 if a.properties.File_contexts == nil {
241 fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
242 } else {
243 fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
244 }
245 if a.Platform() {
246 if matched, err := path.Match("system/sepolicy/**/*", fileContexts.String()); err != nil || !matched {
247 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", fileContexts)
248 return
249 }
250 }
251 if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() {
252 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
253 return
254 }
255
256 output := android.PathForModuleOut(ctx, "file_contexts")
257 rule := android.NewRuleBuilder()
258 rule.Command().Text("rm").FlagWithOutput("-f ", output)
259 rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output)
260 rule.Command().Text("echo").Text(">>").Output(output)
261 rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output)
262 rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts")
263
264 a.fileContexts = output.OutputPath
265}
266
Jiyong Park19972c72020-01-28 20:05:29 +0900267func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs {
Jiyong Park9918e1a2020-03-17 19:16:40 +0900268 var noticeFiles android.Paths
269
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100270 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park9918e1a2020-03-17 19:16:40 +0900271 if externalDep {
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100272 // As soon as the dependency graph crosses the APEX boundary, don't go further.
273 return false
Jiyong Park09d77522019-11-18 11:16:27 +0900274 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100275
Jiyong Park9918e1a2020-03-17 19:16:40 +0900276 notices := to.NoticeFiles()
277 noticeFiles = append(noticeFiles, notices...)
Paul Duffinbe5a5be2020-03-30 15:54:08 +0100278
279 return true
Jiyong Park9918e1a2020-03-17 19:16:40 +0900280 })
Jiyong Park09d77522019-11-18 11:16:27 +0900281
282 if len(noticeFiles) == 0 {
Jiyong Park19972c72020-01-28 20:05:29 +0900283 return android.NoticeOutputs{}
Jiyong Park09d77522019-11-18 11:16:27 +0900284 }
285
Jiyong Park33c77362020-05-29 22:00:16 +0900286 return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles))
Jiyong Park09d77522019-11-18 11:16:27 +0900287}
288
Jiyong Park3a1602e2020-01-14 14:39:19 +0900289func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath {
290 output := android.PathForModuleOut(ctx, "installed-files.txt")
291 rule := android.NewRuleBuilder()
292 rule.Command().
293 Implicit(builtApex).
294 Text("(cd " + imageDir.String() + " ; ").
Jiyong Parkbd63a102020-02-08 12:40:05 +0900295 Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") ").
Jiyong Park3a1602e2020-01-14 14:39:19 +0900296 Text(" | sort -nr > ").
297 Output(output)
298 rule.Build(pctx, ctx, "installed-files."+a.Name(), "Installed files")
299 return output.OutputPath
300}
301
Jiyong Parkbd159612020-02-28 15:22:21 +0900302func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath {
303 output := android.PathForModuleOut(ctx, "bundle_config.json")
304
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900305 type ApkConfig struct {
306 Package_name string `json:"package_name"`
307 Apk_path string `json:"path"`
308 }
Jiyong Parkbd159612020-02-28 15:22:21 +0900309 config := struct {
310 Compression struct {
311 Uncompressed_glob []string `json:"uncompressed_glob"`
312 } `json:"compression"`
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900313 Apex_config struct {
314 Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"`
315 } `json:"apex_config,omitempty"`
Jiyong Parkbd159612020-02-28 15:22:21 +0900316 }{}
317
318 config.Compression.Uncompressed_glob = []string{
319 "apex_payload.img",
320 "apex_manifest.*",
321 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900322
323 // collect the manifest names and paths of android apps
324 // if their manifest names are overridden
325 for _, fi := range a.filesInfo {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700326 if fi.class != app && fi.class != appSet {
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900327 continue
328 }
329 packageName := fi.overriddenPackageName
330 if packageName != "" {
331 config.Apex_config.Apex_embedded_apk_config = append(
332 config.Apex_config.Apex_embedded_apk_config,
333 ApkConfig{
334 Package_name: packageName,
335 Apk_path: fi.Path(),
336 })
337 }
338 }
339
Jiyong Parkbd159612020-02-28 15:22:21 +0900340 j, err := json.Marshal(config)
341 if err != nil {
342 panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
343 }
344
345 ctx.Build(pctx, android.BuildParams{
346 Rule: android.WriteFile,
347 Output: output,
348 Description: "Bundle Config " + output.String(),
349 Args: map[string]string{
350 "content": string(j),
351 },
352 })
353
354 return output.OutputPath
355}
356
Jiyong Park09d77522019-11-18 11:16:27 +0900357func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
358 var abis []string
359 for _, target := range ctx.MultiTargets() {
360 if len(target.Arch.Abi) > 0 {
361 abis = append(abis, target.Arch.Abi[0])
362 }
363 }
364
365 abis = android.FirstUniqueStrings(abis)
366
367 apexType := a.properties.ApexType
368 suffix := apexType.suffix()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900369 var implicitInputs []android.Path
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800370 unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
Jiyong Park09d77522019-11-18 11:16:27 +0900371
Jiyong Park7cd10e32020-01-14 09:22:18 +0900372 // TODO(jiyong): construct the copy rules using RuleBuilder
373 var copyCommands []string
374 for _, fi := range a.filesInfo {
375 destPath := android.PathForModuleOut(ctx, "image"+suffix, fi.Path()).String()
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700376 destPathDir := filepath.Dir(destPath)
377 if fi.class == appSet {
378 copyCommands = append(copyCommands, "rm -rf "+destPathDir)
379 }
380 copyCommands = append(copyCommands, "mkdir -p "+destPathDir)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900381 if a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() {
382 // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
383 pathOnDevice := filepath.Join("/system", fi.Path())
384 copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath)
385 } else {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700386 if fi.class == appSet {
387 copyCommands = append(copyCommands,
388 fmt.Sprintf("unzip -q -d %s %s", destPathDir, fi.builtFile.String()))
389 } else {
390 copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath)
391 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900392 implicitInputs = append(implicitInputs, fi.builtFile)
393 }
394 // create additional symlinks pointing the file inside the APEX
395 for _, symlinkPath := range fi.SymlinkPaths() {
396 symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
Tim Joinesc1ef1bb2020-03-18 18:00:41 +0000397 copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900398 }
Liz Kammer1c14a212020-05-12 15:26:55 -0700399 for _, d := range fi.dataPaths {
400 // TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
401 relPath := d.Rel()
402 dataPath := d.String()
403 if !strings.HasSuffix(dataPath, relPath) {
404 panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
405 }
406
407 dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath)).String()
408
409 copyCommands = append(copyCommands, "cp -f "+d.String()+" "+dataDest)
410 implicitInputs = append(implicitInputs, d)
411 }
Jiyong Park09d77522019-11-18 11:16:27 +0900412 }
413
Jiyong Park7cd10e32020-01-14 09:22:18 +0900414 // TODO(jiyong): use RuleBuilder
415 var emitCommands []string
416 imageContentFile := android.PathForModuleOut(ctx, "content.txt")
Jooyung Han214bf372019-11-12 13:03:50 +0900417 emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
Jooyung Han5417f772020-03-12 18:37:20 +0900418 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900419 emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
420 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900421 for _, fi := range a.filesInfo {
422 emitCommands = append(emitCommands, "echo './"+fi.Path()+"' >> "+imageContentFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900423 }
424 emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
Jooyung Han214bf372019-11-12 13:03:50 +0900425 implicitInputs = append(implicitInputs, a.manifestPbOut)
Jiyong Park09d77522019-11-18 11:16:27 +0900426
Jooyung Han938b5932020-06-20 12:47:47 +0900427 if a.overridableProperties.Allowed_files != nil {
Jiyong Park09d77522019-11-18 11:16:27 +0900428 ctx.Build(pctx, android.BuildParams{
429 Rule: emitApexContentRule,
430 Implicits: implicitInputs,
431 Output: imageContentFile,
432 Description: "emit apex image content",
433 Args: map[string]string{
434 "emit_commands": strings.Join(emitCommands, " && "),
435 },
436 })
437 implicitInputs = append(implicitInputs, imageContentFile)
Jooyung Han938b5932020-06-20 12:47:47 +0900438 allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files))
Jiyong Park09d77522019-11-18 11:16:27 +0900439
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800440 phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output")
Jiyong Park09d77522019-11-18 11:16:27 +0900441 ctx.Build(pctx, android.BuildParams{
442 Rule: diffApexContentRule,
443 Implicits: implicitInputs,
444 Output: phonyOutput,
445 Description: "diff apex image content",
446 Args: map[string]string{
Colin Cross440e0d02020-06-11 11:32:11 -0700447 "allowed_files_file": allowedFilesFile.String(),
448 "image_content_file": imageContentFile.String(),
449 "apex_module_name": a.Name(),
Jiyong Park09d77522019-11-18 11:16:27 +0900450 },
451 })
452
453 implicitInputs = append(implicitInputs, phonyOutput)
454 }
455
456 outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
457 prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
458
Jiyong Park3a1602e2020-01-14 14:39:19 +0900459 imageDir := android.PathForModuleOut(ctx, "image"+suffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900460 if apexType == imageApex {
461 // files and dirs that will be created in APEX
462 var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"}
463 var executablePaths []string // this also includes dirs
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700464 var extractedAppSetPaths android.Paths
465 var extractedAppSetDirs []string
Jiyong Park09d77522019-11-18 11:16:27 +0900466 for _, f := range a.filesInfo {
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900467 pathInApex := f.Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900468 if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
469 executablePaths = append(executablePaths, pathInApex)
Liz Kammer1c14a212020-05-12 15:26:55 -0700470 for _, d := range f.dataPaths {
471 readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.Rel()))
472 }
Jiyong Park09d77522019-11-18 11:16:27 +0900473 for _, s := range f.symlinks {
474 executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
475 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700476 } else if f.class == appSet {
477 extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile)
478 extractedAppSetDirs = append(extractedAppSetDirs, f.installDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900479 } else {
480 readOnlyPaths = append(readOnlyPaths, pathInApex)
481 }
482 dir := f.installDir
483 for !android.InList(dir, executablePaths) && dir != "" {
484 executablePaths = append(executablePaths, dir)
485 dir, _ = filepath.Split(dir) // move up to the parent
486 if len(dir) > 0 {
487 // remove trailing slash
488 dir = dir[:len(dir)-1]
489 }
490 }
491 }
492 sort.Strings(readOnlyPaths)
493 sort.Strings(executablePaths)
494 cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
495 ctx.Build(pctx, android.BuildParams{
496 Rule: generateFsConfig,
497 Output: cannedFsConfig,
498 Description: "generate fs config",
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700499 Inputs: extractedAppSetPaths,
Jiyong Park09d77522019-11-18 11:16:27 +0900500 Args: map[string]string{
501 "ro_paths": strings.Join(readOnlyPaths, " "),
502 "exec_paths": strings.Join(executablePaths, " "),
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700503 "apk_paths": strings.Join(extractedAppSetDirs, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900504 },
505 })
506
Jiyong Park09d77522019-11-18 11:16:27 +0900507 optFlags := []string{}
508
509 // Additional implicit inputs.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900510 implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file)
Jiyong Park09d77522019-11-18 11:16:27 +0900511 optFlags = append(optFlags, "--pubkey "+a.public_key_file.String())
512
Jooyung Han27151d92019-12-16 17:45:32 +0900513 manifestPackageName := a.getOverrideManifestPackageName(ctx)
514 if manifestPackageName != "" {
Jiyong Park09d77522019-11-18 11:16:27 +0900515 optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName)
516 }
517
518 if a.properties.AndroidManifest != nil {
519 androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest))
520 implicitInputs = append(implicitInputs, androidManifestFile)
521 optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String())
522 }
523
524 targetSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe644009a2020-05-20 00:16:27 +0100525 // TODO(b/157078772): propagate min_sdk_version to apexer.
Baligh Uddinf6201372020-01-24 23:15:44 +0000526 minSdkVersion := ctx.Config().DefaultAppTargetSdk()
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000527
Jooyung Han5417f772020-03-12 18:37:20 +0900528 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
529 minSdkVersion = strconv.Itoa(a.minSdkVersion(ctx))
Nikita Ioffe5d600c92020-02-20 00:43:27 +0000530 }
531
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000532 if java.UseApiFingerprint(ctx) {
533 targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000534 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
535 }
Nikita Ioffe1f4f3452020-03-02 16:58:11 +0000536 if java.UseApiFingerprint(ctx) {
537 minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String())
Baligh Uddinf6201372020-01-24 23:15:44 +0000538 implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx))
Jiyong Park09d77522019-11-18 11:16:27 +0900539 }
540 optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion)
Baligh Uddinf6201372020-01-24 23:15:44 +0000541 optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +0900542
Baligh Uddin004d7172020-02-19 21:29:28 -0800543 if a.overridableProperties.Logging_parent != "" {
544 optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent)
545 }
546
Jiyong Park19972c72020-01-28 20:05:29 +0900547 a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix)
548 if a.mergedNotices.HtmlGzOutput.Valid() {
Jiyong Park09d77522019-11-18 11:16:27 +0900549 // If there's a NOTICE file, embed it as an asset file in the APEX.
Jiyong Park19972c72020-01-28 20:05:29 +0900550 implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path())
551 optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String()))
Jiyong Park09d77522019-11-18 11:16:27 +0900552 }
553
Nikita Ioffeb4b44c02020-01-02 23:01:39 +0000554 if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && ctx.ModuleDir() != "system/apex/shim/build" && a.testOnlyShouldSkipHashtreeGeneration() {
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000555 ctx.PropertyErrorf("test_only_no_hashtree", "not available")
556 return
557 }
Jooyung Han5417f772020-03-12 18:37:20 +0900558 if a.minSdkVersion(ctx) > android.SdkVersion_Android10 || a.testOnlyShouldSkipHashtreeGeneration() {
Jiyong Park09d77522019-11-18 11:16:27 +0900559 // Apexes which are supposed to be installed in builtin dirs(/system, etc)
560 // don't need hashtree for activation. Therefore, by removing hashtree from
561 // apex bundle (filesystem image in it, to be specific), we can save storage.
562 optFlags = append(optFlags, "--no_hashtree")
563 }
564
Dario Frenica913392020-04-27 18:21:11 +0100565 if a.testOnlyShouldSkipPayloadSign() {
566 optFlags = append(optFlags, "--unsigned_payload")
567 }
568
Jiyong Park09d77522019-11-18 11:16:27 +0900569 if a.properties.Apex_name != nil {
570 // If apex_name is set, apexer can skip checking if key name matches with apex name.
571 // Note that apex_manifest is also mended.
572 optFlags = append(optFlags, "--do_not_check_keyname")
573 }
574
Jooyung Han5417f772020-03-12 18:37:20 +0900575 if a.minSdkVersion(ctx) == android.SdkVersion_Android10 {
Jooyung Han214bf372019-11-12 13:03:50 +0900576 implicitInputs = append(implicitInputs, a.manifestJsonOut)
577 optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String())
578 }
579
Jiyong Park09d77522019-11-18 11:16:27 +0900580 ctx.Build(pctx, android.BuildParams{
581 Rule: apexRule,
582 Implicits: implicitInputs,
583 Output: unsignedOutputFile,
584 Description: "apex (" + apexType.name() + ")",
585 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900586 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900587 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900588 "copy_commands": strings.Join(copyCommands, " && "),
589 "manifest": a.manifestPbOut.String(),
590 "file_contexts": a.fileContexts.String(),
591 "canned_fs_config": cannedFsConfig.String(),
592 "key": a.private_key_file.String(),
593 "opt_flags": strings.Join(optFlags, " "),
Jiyong Park09d77522019-11-18 11:16:27 +0900594 },
595 })
596
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800597 apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix)
598 bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip")
Jiyong Park09d77522019-11-18 11:16:27 +0900599 a.bundleModuleFile = bundleModuleFile
600
601 ctx.Build(pctx, android.BuildParams{
602 Rule: apexProtoConvertRule,
603 Input: unsignedOutputFile,
604 Output: apexProtoFile,
605 Description: "apex proto convert",
606 })
607
Jiyong Parkbd159612020-02-28 15:22:21 +0900608 bundleConfig := a.buildBundleConfig(ctx)
609
Jiyong Park09d77522019-11-18 11:16:27 +0900610 ctx.Build(pctx, android.BuildParams{
611 Rule: apexBundleRule,
612 Input: apexProtoFile,
Jiyong Parkbd159612020-02-28 15:22:21 +0900613 Implicit: bundleConfig,
Jiyong Park09d77522019-11-18 11:16:27 +0900614 Output: a.bundleModuleFile,
615 Description: "apex bundle module",
616 Args: map[string]string{
Jiyong Parkbd159612020-02-28 15:22:21 +0900617 "abi": strings.Join(abis, "."),
618 "config": bundleConfig.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900619 },
620 })
621 } else {
622 ctx.Build(pctx, android.BuildParams{
623 Rule: zipApexRule,
624 Implicits: implicitInputs,
625 Output: unsignedOutputFile,
626 Description: "apex (" + apexType.name() + ")",
627 Args: map[string]string{
Jooyung Han214bf372019-11-12 13:03:50 +0900628 "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir,
Jiyong Park3a1602e2020-01-14 14:39:19 +0900629 "image_dir": imageDir.String(),
Jooyung Han214bf372019-11-12 13:03:50 +0900630 "copy_commands": strings.Join(copyCommands, " && "),
631 "manifest": a.manifestPbOut.String(),
Jiyong Park09d77522019-11-18 11:16:27 +0900632 },
633 })
634 }
635
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800636 a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix)
Kousik Kumar309b1c02020-05-28 06:13:33 -0700637 rule := java.Signapk
638 args := map[string]string{
639 "certificates": a.container_certificate_file.String() + " " + a.container_private_key_file.String(),
640 "flags": "-a 4096", //alignment
641 }
642 implicits := android.Paths{
643 a.container_certificate_file,
644 a.container_private_key_file,
645 }
646 if ctx.Config().IsEnvTrue("RBE_SIGNAPK") {
647 rule = java.SignapkRE
648 args["implicits"] = strings.Join(implicits.Strings(), ",")
649 args["outCommaList"] = a.outputFile.String()
650 }
Jiyong Park09d77522019-11-18 11:16:27 +0900651 ctx.Build(pctx, android.BuildParams{
Kousik Kumar309b1c02020-05-28 06:13:33 -0700652 Rule: rule,
Jiyong Park09d77522019-11-18 11:16:27 +0900653 Description: "signapk",
654 Output: a.outputFile,
655 Input: unsignedOutputFile,
Kousik Kumar309b1c02020-05-28 06:13:33 -0700656 Implicits: implicits,
657 Args: args,
Jiyong Park09d77522019-11-18 11:16:27 +0900658 })
659
660 // Install to $OUT/soong/{target,host}/.../apex
661 if a.installable() {
Jaewoong Jung1670ca02019-11-22 14:50:42 -0800662 ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900663 }
664 a.buildFilesInfo(ctx)
Jiyong Park3a1602e2020-01-14 14:39:19 +0900665
666 // installed-files.txt is dist'ed
667 a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
Jiyong Park09d77522019-11-18 11:16:27 +0900668}
669
670func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
671 // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
672 // reply true to `InstallBypassMake()` (thus making the call
673 // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
674 // instead of `android.PathForOutput`) to return the correct path to the flattened
675 // APEX (as its contents is installed by Make, not Soong).
676 factx := flattenedApexContext{ctx}
Jiyong Parka5948012020-02-07 10:15:14 +0900677 apexBundleName := a.Name()
678 a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName)
Jiyong Park09d77522019-11-18 11:16:27 +0900679
Jiyong Park317645e2019-12-05 13:20:58 +0900680 if a.installable() && a.GetOverriddenBy() == "" {
Jiyong Parka5948012020-02-07 10:15:14 +0900681 installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName)
Jooyung Han54aca7b2019-11-20 02:26:02 +0900682 devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
Jiyong Parka5948012020-02-07 10:15:14 +0900683 addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900684 }
Jiyong Park09d77522019-11-18 11:16:27 +0900685 a.buildFilesInfo(ctx)
686}
687
688func (a *apexBundle) setCertificateAndPrivateKey(ctx android.ModuleContext) {
Jooyung Hanf121a652019-12-17 14:30:11 +0900689 if a.container_certificate_file == nil {
690 cert := String(a.properties.Certificate)
691 if cert == "" {
692 pem, key := ctx.Config().DefaultAppCertificate(ctx)
693 a.container_certificate_file = pem
694 a.container_private_key_file = key
695 } else {
696 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
697 a.container_certificate_file = defaultDir.Join(ctx, cert+".x509.pem")
698 a.container_private_key_file = defaultDir.Join(ctx, cert+".pk8")
699 }
Jiyong Park09d77522019-11-18 11:16:27 +0900700 }
701}
702
703func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) {
704 if a.installable() {
Jooyung Han214bf372019-11-12 13:03:50 +0900705 // 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 +0900706 // with other ordinary files.
Jiyong Park7cd10e32020-01-14 09:22:18 +0900707 a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900708
709 // rename to apex_pubkey
710 copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey")
711 ctx.Build(pctx, android.BuildParams{
712 Rule: android.Cp,
713 Input: a.public_key_file,
714 Output: copiedPubkey,
715 })
Jiyong Park7cd10e32020-01-14 09:22:18 +0900716 a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil))
Jiyong Park09d77522019-11-18 11:16:27 +0900717
718 if a.properties.ApexType == flattenedApex {
Jiyong Parka5948012020-02-07 10:15:14 +0900719 apexBundleName := a.Name()
Jiyong Park09d77522019-11-18 11:16:27 +0900720 for _, fi := range a.filesInfo {
Jiyong Parka5948012020-02-07 10:15:14 +0900721 dir := filepath.Join("apex", apexBundleName, fi.installDir)
Jiyong Parkf1493cc2020-05-29 21:29:20 +0900722 target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.Stem(), fi.builtFile)
Jiyong Park09d77522019-11-18 11:16:27 +0900723 for _, sym := range fi.symlinks {
724 ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
725 }
726 }
727 }
728 }
729}
Jooyung Han27151d92019-12-16 17:45:32 +0900730
731func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string {
732 // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
733 // to see if it should be overridden because their <apex name> is dynamically generated
734 // according to its VNDK version.
735 if a.vndkApex {
736 overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName)
737 if overridden {
738 return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1)
739 }
740 return ""
741 }
Baligh Uddin5b57dba2020-03-15 13:01:05 -0700742 if a.overridableProperties.Package_name != "" {
743 return a.overridableProperties.Package_name
744 }
Jiyong Park20bacab2020-03-03 11:45:41 +0900745 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jooyung Han27151d92019-12-16 17:45:32 +0900746 if overridden {
747 return manifestPackageName
748 }
749 return ""
750}
Jiyong Park83dc74b2020-01-14 18:38:44 +0900751
752func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
753 if !a.primaryApexType {
754 return
755 }
756
757 if a.properties.IsCoverageVariant {
758 // Otherwise, we will have duplicated rules for coverage and
759 // non-coverage variants of the same APEX
760 return
761 }
762
763 if ctx.Host() {
764 // No need to generate dependency info for host variant
765 return
766 }
767
Artur Satayev872a1442020-04-27 17:08:37 +0100768 depInfos := android.DepNameToDepInfoMap{}
769 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
770 if from.Name() == to.Name() {
771 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
772 // As soon as the dependency graph crosses the APEX boundary, don't go further.
773 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +0900774 }
Jiyong Park83dc74b2020-01-14 18:38:44 +0900775
Artur Satayev872a1442020-04-27 17:08:37 +0100776 if info, exists := depInfos[to.Name()]; exists {
777 if !android.InList(from.Name(), info.From) {
778 info.From = append(info.From, from.Name())
779 }
780 info.IsExternal = info.IsExternal && externalDep
781 depInfos[to.Name()] = info
782 } else {
Artur Satayev480e25b2020-04-27 18:53:18 +0100783 toMinSdkVersion := "(no version)"
784 if m, ok := to.(interface{ MinSdkVersion() string }); ok {
785 if v := m.MinSdkVersion(); v != "" {
786 toMinSdkVersion = v
787 }
788 }
789
Artur Satayev872a1442020-04-27 17:08:37 +0100790 depInfos[to.Name()] = android.ApexModuleDepInfo{
Artur Satayev480e25b2020-04-27 18:53:18 +0100791 To: to.Name(),
792 From: []string{from.Name()},
793 IsExternal: externalDep,
794 MinSdkVersion: toMinSdkVersion,
Artur Satayev872a1442020-04-27 17:08:37 +0100795 }
796 }
797
798 // As soon as the dependency graph crosses the APEX boundary, don't go further.
799 return !externalDep
Jiyong Park83dc74b2020-01-14 18:38:44 +0900800 })
801
Artur Satayev480e25b2020-04-27 18:53:18 +0100802 a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos)
Artur Satayev872a1442020-04-27 17:08:37 +0100803
Jiyong Park83dc74b2020-01-14 18:38:44 +0900804 ctx.Build(pctx, android.BuildParams{
805 Rule: android.Phony,
806 Output: android.PathForPhony(ctx, a.Name()+"-deps-info"),
Artur Satayeva8bd1132020-04-27 18:07:06 +0100807 Inputs: []android.Path{
808 a.ApexBundleDepsInfo.FullListPath(),
809 a.ApexBundleDepsInfo.FlatListPath(),
810 },
Jiyong Park83dc74b2020-01-14 18:38:44 +0900811 })
812}