Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 18 | "encoding/json" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 19 | "fmt" |
| 20 | "path/filepath" |
| 21 | "runtime" |
| 22 | "sort" |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 23 | "strconv" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 24 | "strings" |
| 25 | |
| 26 | "android/soong/android" |
| 27 | "android/soong/java" |
| 28 | |
| 29 | "github.com/google/blueprint" |
| 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
| 33 | var ( |
| 34 | pctx = android.NewPackageContext("android/apex") |
| 35 | ) |
| 36 | |
| 37 | func init() { |
| 38 | pctx.Import("android/soong/android") |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 39 | pctx.Import("android/soong/cc/config") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 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" |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 43 | // projects, and hence cannot build 'aapt2'. Use the SDK prebuilt instead. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 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 Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 49 | return ctx.Config().HostToolPath(ctx, tool).String() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 50 | } |
| 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 Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 65 | pctx.HostBinToolVariable("extract_apks", "extract_apks") |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 66 | pctx.HostBinToolVariable("make_f2fs", "make_f2fs") |
| 67 | pctx.HostBinToolVariable("sload_f2fs", "sload_f2fs") |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 68 | pctx.HostBinToolVariable("make_erofs", "make_erofs") |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 69 | pctx.HostBinToolVariable("apex_compression_tool", "apex_compression_tool") |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 70 | pctx.HostBinToolVariable("dexdeps", "dexdeps") |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 71 | pctx.SourcePathVariable("genNdkUsedbyApexPath", "build/soong/scripts/gen_ndk_usedby_apex.sh") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | var ( |
| 75 | // Create a canned fs config file where all files and directories are |
| 76 | // by default set to (uid/gid/mode) = (1000/1000/0644) |
| 77 | // TODO(b/113082813) make this configurable using config.fs syntax |
| 78 | generateFsConfig = pctx.StaticRule("generateFsConfig", blueprint.RuleParams{ |
LaMont Jones | 4224c62 | 2021-08-05 20:59:17 +0000 | [diff] [blame] | 79 | Command: `( set -e; echo '/ 1000 1000 0755' ` + |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 80 | `&& for i in ${ro_paths}; do echo "/$$i 1000 1000 0644"; done ` + |
| 81 | `&& for i in ${exec_paths}; do echo "/$$i 0 2000 0755"; done ` + |
| 82 | `&& ( 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}`, |
| 83 | Description: "fs_config ${out}", |
| 84 | Rspfile: "$out.apklist", |
| 85 | RspfileContent: "$in", |
| 86 | }, "ro_paths", "exec_paths", "apk_paths") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 87 | |
| 88 | apexManifestRule = pctx.StaticRule("apexManifestRule", blueprint.RuleParams{ |
| 89 | Command: `rm -f $out && ${jsonmodify} $in ` + |
| 90 | `-a provideNativeLibs ${provideNativeLibs} ` + |
| 91 | `-a requireNativeLibs ${requireNativeLibs} ` + |
| 92 | `${opt} ` + |
| 93 | `-o $out`, |
| 94 | CommandDeps: []string{"${jsonmodify}"}, |
| 95 | Description: "prepare ${out}", |
| 96 | }, "provideNativeLibs", "requireNativeLibs", "opt") |
| 97 | |
| 98 | stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ |
| 99 | Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, |
| 100 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 101 | Description: "strip ${in}=>${out}", |
| 102 | }) |
| 103 | |
| 104 | pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ |
| 105 | Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, |
| 106 | CommandDeps: []string{"${conv_apex_manifest}"}, |
| 107 | Description: "convert ${in}=>${out}", |
| 108 | }) |
| 109 | |
Joe Onorato | b4638c1 | 2021-10-27 15:47:06 -0700 | [diff] [blame] | 110 | // TODO(b/113233103): make sure that file_contexts is as expected, i.e., validate |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 111 | // against the binary policy using sefcontext_compiler -p <policy>. |
| 112 | |
| 113 | // TODO(b/114327326): automate the generation of file_contexts |
| 114 | apexRule = pctx.StaticRule("apexRule", blueprint.RuleParams{ |
| 115 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 116 | `(. ${out}.copy_commands) && ` + |
| 117 | `APEXER_TOOL_PATH=${tool_path} ` + |
| 118 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 119 | `--file_contexts ${file_contexts} ` + |
| 120 | `--canned_fs_config ${canned_fs_config} ` + |
Dario Freni | 0f4ae07 | 2020-01-02 15:24:12 +0000 | [diff] [blame] | 121 | `--include_build_info ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 122 | `--payload_type image ` + |
| 123 | `--key ${key} ${opt_flags} ${image_dir} ${out} `, |
| 124 | CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 125 | "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}", |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 126 | "${soong_zip}", "${zipalign}", "${aapt2}", "prebuilts/sdk/current/public/android.jar"}, |
| 127 | Rspfile: "${out}.copy_commands", |
| 128 | RspfileContent: "${copy_commands}", |
| 129 | Description: "APEX ${image_dir} => ${out}", |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 130 | }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 131 | |
| 132 | zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ |
| 133 | Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + |
| 134 | `(. ${out}.copy_commands) && ` + |
| 135 | `APEXER_TOOL_PATH=${tool_path} ` + |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 136 | `${apexer} --force --manifest ${manifest} ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 137 | `--payload_type zip ` + |
| 138 | `${image_dir} ${out} `, |
| 139 | CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, |
| 140 | Rspfile: "${out}.copy_commands", |
| 141 | RspfileContent: "${copy_commands}", |
| 142 | Description: "ZipAPEX ${image_dir} => ${out}", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 143 | }, "tool_path", "image_dir", "copy_commands", "manifest") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 144 | |
| 145 | apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", |
| 146 | blueprint.RuleParams{ |
| 147 | Command: `${aapt2} convert --output-format proto $in -o $out`, |
| 148 | CommandDeps: []string{"${aapt2}"}, |
| 149 | }) |
| 150 | |
| 151 | apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{ |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 152 | Command: `${zip2zip} -i $in -o $out.base ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 153 | `apex_payload.img:apex/${abi}.img ` + |
Dario Freni | da1aefe | 2020-03-02 21:47:09 +0000 | [diff] [blame] | 154 | `apex_build_info.pb:apex/${abi}.build_info.pb ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 155 | `apex_manifest.json:root/apex_manifest.json ` + |
Jiyong Park | 53ae334 | 2019-12-08 02:06:24 +0900 | [diff] [blame] | 156 | `apex_manifest.pb:root/apex_manifest.pb ` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 157 | `AndroidManifest.xml:manifest/AndroidManifest.xml ` + |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 158 | `assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` + |
| 159 | `${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` + |
| 160 | `${merge_zips} $out $out.base $out.config`, |
| 161 | CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"}, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 162 | Description: "app bundle", |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 163 | }, "abi", "config") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 164 | |
| 165 | emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{ |
| 166 | Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`, |
| 167 | Rspfile: "${out}.emit_commands", |
| 168 | RspfileContent: "${emit_commands}", |
| 169 | Description: "Emit APEX image content", |
| 170 | }, "emit_commands") |
| 171 | |
| 172 | diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{ |
| 173 | Command: `diff --unchanged-group-format='' \` + |
| 174 | `--changed-group-format='%<' \` + |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 175 | `${image_content_file} ${allowed_files_file} || (` + |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 176 | `echo -e "New unexpected files were added to ${apex_module_name}." ` + |
| 177 | ` "To fix the build run following command:" && ` + |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 178 | `echo "system/apex/tools/update_allowed_list.sh ${allowed_files_file} ${image_content_file}" && ` + |
Dan Willemsen | 81e43c5 | 2020-01-28 15:40:19 -0800 | [diff] [blame] | 179 | `exit 1); touch ${out}`, |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 180 | Description: "Diff ${image_content_file} and ${allowed_files_file}", |
| 181 | }, "image_content_file", "allowed_files_file", "apex_module_name") |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 182 | |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 183 | generateAPIsUsedbyApexRule = pctx.StaticRule("generateAPIsUsedbyApexRule", blueprint.RuleParams{ |
| 184 | Command: "$genNdkUsedbyApexPath ${image_dir} ${readelf} ${out}", |
| 185 | CommandDeps: []string{"${genNdkUsedbyApexPath}"}, |
| 186 | Description: "Generate symbol list used by Apex", |
| 187 | }, "image_dir", "readelf") |
| 188 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 189 | // Don't add more rules here. Consider using android.NewRuleBuilder instead. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 190 | ) |
| 191 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 192 | // buildManifest creates buile rules to modify the input apex_manifest.json to add information |
| 193 | // gathered by the build system such as provided/required native libraries. Two output files having |
| 194 | // different formats are generated. a.manifestJsonOut is JSON format for Q devices, and |
| 195 | // a.manifest.PbOut is protobuf format for R+ devices. |
| 196 | // TODO(jiyong): make this to return paths instead of directly storing the paths to apexBundle |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 197 | func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, requireNativeLibs []string) { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 198 | src := android.PathForModuleSrc(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 199 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 200 | // Put dependency({provide|require}NativeLibs) in apex_manifest.json |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 201 | provideNativeLibs = android.SortedUniqueStrings(provideNativeLibs) |
| 202 | requireNativeLibs = android.SortedUniqueStrings(android.RemoveListFromList(requireNativeLibs, provideNativeLibs)) |
| 203 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 204 | // APEX name can be overridden |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 205 | optCommands := []string{} |
| 206 | if a.properties.Apex_name != nil { |
| 207 | optCommands = append(optCommands, "-v name "+*a.properties.Apex_name) |
| 208 | } |
| 209 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 210 | // Collect jniLibs. Notice that a.filesInfo is already sorted |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 211 | var jniLibs []string |
| 212 | for _, fi := range a.filesInfo { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 213 | if fi.isJniLib && !android.InList(fi.stem(), jniLibs) { |
| 214 | jniLibs = append(jniLibs, fi.stem()) |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | if len(jniLibs) > 0 { |
| 218 | optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " ")) |
| 219 | } |
| 220 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 221 | manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 222 | ctx.Build(pctx, android.BuildParams{ |
| 223 | Rule: apexManifestRule, |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 224 | Input: src, |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 225 | Output: manifestJsonFullOut, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 226 | Args: map[string]string{ |
| 227 | "provideNativeLibs": strings.Join(provideNativeLibs, " "), |
| 228 | "requireNativeLibs": strings.Join(requireNativeLibs, " "), |
| 229 | "opt": strings.Join(optCommands, " "), |
| 230 | }, |
| 231 | }) |
| 232 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 233 | // b/143654022 Q apexd can't understand newly added keys in apex_manifest.json prepare |
| 234 | // stripped-down version so that APEX modules built from R+ can be installed to Q |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 235 | minSdkVersion := a.minSdkVersion(ctx) |
| 236 | if minSdkVersion.EqualTo(android.SdkVersion_Android10) { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 237 | a.manifestJsonOut = android.PathForModuleOut(ctx, "apex_manifest.json") |
| 238 | ctx.Build(pctx, android.BuildParams{ |
| 239 | Rule: stripApexManifestRule, |
| 240 | Input: manifestJsonFullOut, |
| 241 | Output: a.manifestJsonOut, |
| 242 | }) |
| 243 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 244 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 245 | // From R+, protobuf binary format (.pb) is the standard format for apex_manifest |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 246 | a.manifestPbOut = android.PathForModuleOut(ctx, "apex_manifest.pb") |
| 247 | ctx.Build(pctx, android.BuildParams{ |
| 248 | Rule: pbApexManifestRule, |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 249 | Input: manifestJsonFullOut, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 250 | Output: a.manifestPbOut, |
| 251 | }) |
| 252 | } |
| 253 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 254 | // buildFileContexts create build rules to append an entry for apex_manifest.pb to the file_contexts |
| 255 | // file for this APEX which is either from /systme/sepolicy/apex/<apexname>-file_contexts or from |
| 256 | // the file_contexts property of this APEX. This is to make sure that the manifest file is correctly |
| 257 | // labeled as system_file. |
| 258 | func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) android.OutputPath { |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 259 | var fileContexts android.Path |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 260 | var fileContextsDir string |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 261 | if a.properties.File_contexts == nil { |
| 262 | fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") |
| 263 | } else { |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 264 | if m, t := android.SrcIsModuleWithTag(*a.properties.File_contexts); m != "" { |
| 265 | otherModule := android.GetModuleFromPathDep(ctx, m, t) |
| 266 | fileContextsDir = ctx.OtherModuleDir(otherModule) |
| 267 | } |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 268 | fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) |
| 269 | } |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 270 | if fileContextsDir == "" { |
| 271 | fileContextsDir = filepath.Dir(fileContexts.String()) |
| 272 | } |
| 273 | fileContextsDir += string(filepath.Separator) |
| 274 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 275 | if a.Platform() { |
Liz Kammer | 37997c4 | 2021-09-14 17:53:38 -0400 | [diff] [blame] | 276 | if !strings.HasPrefix(fileContextsDir, "system/sepolicy/") { |
| 277 | ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but found in %q", fileContextsDir) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 281 | ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", fileContexts.String()) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | output := android.PathForModuleOut(ctx, "file_contexts") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 285 | rule := android.NewRuleBuilder(pctx, ctx) |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 286 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 287 | switch a.properties.ApexType { |
| 288 | case imageApex: |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 289 | // remove old file |
| 290 | rule.Command().Text("rm").FlagWithOutput("-f ", output) |
| 291 | // copy file_contexts |
| 292 | rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output) |
| 293 | // new line |
| 294 | rule.Command().Text("echo").Text(">>").Output(output) |
| 295 | // force-label /apex_manifest.pb and / as system_file so that apexd can read them |
| 296 | rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output) |
| 297 | rule.Command().Text("echo").Flag("/ u:object_r:system_file:s0").Text(">>").Output(output) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 298 | case flattenedApex: |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 299 | // For flattened apexes, install path should be prepended. |
| 300 | // File_contexts file should be emiited to make via LOCAL_FILE_CONTEXTS |
| 301 | // so that it can be merged into file_contexts.bin |
| 302 | apexPath := android.InstallPathToOnDevicePath(ctx, a.installDir.Join(ctx, a.Name())) |
| 303 | apexPath = strings.ReplaceAll(apexPath, ".", `\\.`) |
| 304 | // remove old file |
| 305 | rule.Command().Text("rm").FlagWithOutput("-f ", output) |
| 306 | // copy file_contexts |
| 307 | rule.Command().Text("awk").Text(`'/object_r/{printf("` + apexPath + `%s\n", $0)}'`).Input(fileContexts).Text(">").Output(output) |
| 308 | // new line |
| 309 | rule.Command().Text("echo").Text(">>").Output(output) |
| 310 | // force-label /apex_manifest.pb and / as system_file so that apexd can read them |
| 311 | rule.Command().Text("echo").Flag(apexPath + `/apex_manifest\\.pb u:object_r:system_file:s0`).Text(">>").Output(output) |
| 312 | rule.Command().Text("echo").Flag(apexPath + "/ u:object_r:system_file:s0").Text(">>").Output(output) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 313 | default: |
| 314 | panic(fmt.Errorf("unsupported type %v", a.properties.ApexType)) |
Jooyung Han | 7f146c0 | 2020-09-23 19:15:55 +0900 | [diff] [blame] | 315 | } |
| 316 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 317 | rule.Build("file_contexts."+a.Name(), "Generate file_contexts") |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 318 | return output.OutputPath |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 319 | } |
| 320 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 321 | // buildNoticeFiles creates a buile rule for aggregating notice files from the modules that |
| 322 | // contributes to this APEX. The notice files are merged into a big notice file. |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 323 | func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs { |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 324 | var noticeFiles android.Paths |
| 325 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 326 | a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 327 | if externalDep { |
Paul Duffin | be5a5be | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 328 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 329 | return false |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 330 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 331 | noticeFiles = append(noticeFiles, to.NoticeFiles()...) |
Paul Duffin | be5a5be | 2020-03-30 15:54:08 +0100 | [diff] [blame] | 332 | return true |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 333 | }) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 334 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 335 | // TODO(jiyong): why do we need this? WalkPayloadDeps should have already covered this. |
Jiyong Park | 41f637d | 2020-09-09 13:18:02 +0900 | [diff] [blame] | 336 | for _, fi := range a.filesInfo { |
| 337 | noticeFiles = append(noticeFiles, fi.noticeFiles...) |
| 338 | } |
| 339 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 340 | if len(noticeFiles) == 0 { |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 341 | return android.NoticeOutputs{} |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 342 | } |
| 343 | |
Jiyong Park | 33c7736 | 2020-05-29 22:00:16 +0900 | [diff] [blame] | 344 | return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.SortedUniquePaths(noticeFiles)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 345 | } |
| 346 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 347 | // buildInstalledFilesFile creates a build rule for the installed-files.txt file where the list of |
| 348 | // files included in this APEX is shown. The text file is dist'ed so that people can see what's |
| 349 | // included in the APEX without actually downloading and extracting it. |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 350 | func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApex android.Path, imageDir android.Path) android.OutputPath { |
| 351 | output := android.PathForModuleOut(ctx, "installed-files.txt") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 352 | rule := android.NewRuleBuilder(pctx, ctx) |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 353 | rule.Command(). |
| 354 | Implicit(builtApex). |
| 355 | Text("(cd " + imageDir.String() + " ; "). |
Jiyong Park | bd63a10 | 2020-02-08 12:40:05 +0900 | [diff] [blame] | 356 | Text("find . \\( -type f -o -type l \\) -printf \"%s %p\\n\") "). |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 357 | Text(" | sort -nr > "). |
| 358 | Output(output) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 359 | rule.Build("installed-files."+a.Name(), "Installed files") |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 360 | return output.OutputPath |
| 361 | } |
| 362 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 363 | // buildBundleConfig creates a build rule for the bundle config file that will control the bundle |
| 364 | // creation process. |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 365 | func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath { |
| 366 | output := android.PathForModuleOut(ctx, "bundle_config.json") |
| 367 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 368 | type ApkConfig struct { |
| 369 | Package_name string `json:"package_name"` |
| 370 | Apk_path string `json:"path"` |
| 371 | } |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 372 | config := struct { |
| 373 | Compression struct { |
| 374 | Uncompressed_glob []string `json:"uncompressed_glob"` |
| 375 | } `json:"compression"` |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 376 | Apex_config struct { |
| 377 | Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"` |
| 378 | } `json:"apex_config,omitempty"` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 379 | }{} |
| 380 | |
| 381 | config.Compression.Uncompressed_glob = []string{ |
| 382 | "apex_payload.img", |
| 383 | "apex_manifest.*", |
| 384 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 385 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 386 | // Collect the manifest names and paths of android apps if their manifest names are |
| 387 | // overridden. |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 388 | for _, fi := range a.filesInfo { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 389 | if fi.class != app && fi.class != appSet { |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 390 | continue |
| 391 | } |
| 392 | packageName := fi.overriddenPackageName |
| 393 | if packageName != "" { |
| 394 | config.Apex_config.Apex_embedded_apk_config = append( |
| 395 | config.Apex_config.Apex_embedded_apk_config, |
| 396 | ApkConfig{ |
| 397 | Package_name: packageName, |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 398 | Apk_path: fi.path(), |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 399 | }) |
| 400 | } |
| 401 | } |
| 402 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 403 | j, err := json.Marshal(config) |
| 404 | if err != nil { |
| 405 | panic(fmt.Errorf("error while marshalling to %q: %#v", output, err)) |
| 406 | } |
| 407 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 408 | android.WriteFileRule(ctx, output, string(j)) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 409 | |
| 410 | return output.OutputPath |
| 411 | } |
| 412 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 413 | // buildUnflattendApex creates build rules to build an APEX using apexer. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 414 | func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 415 | apexType := a.properties.ApexType |
| 416 | suffix := apexType.suffix() |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 417 | apexName := proptools.StringDefault(a.properties.Apex_name, a.BaseModuleName()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 418 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 419 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 420 | // Step 1: copy built files to appropriate directories under the image directory |
| 421 | |
| 422 | imageDir := android.PathForModuleOut(ctx, "image"+suffix) |
| 423 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 424 | installSymbolFiles := !ctx.Config().KatiEnabled() || a.ExportedToMake() |
| 425 | |
| 426 | // b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden |
| 427 | // APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver> |
| 428 | // as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files |
| 429 | // for the overriding VNDK APEXes. |
| 430 | if a.vndkApex && len(a.overridableProperties.Overrides) > 0 { |
| 431 | installSymbolFiles = false |
| 432 | } |
| 433 | |
| 434 | // Avoid creating duplicate build rules for multi-installed APEXes. |
| 435 | if proptools.BoolDefault(a.properties.Multi_install_skip_symbol_files, false) { |
| 436 | installSymbolFiles = false |
| 437 | } |
| 438 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 439 | // TODO(jiyong): use the RuleBuilder |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 440 | var copyCommands []string |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 441 | var implicitInputs []android.Path |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 442 | pathWhenActivated := android.PathForModuleInPartitionInstall(ctx, "apex", apexName) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 443 | for _, fi := range a.filesInfo { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 444 | destPath := imageDir.Join(ctx, fi.path()).String() |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 445 | var installedPath android.InstallPath |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 446 | // Prepare the destination path |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 447 | destPathDir := filepath.Dir(destPath) |
| 448 | if fi.class == appSet { |
| 449 | copyCommands = append(copyCommands, "rm -rf "+destPathDir) |
| 450 | } |
| 451 | copyCommands = append(copyCommands, "mkdir -p "+destPathDir) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 452 | |
| 453 | // Copy the built file to the directory. But if the symlink optimization is turned |
| 454 | // on, place a symlink to the corresponding file in /system partition instead. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 455 | if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 456 | // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 457 | pathOnDevice := filepath.Join("/system", fi.path()) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 458 | copyCommands = append(copyCommands, "ln -sfn "+pathOnDevice+" "+destPath) |
| 459 | } else { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 460 | if fi.class == appSet { |
| 461 | copyCommands = append(copyCommands, |
Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 462 | fmt.Sprintf("unzip -qDD -d %s %s", destPathDir, |
| 463 | fi.module.(*java.AndroidAppSet).PackedAdditionalOutputs().String())) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 464 | if installSymbolFiles { |
| 465 | installedPath = ctx.InstallFileWithExtraFilesZip(pathWhenActivated.Join(ctx, fi.installDir), |
| 466 | fi.stem(), fi.builtFile, fi.module.(*java.AndroidAppSet).PackedAdditionalOutputs()) |
| 467 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 468 | } else { |
| 469 | copyCommands = append(copyCommands, "cp -f "+fi.builtFile.String()+" "+destPath) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 470 | if installSymbolFiles { |
| 471 | installedPath = ctx.InstallFile(pathWhenActivated.Join(ctx, fi.installDir), fi.stem(), fi.builtFile) |
| 472 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 473 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 474 | implicitInputs = append(implicitInputs, fi.builtFile) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 475 | if installSymbolFiles { |
| 476 | implicitInputs = append(implicitInputs, installedPath) |
| 477 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 478 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 479 | |
| 480 | // Create additional symlinks pointing the file inside the APEX (if any). Note that |
| 481 | // this is independent from the symlink optimization. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 482 | for _, symlinkPath := range fi.symlinkPaths() { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 483 | symlinkDest := imageDir.Join(ctx, symlinkPath).String() |
Tim Joines | c1ef1bb | 2020-03-18 18:00:41 +0000 | [diff] [blame] | 484 | copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 485 | if installSymbolFiles { |
| 486 | installedSymlink := ctx.InstallSymlink(pathWhenActivated.Join(ctx, filepath.Dir(symlinkPath)), filepath.Base(symlinkPath), installedPath) |
| 487 | implicitInputs = append(implicitInputs, installedSymlink) |
| 488 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 489 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 490 | |
| 491 | // Copy the test files (if any) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 492 | for _, d := range fi.dataPaths { |
| 493 | // TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 494 | relPath := d.SrcPath.Rel() |
| 495 | dataPath := d.SrcPath.String() |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 496 | if !strings.HasSuffix(dataPath, relPath) { |
| 497 | panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath)) |
| 498 | } |
| 499 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 500 | dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath), d.RelativeInstallPath).String() |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 501 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 502 | copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest) |
| 503 | implicitInputs = append(implicitInputs, d.SrcPath) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 504 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 505 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 506 | implicitInputs = append(implicitInputs, a.manifestPbOut) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 507 | if installSymbolFiles { |
| 508 | installedManifest := ctx.InstallFile(pathWhenActivated, "apex_manifest.pb", a.manifestPbOut) |
| 509 | installedKey := ctx.InstallFile(pathWhenActivated, "apex_pubkey", a.publicKeyFile) |
| 510 | implicitInputs = append(implicitInputs, installedManifest, installedKey) |
| 511 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 512 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 513 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 514 | // Step 1.a: Write the list of files in this APEX to a txt file and compare it against |
| 515 | // the allowed list given via the allowed_files property. Build fails when the two lists |
| 516 | // differ. |
| 517 | // |
| 518 | // TODO(jiyong): consider removing this. Nobody other than com.android.apex.cts.shim.* seems |
| 519 | // to be using this at this moment. Furthermore, this looks very similar to what |
| 520 | // buildInstalledFilesFile does. At least, move this to somewhere else so that this doesn't |
| 521 | // hurt readability. |
| 522 | // TODO(jiyong): use RuleBuilder |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 523 | if a.overridableProperties.Allowed_files != nil { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 524 | // Build content.txt |
| 525 | var emitCommands []string |
| 526 | imageContentFile := android.PathForModuleOut(ctx, "content.txt") |
| 527 | emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String()) |
| 528 | minSdkVersion := a.minSdkVersion(ctx) |
| 529 | if minSdkVersion.EqualTo(android.SdkVersion_Android10) { |
| 530 | emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String()) |
| 531 | } |
| 532 | for _, fi := range a.filesInfo { |
| 533 | emitCommands = append(emitCommands, "echo './"+fi.path()+"' >> "+imageContentFile.String()) |
| 534 | } |
| 535 | emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 536 | ctx.Build(pctx, android.BuildParams{ |
| 537 | Rule: emitApexContentRule, |
| 538 | Implicits: implicitInputs, |
| 539 | Output: imageContentFile, |
| 540 | Description: "emit apex image content", |
| 541 | Args: map[string]string{ |
| 542 | "emit_commands": strings.Join(emitCommands, " && "), |
| 543 | }, |
| 544 | }) |
| 545 | implicitInputs = append(implicitInputs, imageContentFile) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 546 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 547 | // Compare content.txt against allowed_files. |
| 548 | allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files)) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 549 | phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 550 | ctx.Build(pctx, android.BuildParams{ |
| 551 | Rule: diffApexContentRule, |
| 552 | Implicits: implicitInputs, |
| 553 | Output: phonyOutput, |
| 554 | Description: "diff apex image content", |
| 555 | Args: map[string]string{ |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 556 | "allowed_files_file": allowedFilesFile.String(), |
| 557 | "image_content_file": imageContentFile.String(), |
| 558 | "apex_module_name": a.Name(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 559 | }, |
| 560 | }) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 561 | implicitInputs = append(implicitInputs, phonyOutput) |
| 562 | } |
| 563 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 564 | unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned") |
Colin Cross | 790ef35 | 2021-10-25 19:15:55 -0700 | [diff] [blame] | 565 | outHostBinDir := ctx.Config().HostToolPath(ctx, "").String() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 566 | prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") |
| 567 | |
Nikita Ioffe | bc03588 | 2021-04-14 21:35:24 +0100 | [diff] [blame] | 568 | // Figure out if need to compress apex. |
Nikita Ioffe | b6ea6c2 | 2021-04-19 13:07:24 +0100 | [diff] [blame] | 569 | compressionEnabled := ctx.Config().CompressedApex() && proptools.BoolDefault(a.properties.Compressible, false) && !a.testApex && !ctx.Config().UnbundledBuildApps() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 570 | if apexType == imageApex { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 571 | //////////////////////////////////////////////////////////////////////////////////// |
| 572 | // Step 2: create canned_fs_config which encodes filemode,uid,gid of each files |
| 573 | // in this APEX. The file will be used by apexer in later steps. |
| 574 | // TODO(jiyong): make this as a function |
| 575 | // TODO(jiyong): use the RuleBuilder |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 576 | var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"} |
| 577 | var executablePaths []string // this also includes dirs |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 578 | var extractedAppSetPaths android.Paths |
| 579 | var extractedAppSetDirs []string |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 580 | for _, f := range a.filesInfo { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 581 | pathInApex := f.path() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 582 | if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") { |
| 583 | executablePaths = append(executablePaths, pathInApex) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 584 | for _, d := range f.dataPaths { |
Liz Kammer | 0a51aa2 | 2020-07-21 11:13:17 -0700 | [diff] [blame] | 585 | readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.RelativeInstallPath, d.SrcPath.Rel())) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 586 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 587 | for _, s := range f.symlinks { |
| 588 | executablePaths = append(executablePaths, filepath.Join(f.installDir, s)) |
| 589 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 590 | } else if f.class == appSet { |
| 591 | extractedAppSetPaths = append(extractedAppSetPaths, f.builtFile) |
| 592 | extractedAppSetDirs = append(extractedAppSetDirs, f.installDir) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 593 | } else { |
| 594 | readOnlyPaths = append(readOnlyPaths, pathInApex) |
| 595 | } |
| 596 | dir := f.installDir |
| 597 | for !android.InList(dir, executablePaths) && dir != "" { |
| 598 | executablePaths = append(executablePaths, dir) |
| 599 | dir, _ = filepath.Split(dir) // move up to the parent |
| 600 | if len(dir) > 0 { |
| 601 | // remove trailing slash |
| 602 | dir = dir[:len(dir)-1] |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | sort.Strings(readOnlyPaths) |
| 607 | sort.Strings(executablePaths) |
| 608 | cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") |
| 609 | ctx.Build(pctx, android.BuildParams{ |
| 610 | Rule: generateFsConfig, |
| 611 | Output: cannedFsConfig, |
| 612 | Description: "generate fs config", |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 613 | Inputs: extractedAppSetPaths, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 614 | Args: map[string]string{ |
| 615 | "ro_paths": strings.Join(readOnlyPaths, " "), |
| 616 | "exec_paths": strings.Join(executablePaths, " "), |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 617 | "apk_paths": strings.Join(extractedAppSetDirs, " "), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 618 | }, |
| 619 | }) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 620 | implicitInputs = append(implicitInputs, cannedFsConfig) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 621 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 622 | //////////////////////////////////////////////////////////////////////////////////// |
| 623 | // Step 3: Prepare option flags for apexer and invoke it to create an unsigned APEX. |
| 624 | // TODO(jiyong): use the RuleBuilder |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 625 | optFlags := []string{} |
| 626 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 627 | fileContexts := a.buildFileContexts(ctx) |
| 628 | implicitInputs = append(implicitInputs, fileContexts) |
| 629 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 630 | implicitInputs = append(implicitInputs, a.privateKeyFile, a.publicKeyFile) |
| 631 | optFlags = append(optFlags, "--pubkey "+a.publicKeyFile.String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 632 | |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 633 | manifestPackageName := a.getOverrideManifestPackageName(ctx) |
| 634 | if manifestPackageName != "" { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 635 | optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) |
| 636 | } |
| 637 | |
| 638 | if a.properties.AndroidManifest != nil { |
| 639 | androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) |
| 640 | implicitInputs = append(implicitInputs, androidManifestFile) |
| 641 | optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) |
| 642 | } |
| 643 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 644 | // Determine target/min sdk version from the context |
| 645 | // TODO(jiyong): make this as a function |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 646 | moduleMinSdkVersion := a.minSdkVersion(ctx) |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 647 | minSdkVersion := moduleMinSdkVersion.String() |
| 648 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 649 | // bundletool doesn't understand what "current" is. We need to transform it to |
| 650 | // codename |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 651 | if moduleMinSdkVersion.IsCurrent() || moduleMinSdkVersion.IsNone() { |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 652 | minSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String() |
Liz Kammer | 4854a7d | 2021-05-27 14:28:27 -0400 | [diff] [blame] | 653 | |
| 654 | if java.UseApiFingerprint(ctx) { |
| 655 | minSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String()) |
| 656 | implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx)) |
| 657 | } |
Nikita Ioffe | 5d600c9 | 2020-02-20 00:43:27 +0000 | [diff] [blame] | 658 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 659 | // apex module doesn't have a concept of target_sdk_version, hence for the time |
| 660 | // being targetSdkVersion == default targetSdkVersion of the branch. |
Nikita Ioffe | 5335bc4 | 2020-10-20 00:02:15 +0100 | [diff] [blame] | 661 | targetSdkVersion := strconv.Itoa(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt()) |
Nikita Ioffe | 5d600c9 | 2020-02-20 00:43:27 +0000 | [diff] [blame] | 662 | |
Nikita Ioffe | 1f4f345 | 2020-03-02 16:58:11 +0000 | [diff] [blame] | 663 | if java.UseApiFingerprint(ctx) { |
| 664 | targetSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", java.ApiFingerprintPath(ctx).String()) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 665 | implicitInputs = append(implicitInputs, java.ApiFingerprintPath(ctx)) |
| 666 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 667 | optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) |
Baligh Uddin | f620137 | 2020-01-24 23:15:44 +0000 | [diff] [blame] | 668 | optFlags = append(optFlags, "--min_sdk_version "+minSdkVersion) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 669 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 670 | if a.overridableProperties.Logging_parent != "" { |
| 671 | optFlags = append(optFlags, "--logging_parent ", a.overridableProperties.Logging_parent) |
| 672 | } |
| 673 | |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 674 | a.mergedNotices = a.buildNoticeFiles(ctx, a.Name()+suffix) |
| 675 | if a.mergedNotices.HtmlGzOutput.Valid() { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 676 | // If there's a NOTICE file, embed it as an asset file in the APEX. |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 677 | implicitInputs = append(implicitInputs, a.mergedNotices.HtmlGzOutput.Path()) |
| 678 | optFlags = append(optFlags, "--assets_dir "+filepath.Dir(a.mergedNotices.HtmlGzOutput.String())) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 679 | } |
| 680 | |
Nikita Ioffe | 9d9960f | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 681 | if (moduleMinSdkVersion.GreaterThan(android.SdkVersion_Android10) && !a.shouldGenerateHashtree()) && !compressionEnabled { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 682 | // Apexes which are supposed to be installed in builtin dirs(/system, etc) |
| 683 | // don't need hashtree for activation. Therefore, by removing hashtree from |
| 684 | // apex bundle (filesystem image in it, to be specific), we can save storage. |
| 685 | optFlags = append(optFlags, "--no_hashtree") |
| 686 | } |
| 687 | |
Dario Freni | ca91339 | 2020-04-27 18:21:11 +0100 | [diff] [blame] | 688 | if a.testOnlyShouldSkipPayloadSign() { |
| 689 | optFlags = append(optFlags, "--unsigned_payload") |
| 690 | } |
| 691 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 692 | if a.properties.Apex_name != nil { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 693 | // If apex_name is set, apexer can skip checking if key name matches with |
| 694 | // apex name. Note that apex_manifest is also mended. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 695 | optFlags = append(optFlags, "--do_not_check_keyname") |
| 696 | } |
| 697 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 698 | if moduleMinSdkVersion == android.SdkVersion_Android10 { |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 699 | implicitInputs = append(implicitInputs, a.manifestJsonOut) |
| 700 | optFlags = append(optFlags, "--manifest_json "+a.manifestJsonOut.String()) |
| 701 | } |
| 702 | |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 703 | optFlags = append(optFlags, "--payload_fs_type "+a.payloadFsType.string()) |
| 704 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 705 | ctx.Build(pctx, android.BuildParams{ |
| 706 | Rule: apexRule, |
| 707 | Implicits: implicitInputs, |
| 708 | Output: unsignedOutputFile, |
| 709 | Description: "apex (" + apexType.name() + ")", |
| 710 | Args: map[string]string{ |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 711 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 712 | "image_dir": imageDir.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 713 | "copy_commands": strings.Join(copyCommands, " && "), |
| 714 | "manifest": a.manifestPbOut.String(), |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 715 | "file_contexts": fileContexts.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 716 | "canned_fs_config": cannedFsConfig.String(), |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 717 | "key": a.privateKeyFile.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 718 | "opt_flags": strings.Join(optFlags, " "), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 719 | }, |
| 720 | }) |
| 721 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 722 | // TODO(jiyong): make the two rules below as separate functions |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 723 | apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix) |
| 724 | bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 725 | a.bundleModuleFile = bundleModuleFile |
| 726 | |
| 727 | ctx.Build(pctx, android.BuildParams{ |
| 728 | Rule: apexProtoConvertRule, |
| 729 | Input: unsignedOutputFile, |
| 730 | Output: apexProtoFile, |
| 731 | Description: "apex proto convert", |
| 732 | }) |
| 733 | |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 734 | implicitInputs = append(implicitInputs, unsignedOutputFile) |
| 735 | |
| 736 | // Run coverage analysis |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 737 | apisUsedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_using.txt") |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 738 | ctx.Build(pctx, android.BuildParams{ |
| 739 | Rule: generateAPIsUsedbyApexRule, |
| 740 | Implicits: implicitInputs, |
| 741 | Description: "coverage", |
| 742 | Output: apisUsedbyOutputFile, |
| 743 | Args: map[string]string{ |
| 744 | "image_dir": imageDir.String(), |
| 745 | "readelf": "${config.ClangBin}/llvm-readelf", |
| 746 | }, |
| 747 | }) |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 748 | a.nativeApisUsedByModuleFile = apisUsedbyOutputFile |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 749 | |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 750 | var nativeLibNames []string |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame] | 751 | for _, f := range a.filesInfo { |
| 752 | if f.class == nativeSharedLib { |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 753 | nativeLibNames = append(nativeLibNames, f.stem()) |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame] | 754 | } |
| 755 | } |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 756 | apisBackedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_backing.txt") |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 757 | rule := android.NewRuleBuilder(pctx, ctx) |
| 758 | rule.Command(). |
| 759 | Tool(android.PathForSource(ctx, "build/soong/scripts/gen_ndk_backedby_apex.sh")). |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 760 | Output(apisBackedbyOutputFile). |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 761 | Flags(nativeLibNames) |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 762 | rule.Build("ndk_backedby_list", "Generate API libraries backed by Apex") |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 763 | a.nativeApisBackedByModuleFile = apisBackedbyOutputFile |
| 764 | |
| 765 | var javaLibOrApkPath []android.Path |
| 766 | for _, f := range a.filesInfo { |
| 767 | if f.class == javaSharedLib || f.class == app { |
| 768 | javaLibOrApkPath = append(javaLibOrApkPath, f.builtFile) |
| 769 | } |
| 770 | } |
| 771 | javaApiUsedbyOutputFile := android.PathForModuleOut(ctx, a.Name()+"_using.xml") |
| 772 | javaUsedByRule := android.NewRuleBuilder(pctx, ctx) |
| 773 | javaUsedByRule.Command(). |
| 774 | Tool(android.PathForSource(ctx, "build/soong/scripts/gen_java_usedby_apex.sh")). |
| 775 | BuiltTool("dexdeps"). |
| 776 | Output(javaApiUsedbyOutputFile). |
| 777 | Inputs(javaLibOrApkPath) |
| 778 | javaUsedByRule.Build("java_usedby_list", "Generate Java APIs used by Apex") |
| 779 | a.javaApisUsedByModuleFile = javaApiUsedbyOutputFile |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 780 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 781 | bundleConfig := a.buildBundleConfig(ctx) |
| 782 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 783 | var abis []string |
| 784 | for _, target := range ctx.MultiTargets() { |
| 785 | if len(target.Arch.Abi) > 0 { |
| 786 | abis = append(abis, target.Arch.Abi[0]) |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | abis = android.FirstUniqueStrings(abis) |
| 791 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 792 | ctx.Build(pctx, android.BuildParams{ |
| 793 | Rule: apexBundleRule, |
| 794 | Input: apexProtoFile, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 795 | Implicit: bundleConfig, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 796 | Output: a.bundleModuleFile, |
| 797 | Description: "apex bundle module", |
| 798 | Args: map[string]string{ |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 799 | "abi": strings.Join(abis, "."), |
| 800 | "config": bundleConfig.String(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 801 | }, |
| 802 | }) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 803 | } else { // zipApex |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 804 | ctx.Build(pctx, android.BuildParams{ |
| 805 | Rule: zipApexRule, |
| 806 | Implicits: implicitInputs, |
| 807 | Output: unsignedOutputFile, |
| 808 | Description: "apex (" + apexType.name() + ")", |
| 809 | Args: map[string]string{ |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 810 | "tool_path": outHostBinDir + ":" + prebuiltSdkToolsBinDir, |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 811 | "image_dir": imageDir.String(), |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 812 | "copy_commands": strings.Join(copyCommands, " && "), |
| 813 | "manifest": a.manifestPbOut.String(), |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 814 | }, |
| 815 | }) |
| 816 | } |
| 817 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 818 | //////////////////////////////////////////////////////////////////////////////////// |
| 819 | // Step 4: Sign the APEX using signapk |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 820 | signedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 821 | |
| 822 | pem, key := a.getCertificateAndPrivateKey(ctx) |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 823 | rule := java.Signapk |
| 824 | args := map[string]string{ |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 825 | "certificates": pem.String() + " " + key.String(), |
Jooyung Han | 5d00f50 | 2021-07-11 07:26:22 +0900 | [diff] [blame] | 826 | "flags": "-a 4096 --align-file-size", //alignment |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 827 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 828 | implicits := android.Paths{pem, key} |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 829 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") { |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 830 | rule = java.SignapkRE |
| 831 | args["implicits"] = strings.Join(implicits.Strings(), ",") |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 832 | args["outCommaList"] = signedOutputFile.String() |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 833 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 834 | ctx.Build(pctx, android.BuildParams{ |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 835 | Rule: rule, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 836 | Description: "signapk", |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 837 | Output: signedOutputFile, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 838 | Input: unsignedOutputFile, |
Kousik Kumar | 309b1c0 | 2020-05-28 06:13:33 -0700 | [diff] [blame] | 839 | Implicits: implicits, |
| 840 | Args: args, |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 841 | }) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 842 | a.outputFile = signedOutputFile |
| 843 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 844 | if ctx.ModuleDir() != "system/apex/apexd/apexd_testdata" && a.testOnlyShouldForceCompression() { |
| 845 | ctx.PropertyErrorf("test_only_force_compression", "not available") |
| 846 | return |
| 847 | } |
Nikita Ioffe | bc03588 | 2021-04-14 21:35:24 +0100 | [diff] [blame] | 848 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 849 | if apexType == imageApex && (compressionEnabled || a.testOnlyShouldForceCompression()) { |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 850 | a.isCompressed = true |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 851 | unsignedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix+".unsigned") |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 852 | |
| 853 | compressRule := android.NewRuleBuilder(pctx, ctx) |
| 854 | compressRule.Command(). |
| 855 | Text("rm"). |
| 856 | FlagWithOutput("-f ", unsignedCompressedOutputFile) |
| 857 | compressRule.Command(). |
| 858 | BuiltTool("apex_compression_tool"). |
| 859 | Flag("compress"). |
| 860 | FlagWithArg("--apex_compression_tool ", outHostBinDir+":"+prebuiltSdkToolsBinDir). |
| 861 | FlagWithInput("--input ", signedOutputFile). |
| 862 | FlagWithOutput("--output ", unsignedCompressedOutputFile) |
| 863 | compressRule.Build("compressRule", "Generate unsigned compressed APEX file") |
| 864 | |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 865 | signedCompressedOutputFile := android.PathForModuleOut(ctx, a.Name()+imageCapexSuffix) |
Mohammad Samiul Islam | 9ac0e32 | 2021-01-19 11:32:29 +0000 | [diff] [blame] | 866 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_SIGNAPK") { |
| 867 | args["outCommaList"] = signedCompressedOutputFile.String() |
| 868 | } |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 869 | ctx.Build(pctx, android.BuildParams{ |
| 870 | Rule: rule, |
| 871 | Description: "sign compressedApex", |
| 872 | Output: signedCompressedOutputFile, |
| 873 | Input: unsignedCompressedOutputFile, |
| 874 | Implicits: implicits, |
| 875 | Args: args, |
| 876 | }) |
| 877 | a.outputFile = signedCompressedOutputFile |
| 878 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 879 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 880 | installSuffix := suffix |
| 881 | if a.isCompressed { |
| 882 | installSuffix = imageCapexSuffix |
| 883 | } |
| 884 | |
Jiyong Park | 17ff283 | 2021-09-27 12:50:30 +0900 | [diff] [blame] | 885 | // Install to $OUT/soong/{target,host}/.../apex. |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 886 | a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile, |
| 887 | a.compatSymlinks.Paths()...) |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 888 | |
| 889 | // installed-files.txt is dist'ed |
| 890 | a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 891 | } |
| 892 | |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 893 | // buildFlattenedApex creates rules for a flattened APEX. Flattened APEX actually doesn't have a |
| 894 | // single output file. It is a phony target for all the files under /system/apex/<name> directory. |
| 895 | // This function creates the installation rules for the files. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 896 | func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 897 | bundleName := a.Name() |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 898 | installedSymlinks := append(android.InstallPaths(nil), a.compatSymlinks...) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 899 | if a.installable() { |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 900 | for _, fi := range a.filesInfo { |
| 901 | dir := filepath.Join("apex", bundleName, fi.installDir) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 902 | installDir := android.PathForModuleInstall(ctx, dir) |
| 903 | if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() { |
| 904 | // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here |
| 905 | pathOnDevice := filepath.Join("/system", fi.path()) |
| 906 | installedSymlinks = append(installedSymlinks, |
| 907 | ctx.InstallAbsoluteSymlink(installDir, fi.stem(), pathOnDevice)) |
| 908 | } else { |
| 909 | target := ctx.InstallFile(installDir, fi.stem(), fi.builtFile) |
| 910 | for _, sym := range fi.symlinks { |
| 911 | installedSymlinks = append(installedSymlinks, |
| 912 | ctx.InstallSymlink(installDir, sym, target)) |
| 913 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 914 | } |
| 915 | } |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 916 | |
| 917 | // Create install rules for the files added in GenerateAndroidBuildActions after |
| 918 | // buildFlattenedApex is called. Add the links to system libs (if any) as dependencies |
| 919 | // of the apex_manifest.pb file since it is always present. |
| 920 | dir := filepath.Join("apex", bundleName) |
| 921 | installDir := android.PathForModuleInstall(ctx, dir) |
| 922 | ctx.InstallFile(installDir, "apex_manifest.pb", a.manifestPbOut, installedSymlinks.Paths()...) |
| 923 | ctx.InstallFile(installDir, "apex_pubkey", a.publicKeyFile) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 924 | } |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 925 | |
| 926 | a.fileContexts = a.buildFileContexts(ctx) |
| 927 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame^] | 928 | a.outputFile = android.PathForModuleInstall(ctx, "apex", bundleName) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // getCertificateAndPrivateKey retrieves the cert and the private key that will be used to sign |
| 932 | // the zip container of this APEX. See the description of the 'certificate' property for how |
| 933 | // the cert and the private key are found. |
| 934 | func (a *apexBundle) getCertificateAndPrivateKey(ctx android.PathContext) (pem, key android.Path) { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 935 | if a.containerCertificateFile != nil { |
| 936 | return a.containerCertificateFile, a.containerPrivateKeyFile |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 937 | } |
| 938 | |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 939 | cert := String(a.overridableProperties.Certificate) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 940 | if cert == "" { |
| 941 | return ctx.Config().DefaultAppCertificate(ctx) |
| 942 | } |
| 943 | |
| 944 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 945 | pem = defaultDir.Join(ctx, cert+".x509.pem") |
| 946 | key = defaultDir.Join(ctx, cert+".pk8") |
| 947 | return pem, key |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 948 | } |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 949 | |
| 950 | func (a *apexBundle) getOverrideManifestPackageName(ctx android.ModuleContext) string { |
| 951 | // For VNDK APEXes, check "com.android.vndk" in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES |
| 952 | // to see if it should be overridden because their <apex name> is dynamically generated |
| 953 | // according to its VNDK version. |
| 954 | if a.vndkApex { |
| 955 | overrideName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(vndkApexName) |
| 956 | if overridden { |
| 957 | return strings.Replace(*a.properties.Apex_name, vndkApexName, overrideName, 1) |
| 958 | } |
| 959 | return "" |
| 960 | } |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 961 | if a.overridableProperties.Package_name != "" { |
| 962 | return a.overridableProperties.Package_name |
| 963 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 964 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 965 | if overridden { |
| 966 | return manifestPackageName |
| 967 | } |
| 968 | return "" |
| 969 | } |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 970 | |
| 971 | func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { |
| 972 | if !a.primaryApexType { |
| 973 | return |
| 974 | } |
| 975 | |
| 976 | if a.properties.IsCoverageVariant { |
| 977 | // Otherwise, we will have duplicated rules for coverage and |
| 978 | // non-coverage variants of the same APEX |
| 979 | return |
| 980 | } |
| 981 | |
| 982 | if ctx.Host() { |
| 983 | // No need to generate dependency info for host variant |
| 984 | return |
| 985 | } |
| 986 | |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 987 | depInfos := android.DepNameToDepInfoMap{} |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 988 | a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 989 | if from.Name() == to.Name() { |
| 990 | // This can happen for cc.reuseObjTag. We are not interested in tracking this. |
| 991 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 992 | return !externalDep |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 993 | } |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 994 | |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 995 | // Skip dependencies that are only available to APEXes; they are developed with updatability |
| 996 | // in mind and don't need manual approval. |
| 997 | if to.(android.ApexModule).NotAvailableForPlatform() { |
| 998 | return !externalDep |
| 999 | } |
| 1000 | |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 1001 | depTag := ctx.OtherModuleDependencyTag(to) |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 1002 | // Check to see if dependency been marked to skip the dependency check |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 1003 | if skipDepCheck, ok := depTag.(android.SkipApexAllowedDependenciesCheck); ok && skipDepCheck.SkipApexAllowedDependenciesCheck() { |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 1004 | return !externalDep |
| 1005 | } |
| 1006 | |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 1007 | if info, exists := depInfos[to.Name()]; exists { |
| 1008 | if !android.InList(from.Name(), info.From) { |
| 1009 | info.From = append(info.From, from.Name()) |
| 1010 | } |
| 1011 | info.IsExternal = info.IsExternal && externalDep |
| 1012 | depInfos[to.Name()] = info |
| 1013 | } else { |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 1014 | toMinSdkVersion := "(no version)" |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1015 | if m, ok := to.(interface { |
| 1016 | MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec |
| 1017 | }); ok { |
| 1018 | if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() { |
| 1019 | toMinSdkVersion = v.ApiLevel.String() |
| 1020 | } |
| 1021 | } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { |
| 1022 | // TODO(b/175678607) eliminate the use of MinSdkVersion returning |
| 1023 | // string |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 1024 | if v := m.MinSdkVersion(); v != "" { |
| 1025 | toMinSdkVersion = v |
| 1026 | } |
| 1027 | } |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 1028 | depInfos[to.Name()] = android.ApexModuleDepInfo{ |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 1029 | To: to.Name(), |
| 1030 | From: []string{from.Name()}, |
| 1031 | IsExternal: externalDep, |
| 1032 | MinSdkVersion: toMinSdkVersion, |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 1037 | return !externalDep |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1038 | }) |
| 1039 | |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 1040 | a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, proptools.String(a.properties.Min_sdk_version), depInfos) |
Artur Satayev | 872a144 | 2020-04-27 17:08:37 +0100 | [diff] [blame] | 1041 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1042 | ctx.Build(pctx, android.BuildParams{ |
| 1043 | Rule: android.Phony, |
| 1044 | Output: android.PathForPhony(ctx, a.Name()+"-deps-info"), |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1045 | Inputs: []android.Path{ |
| 1046 | a.ApexBundleDepsInfo.FullListPath(), |
| 1047 | a.ApexBundleDepsInfo.FlatListPath(), |
| 1048 | }, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1049 | }) |
| 1050 | } |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 1051 | |
| 1052 | func (a *apexBundle) buildLintReports(ctx android.ModuleContext) { |
| 1053 | depSetsBuilder := java.NewLintDepSetBuilder() |
| 1054 | for _, fi := range a.filesInfo { |
| 1055 | depSetsBuilder.Transitive(fi.lintDepSets) |
| 1056 | } |
| 1057 | |
| 1058 | a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build()) |
| 1059 | } |